Back to Collection Items
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
DECLARE @iTmp0 int
-- Important: Do not use nvarchar(max). See the warning about using nvarchar(max).
DECLARE @sTmp0 nvarchar(4000)
-- This example assumes the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.
DECLARE @http int
-- Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.Http', @http OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
DECLARE @success int
DECLARE @req int
-- Use "Chilkat_9_5_0.HttpRequest" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.HttpRequest', @req OUT
EXEC sp_OAMethod @req, 'AddParam', NULL, 'grant_type', 'client_credentials'
EXEC sp_OAMethod @req, 'AddHeader', NULL, 'Conversation-ID', '{{conv_id}}'
EXEC sp_OAMethod @req, 'AddHeader', NULL, 'Authorization', 'Basic {{secret}}'
DECLARE @resp int
EXEC sp_OAMethod @http, 'PostUrlEncoded', @resp OUT, 'https://domain.com/v2/auth/token', @req
EXEC sp_OAGetProperty @http, 'LastMethodSuccess', @iTmp0 OUT
IF @iTmp0 = 0
BEGIN
EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @req
RETURN
END
EXEC sp_OAGetProperty @resp, 'StatusCode', @iTmp0 OUT
PRINT @iTmp0
EXEC sp_OAGetProperty @resp, 'BodyStr', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @resp
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @req
END
GO
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": [
]
}