Chilkat Online Tools

unicodeC / Booking Management API v2021.12 / REST Authorize

Back to Collection Items

#include <C_CkHttpW.h>
#include <C_CkHttpRequestW.h>
#include <C_CkHttpResponseW.h>

void ChilkatSample(void)
    {
    HCkHttpW http;
    BOOL success;
    HCkHttpRequestW req;
    HCkHttpResponseW resp;

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

    http = CkHttpW_Create();

    req = CkHttpRequestW_Create();
    CkHttpRequestW_AddParam(req,L"grant_type",L"client_credentials");

    CkHttpRequestW_AddHeader(req,L"Conversation-ID",L"{{conv_id}}");
    CkHttpRequestW_AddHeader(req,L"Authorization",L"Basic {{secret}}");

    resp = CkHttpW_PostUrlEncoded(http,L"https://domain.com/v2/auth/token",req);
    if (CkHttpW_getLastMethodSuccess(http) == FALSE) {
        wprintf(L"%s\n",CkHttpW_lastErrorText(http));
        CkHttpW_Dispose(http);
        CkHttpRequestW_Dispose(req);
        return;
    }

    wprintf(L"%d\n",CkHttpResponseW_getStatusCode(resp));
    wprintf(L"%s\n",CkHttpResponseW_bodyStr(resp));
    CkHttpResponseW_Dispose(resp);


    CkHttpW_Dispose(http);
    CkHttpRequestW_Dispose(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": "REST Authorize",
  "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": [
  ]
}