How can I refresh an expired Access Token?
Use the refresh token to get a new access token.
Since access tokens are only valid for 24 hours, your application will need a new token to continue using the API after that.
When you use the Authentication API for the first time, you will get an access_token in exchange for your normal Sonetel credentials (email address and password).
You can also request a refresh_token along with the access_token. To do so you need to use “refresh” parameter in your API call.
If you do this, the API response received will have two tokens
- access_token
Has a validity of 24 hours. - refresh_token.
Has a validity of 30 days.
After 24 hours, when the access_token expires, you can use the refresh_token to get a new access_token. This request should also have the “refresh” parameter set to get a new refresh_token.
Use the refresh token
When you use the refresh_token to request for a new access_token, your request will look something like this:
curl --location --request POST 'https://api.sonetel.com/SonetelAuth/beta/oauth/token' \
--header 'Accept: application/json, text/plain, */*' \
--header 'Authorization: Basic c29uZXRlbC1hcGk6c2fuZXRlbC1hcGk=' \
--form 'grant_type="refresh_token"' \
--form 'refresh="yes"' \
--form 'refresh_token="eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJhcGkuc29uZXRlbC5jb20iLCJ1c2VyX2lkIjoiMjAwMDAzMjU4NSIsInVzZXJfbmFtZSI6ImFhc2hlZXNoam9zaGlAZ21haWwuY29tIiwic2NvcGUiOlsiYWNjb3VudC5yZWFkIiwxBYWjb3VudC53cml0ZSIsImNvbnZlcnNhdGlvbi5yZWFkIiwiY29udmVyc2F0aW9uLndyaXRlIiwidXNlci5yZWFkIiwidXNlci53cml0ZSJdLCJhdGkiOiJmYjEwNzBlMy1hNTAzLTRlNDYtAdYyOS1lMTIyMTQ2YmQ4MGMiLCJpc3MiOiJTb25ldGVsTm9kZTEyMyIsImV4cCI6MTY2MTgyOTMyOSwiaWF0IjoxNjU0MDUzMzI5LCJqdGkiOiJiODg3Y2NlNC05MjZhLTRkMjItYTQzYS12345jYzc5MTNjNjgiLCJhY2NfaWQiOjUwMzM3MjgsImNsaWVudF9pZCI6InNvbmV0ZWwtYXBpIn0.VNqyenLWOWu_dOOTz0I6DNbxfA2I7nqpCJCNEk2L93cvEnlfWg_-l7_CSiD4O-IJlYDpwGxyvjrbrg9n725e2iJdyXofHdf_rcIEUk_J_z6dbGdZOF2gxDL3iXDNmlNYBh7h8fMoNLC-q2R6nNVoyToPKJ6dCJPtqv3ojsMjnhRBGAj1n0KXT7z_YcAG9kW9-43LKXnO53mAegqsSfhmaHJvreNBzWNh7WB7Zt5fpAaCVDMi6qYHS7vU1FHiJ6d66KmVq0BuO7Pyijc3g6W85601dO7eZC4i94DSvHVWmg4Selqk8lSm_0pq3Ihp0r867uoswogpfQN2MFUSwmgqCw"'
The response will look something like this:
See the details in the API documentation.