DataFlex / Zoho CRM REST APIs / Generate Access Token and Refresh Token
Back to Collection Items
Use ChilkatAx-win32.pkg
Procedure Test
Handle hoHttp
Boolean iSuccess
Variant vReq
Handle hoReq
Variant vJsonFormData1
Handle hoJsonFormData1
Variant vJsonFormData2
Handle hoJsonFormData2
Variant vJsonFormData3
Handle hoJsonFormData3
Variant vResp
Handle hoResp
String sTemp1
Integer iTemp1
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
Get Create (RefClass(cComChilkatHttp)) To hoHttp
If (Not(IsComObjectCreated(hoHttp))) Begin
Send CreateComObject of hoHttp
End
Get Create (RefClass(cComChilkatHttpRequest)) To hoReq
If (Not(IsComObjectCreated(hoReq))) Begin
Send CreateComObject of hoReq
End
Set ComHttpVerb Of hoReq To "POST"
Set ComPath Of hoReq To "/oauth/v2/token"
Set ComContentType Of hoReq To "multipart/form-data"
Get Create (RefClass(cComChilkatJsonObject)) To hoJsonFormData1
If (Not(IsComObjectCreated(hoJsonFormData1))) Begin
Send CreateComObject of hoJsonFormData1
End
Get pvComObject of hoJsonFormData1 to vJsonFormData1
Get ComAddStringForUpload2 Of hoReq "client_id" "" vJsonFormData1 "utf-8" "application/json" To iSuccess
Get Create (RefClass(cComChilkatJsonObject)) To hoJsonFormData2
If (Not(IsComObjectCreated(hoJsonFormData2))) Begin
Send CreateComObject of hoJsonFormData2
End
Get pvComObject of hoJsonFormData2 to vJsonFormData2
Get ComAddStringForUpload2 Of hoReq "client_secret" "" vJsonFormData2 "utf-8" "application/json" To iSuccess
Get Create (RefClass(cComChilkatJsonObject)) To hoJsonFormData3
If (Not(IsComObjectCreated(hoJsonFormData3))) Begin
Send CreateComObject of hoJsonFormData3
End
Get pvComObject of hoJsonFormData3 to vJsonFormData3
Get ComAddStringForUpload2 Of hoReq "redirect_uri" "" vJsonFormData3 "utf-8" "application/json" To iSuccess
Send ComAddParam To hoReq "code" "{{client-id}}{{client-secret}}{{redirect-uri}}paste_grant_token_here"
Send ComAddParam To hoReq "grant_type" "{{client-id}}{{client-secret}}{{redirect-uri}}paste_grant_token_hereauthorization_code"
Get Create (RefClass(cComChilkatHttpResponse)) To hoResp
If (Not(IsComObjectCreated(hoResp))) Begin
Send CreateComObject of hoResp
End
Get pvComObject of hoReq to vReq
Get pvComObject of hoResp to vResp
Get ComHttpSReq Of hoHttp "domain.com" 443 True vReq vResp To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoHttp To sTemp1
Showln sTemp1
Procedure_Return
End
Get ComStatusCode Of hoResp To iTemp1
Showln iTemp1
Get ComBodyStr Of hoResp To sTemp1
Showln sTemp1
End_Procedure
Curl Command
curl -X POST
--form 'client_id={{client-id}}'
--form 'client_secret={{client-id}}{{client-secret}}'
--form 'redirect_uri={{client-id}}{{client-secret}}{{redirect-uri}}'
--form 'code={{client-id}}{{client-secret}}{{redirect-uri}}paste_grant_token_here'
--form 'grant_type={{client-id}}{{client-secret}}{{redirect-uri}}paste_grant_token_hereauthorization_code'
https://domain.com/oauth/v2/token
Postman Collection Item JSON
{
"name": "Generate Access Token and Refresh Token",
"event": [
{
"listen": "test",
"script": {
"exec": [
"if (responseCode.code === 200)",
"{",
" var jsonData = JSON.parse(responseBody);",
"",
" pm.environment.set(\"refresh-token\", jsonData.refresh_token);",
" 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": "redirect_uri",
"value": "{{redirect-uri}}",
"type": "text"
},
{
"key": "code",
"value": "paste_grant_token_here",
"type": "text"
},
{
"key": "grant_type",
"value": "authorization_code",
"type": "text"
}
]
},
"url": {
"raw": "{{accounts-url}}/oauth/v2/token",
"host": [
"{{accounts-url}}"
],
"path": [
"oauth",
"v2",
"token"
]
},
"description": "### Step 3: Generate Access Token and Refresh Token\n\nOAuth2.0 requests are usually authenticated with an **access token**, which is passed as bearer token. To use this access token, you need to construct a normal HTTP request and include it in an Authorization header along with the value of Bearer."
},
"response": [
]
}