Chilkat Online Tools

TCL / Booking Management API v2021.12 / 0. REST Authorize ATK Copy

Back to Collection Items

load ./chilkat.dll

# This example assumes the Chilkat API to have been previously unlocked.
# See Global Unlock Sample for sample code.

set http [new_CkHttp]

set req [new_CkHttpRequest]

CkHttpRequest_AddParam $req "grant_type" "client_credentials"

CkHttpRequest_AddHeader $req "Conversation-ID" "{{conv_id}}"
CkHttpRequest_AddHeader $req "Authorization" "Basic {{secret}}"

# resp is a CkHttpResponse
set resp [CkHttp_PostUrlEncoded $http "https://domain.com/v2/auth/token" $req]
if {[CkHttp_get_LastMethodSuccess $http] == 0} then {
    puts [CkHttp_lastErrorText $http]
    delete_CkHttp $http
    delete_CkHttpRequest $req
    exit
}

puts [CkHttpResponse_get_StatusCode $resp]
puts [CkHttpResponse_bodyStr $resp]
delete_CkHttpResponse $resp


delete_CkHttp $http
delete_CkHttpRequest $req

Curl Command

curl -X POST
	-H "Content-Type: application/x-www-form-urlencoded"
	-H "Authorization: Basic {{secret}}"
	-H "Conversation-ID: {{conv_id}}"
	-d 'grant_type=client_credentials'
https://domain.com/v2/auth/token

Postman Collection Item JSON

{
  "name": "0. REST Authorize ATK Copy",
  "event": [
    {
      "listen": "prerequest",
      "script": {
        "exec": [
          ""
        ],
        "type": "text/javascript"
      }
    },
    {
      "listen": "test",
      "script": {
        "exec": [
          ""
        ],
        "type": "text/javascript"
      }
    }
  ],
  "request": {
    "auth": {
      "type": "noauth"
    },
    "method": "POST",
    "header": [
      {
        "key": "Content-Type",
        "value": "application/x-www-form-urlencoded",
        "type": "text"
      },
      {
        "key": "Authorization",
        "value": "Basic {{secret}}",
        "type": "text"
      },
      {
        "key": "Conversation-ID",
        "value": "{{conv_id}}",
        "type": "text"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "grant_type=client_credentials"
    },
    "url": {
      "raw": "{{rest_endpoint}}/v2/auth/token",
      "host": [
        "{{rest_endpoint}}"
      ],
      "path": [
        "v2",
        "auth",
        "token"
      ]
    },
    "description": "\n\n[//]: # \"Start\"\n\n<b>[Description](https://developer.sabre.com/resources/getting_started_with_sabre_apis/how_to_get_a_token#3sub3)\n\n[//]: # \"End\""
  },
  "response": [
  ]
}