Back to Collection Items
load ./chilkat.dll
# This example assumes the Chilkat API to have been previously unlocked.
# See Global Unlock Sample for sample code.
set http [new_CkHttp]
set req [new_CkHttpRequest]
CkHttpRequest_put_HttpVerb $req "POST"
CkHttpRequest_put_Path $req "/oauth/v2/token"
CkHttpRequest_put_ContentType $req "multipart/form-data"
set jsonFormData1 [new_CkJsonObject]
CkHttpRequest_AddStringForUpload2 $req "client_id" "" $jsonFormData1 "utf-8" "application/json"
set jsonFormData2 [new_CkJsonObject]
CkHttpRequest_AddStringForUpload2 $req "client_secret" "" $jsonFormData2 "utf-8" "application/json"
set jsonFormData3 [new_CkJsonObject]
CkHttpRequest_AddStringForUpload2 $req "refresh_token" "" $jsonFormData3 "utf-8" "application/json"
CkHttpRequest_AddParam $req "grant_type" "{{client-id}}{{client-secret}}{{refresh-token}}refresh_token"
# resp is a CkHttpResponse
set resp [CkHttp_SynchronousRequest $http "domain.com" 443 1 $req]
if {[CkHttp_get_LastMethodSuccess $http] == 0} then {
puts [CkHttp_lastErrorText $http]
delete_CkHttp $http
delete_CkHttpRequest $req
delete_CkJsonObject $jsonFormData1
delete_CkJsonObject $jsonFormData2
delete_CkJsonObject $jsonFormData3
exit
}
puts [CkHttpResponse_get_StatusCode $resp]
puts [CkHttpResponse_bodyStr $resp]
delete_CkHttpResponse $resp
delete_CkHttp $http
delete_CkHttpRequest $req
delete_CkJsonObject $jsonFormData1
delete_CkJsonObject $jsonFormData2
delete_CkJsonObject $jsonFormData3
Curl Command
curl -X POST
--form 'client_id={{client-id}}'
--form 'client_secret={{client-id}}{{client-secret}}'
--form 'refresh_token={{client-id}}{{client-secret}}{{refresh-token}}'
--form 'grant_type={{client-id}}{{client-secret}}{{refresh-token}}refresh_token'
https://domain.com/oauth/v2/token
Postman Collection Item JSON
{
"name": "Refresh Access Tokens",
"event": [
{
"listen": "test",
"script": {
"exec": [
"if (responseCode.code === 200)",
"{",
" var jsonData = JSON.parse(responseBody);",
"",
" pm.environment.set(\"access-token\", jsonData.access_token);",
" pm.environment.set(\"expiry-time\", Date.now() + parseInt(jsonData.expires_in));",
"}"
],
"type": "text/javascript"
}
}
],
"request": {
"auth": {
"type": "noauth"
},
"method": "POST",
"header": [
],
"body": {
"mode": "formdata",
"formdata": [
{
"key": "client_id",
"value": "{{client-id}}",
"type": "text"
},
{
"key": "client_secret",
"value": "{{client-secret}}",
"type": "text"
},
{
"key": "refresh_token",
"value": "{{refresh-token}}",
"type": "text"
},
{
"key": "grant_type",
"value": "refresh_token",
"type": "text"
}
]
},
"url": {
"raw": "{{accounts-url}}/oauth/v2/token",
"host": [
"{{accounts-url}}"
],
"path": [
"oauth",
"v2",
"token"
]
},
"description": "### Step 4: Refresh Access Tokens\n\nAs obvious as it is, refresh tokens are used to generate new access tokens when the current ones are past the expiry time."
},
"response": [
]
}