Back to Collection Items
#import <CkoHttp.h>
#import <CkoHttpRequest.h>
#import <CkoJsonObject.h>
#import <CkoHttpResponse.h>
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
CkoHttp *http = [[CkoHttp alloc] init];
BOOL success;
CkoHttpRequest *req = [[CkoHttpRequest alloc] init];
[req AddParam: @"grant_type" value: @"client_credentials"];
CkoJsonObject *jsonParam2 = [[CkoJsonObject alloc] init];
[req AddParam: @"client_id" value: [jsonParam2 Emit]];
CkoJsonObject *jsonParam3 = [[CkoJsonObject alloc] init];
[req AddParam: @"client_secret" value: [jsonParam3 Emit]];
[req AddParam: @"scope" value: @"pc pcapi"];
CkoHttpResponse *resp = [http PostUrlEncoded: @"https://domain.com/" req: req];
if (http.LastMethodSuccess == NO) {
NSLog(@"%@",http.LastErrorText);
return;
}
NSLog(@"%d",[resp.StatusCode intValue]);
NSLog(@"%@",resp.BodyStr);
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": [
]
}