Back to Collection Items
Use ChilkatAx-win32.pkg
Procedure Test
Handle hoHttp
Boolean iSuccess
Variant vReq
Handle hoReq
Handle hoJsonParam2
Handle hoJsonParam3
Variant vResp
Handle hoResp
String sTemp1
Integer iTemp1
Boolean bTemp1
// 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
Send ComAddParam To hoReq "grant_type" "client_credentials"
Get Create (RefClass(cComChilkatJsonObject)) To hoJsonParam2
If (Not(IsComObjectCreated(hoJsonParam2))) Begin
Send CreateComObject of hoJsonParam2
End
Get ComEmit Of hoJsonParam2 To sTemp1
Send ComAddParam To hoReq "client_id" sTemp1
Get Create (RefClass(cComChilkatJsonObject)) To hoJsonParam3
If (Not(IsComObjectCreated(hoJsonParam3))) Begin
Send CreateComObject of hoJsonParam3
End
Get ComEmit Of hoJsonParam3 To sTemp1
Send ComAddParam To hoReq "client_secret" sTemp1
Send ComAddParam To hoReq "scope" "pc pcapi"
Get pvComObject of hoReq to vReq
Get ComPostUrlEncoded Of hoHttp "https://domain.com/" vReq To vResp
If (IsComObject(vResp)) Begin
Get Create (RefClass(cComChilkatHttpResponse)) To hoResp
Set pvComObject Of hoResp To vResp
End
Get ComLastMethodSuccess Of hoHttp To bTemp1
If (bTemp1 = 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
Send Destroy of hoResp
End_Procedure
Curl Command
curl -X POST
-H "Content-Type: application/x-www-form-urlencoded"
--data-urlencode 'grant_type=client_credentials'
--data-urlencode 'client_id={{partner_client_id}}'
--data-urlencode 'client_secret={{partner_client_secret}}'
--data-urlencode 'scope=pc pcapi'
https://domain.com/
Postman Collection Item JSON
{
"name": "[Partner] Create Partner Authentication Token",
"event": [
{
"listen": "test",
"script": {
"type": "text/javascript",
"exec": [
"// Extract oAuth Token from response body",
"var jsonData = JSON.parse(responseBody);",
"var partnerToken = jsonData.access_token;",
"",
"// Set to an environment variable",
"postman.setEnvironmentVariable(\"partner_token\", partnerToken);"
]
}
}
],
"_postman_id": "6f420d0f-ef65-40dc-a870-e21ff2522ccf",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"name": "Content-Type",
"value": "application/x-www-form-urlencoded",
"type": "text"
}
],
"body": {
"mode": "urlencoded",
"urlencoded": [
{
"key": "grant_type",
"value": "client_credentials",
"type": "text"
},
{
"key": "client_id",
"value": "{{partner_client_id}}",
"type": "text"
},
{
"key": "client_secret",
"value": "{{partner_client_secret}}",
"type": "text"
},
{
"key": "scope",
"value": "pc pcapi",
"type": "text"
}
]
},
"url": "{{api_host}}/oauth2/v1/token"
},
"response": [
]
}