Back to Collection Items
func chilkatTest() {
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
let http = CkoHttp()!
var success: Bool
let req = CkoHttpRequest()!
req.addParam("grant_type", value: "client_credentials")
let jsonParam2 = CkoJsonObject()!
req.addParam("client_id", value: jsonParam2.emit())
let jsonParam3 = CkoJsonObject()!
req.addParam("client_secret", value: jsonParam3.emit())
req.addParam("scope", value: "InvoicingAPI")
var resp: CkoHttpResponse? = http.postUrlEncoded("https://domain.com/connect/token", req: req)
if http.lastMethodSuccess == false {
print("\(http.lastErrorText!)")
return
}
print("\(resp!.statusCode.intValue)")
print("\(resp!.bodyStr!)")
resp = nil
}
Curl Command
curl -X POST
-H "Content-Type: application/x-www-form-urlencoded"
--data-urlencode 'grant_type=client_credentials'
--data-urlencode 'client_id={{clientId}}'
--data-urlencode 'client_secret={{clientSecret}}'
--data-urlencode 'scope=InvoicingAPI'
https://domain.com/connect/token
Postman Collection Item JSON
{
"name": "1. Login as Taxpayer System",
"event": [
{
"listen": "test",
"script": {
"exec": [
"\r",
"pm.test(\"Status code is 200\", function () {\r",
"var jsonData = JSON.parse(responseBody);\r",
"pm.environment.set(\"generatedAccessToken\", jsonData.access_token);\r",
"});\r",
"\r",
"\r",
"\r",
""
],
"type": "text/javascript"
}
}
],
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/x-www-form-urlencoded",
"type": "text"
},
{
"key": "",
"value": "",
"type": "text"
}
],
"body": {
"mode": "urlencoded",
"urlencoded": [
{
"key": "grant_type",
"value": "client_credentials",
"type": "text"
},
{
"key": "client_id",
"value": "{{clientId}}",
"type": "text"
},
{
"key": "client_secret",
"value": "{{clientSecret}}",
"type": "text"
},
{
"key": "scope",
"value": "InvoicingAPI",
"type": "text"
}
]
},
"url": {
"raw": "{{idSrvBaseUrl}}/connect/token",
"host": [
"{{idSrvBaseUrl}}"
],
"path": [
"connect",
"token"
]
}
},
"response": [
]
}