C / DocuSign REST API / 01 Authorize Code Grant Access Token
Back to Collection Items
#include <C_CkHttp.h>
#include <C_CkHttpRequest.h>
#include <C_CkJsonObject.h>
#include <C_CkHttpResponse.h>
void ChilkatSample(void)
{
HCkHttp http;
BOOL success;
HCkHttpRequest req;
HCkJsonObject jsonParam1;
HCkHttpResponse resp;
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
http = CkHttp_Create();
req = CkHttpRequest_Create();
jsonParam1 = CkJsonObject_Create();
CkHttpRequest_AddParam(req,"code",CkJsonObject_emit(jsonParam1));
CkHttpRequest_AddParam(req,"grant_type","authorization_code");
CkHttpRequest_AddHeader(req,"Authorization","Basic {{encodedKeys}}");
resp = CkHttp_PostUrlEncoded(http,"https://{{hostenv}}/oauth/token",req);
if (CkHttp_getLastMethodSuccess(http) == FALSE) {
printf("%s\n",CkHttp_lastErrorText(http));
CkHttp_Dispose(http);
CkHttpRequest_Dispose(req);
CkJsonObject_Dispose(jsonParam1);
return;
}
printf("%d\n",CkHttpResponse_getStatusCode(resp));
printf("%s\n",CkHttpResponse_bodyStr(resp));
CkHttpResponse_Dispose(resp);
CkHttp_Dispose(http);
CkHttpRequest_Dispose(req);
CkJsonObject_Dispose(jsonParam1);
}
Curl Command
curl -X POST
-H "Authorization: Basic {{encodedKeys}}"
--data-urlencode 'code={{codeFromUrl}}'
--data-urlencode 'grant_type=authorization_code'
https://{{hostenv}}/oauth/token
Postman Collection Item JSON
{
"name": "01 Authorize Code Grant Access Token",
"event": [
{
"listen": "test",
"script": {
"type": "text/javascript",
"exec": [
"var jsonData = JSON.parse(responseBody);",
"postman.setEnvironmentVariable(\"accessToken\", jsonData.access_token);",
"var jsonData = JSON.parse(responseBody);",
"postman.setEnvironmentVariable(\"refreshToken\", jsonData.refresh_token);"
]
}
}
],
"request": {
"method": "POST",
"header": [
{
"key": "Authorization",
"value": "Basic {{encodedKeys}}"
}
],
"body": {
"mode": "urlencoded",
"urlencoded": [
{
"key": "code",
"value": "{{codeFromUrl}}"
},
{
"key": "grant_type",
"value": "authorization_code"
}
]
},
"url": {
"raw": "https://{{hostenv}}/oauth/token",
"protocol": "https",
"host": [
"{{hostenv}}"
],
"path": [
"oauth",
"token"
]
}
},
"response": [
]
}