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
-- Use this online tool to generate code from sample JSON: Generate Code to Create JSON
-- The following JSON is sent in the request body.
-- {
-- "password": "{{password}}",
-- "usernameOrEmailAddress": "{{usernameOrEmailAddress}}",
-- "tenancyName": "{{tenant}}"
-- }
DECLARE @json int
-- Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @json OUT
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'password', '{{password}}'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'usernameOrEmailAddress', '{{usernameOrEmailAddress}}'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'tenancyName', '{{tenant}}'
-- Adds the "Authorization: Bearer <access_token>" header.
EXEC sp_OASetProperty @http, 'AuthToken', '<access_token>'
DECLARE @resp int
EXEC sp_OAMethod @http, 'PostJson3', @resp OUT, 'https://domain.com/api/Account/Authenticate', 'application/json', @json
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 @json
RETURN
END
DECLARE @sbResponseBody int
-- Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @sbResponseBody OUT
EXEC sp_OAMethod @resp, 'GetBodySb', @success OUT, @sbResponseBody
DECLARE @jResp int
-- Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @jResp OUT
EXEC sp_OAMethod @jResp, 'LoadSb', @success OUT, @sbResponseBody
EXEC sp_OASetProperty @jResp, 'EmitCompact', 0
PRINT 'Response Body:'
EXEC sp_OAMethod @jResp, 'Emit', @sTmp0 OUT
PRINT @sTmp0
DECLARE @respStatusCode int
EXEC sp_OAGetProperty @resp, 'StatusCode', @respStatusCode OUT
PRINT 'Response Status Code = ' + @respStatusCode
IF @respStatusCode >= 400
BEGIN
PRINT 'Response Header:'
EXEC sp_OAGetProperty @resp, 'Header', @sTmp0 OUT
PRINT @sTmp0
PRINT 'Failed.'
EXEC @hr = sp_OADestroy @resp
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @json
EXEC @hr = sp_OADestroy @sbResponseBody
EXEC @hr = sp_OADestroy @jResp
RETURN
END
EXEC @hr = sp_OADestroy @resp
-- Sample JSON response:
-- (Sample code for parsing the JSON response is shown below)
-- {
-- "result": "eyJhbGciOiJSUzI1NiIsImtpZCI6IjVENzg4QTgyMEE4QzAzMkJBNzg1Mjk4QjNBMTlEMkNGMEQyODI2ODYiLCJ0eXAiOiJKV1QiLCJ4NXQiOiJYWGlLZ2dxTUF5dW5oU21MT2huU3p3MG9Kb1kifQ.eyJuYmYiOjE2MTc5NzQ1NjYsImV4cCI6MTYxNzk3ODQ2NiwiaXNzIjoiaHR0cHM6Ly9wdGFvcmNoMjAxMC1pcy5henVyZXdlYnNpdGVzLm5ldC9pZGVudGl0eSIsImF1ZCI6Ik9yY2hlc3RyYXRvckFwaVVzZXJBY2Nlc3MiLCJjbGllbnRfaWQiOiI0ZDdmMmJmMi05MDkzLTQ5NTktOWQ1Mi1iNGE2NjBmMTQ4NWYiLCJzdWIiOiJkNGF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UiAXX1Y4lo6_LJBBld1_y_AxRzHBskvsNc5WZwFCfrMM27NjFATfrODToECkWq-S3s-rI6h-mjQZECta4PG9cDYK5cyPB6yYp9VY2FqMg4znUIphyQIVRgHUsC2cGSo-UGZdCrgX5J4za5b3ze9OoAY",
-- "targetUrl": null,
-- "success": true,
-- "error": null,
-- "unAuthorizedRequest": false,
-- "__abp": true
-- }
-- Sample code for parsing the JSON response...
-- Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code
DECLARE @result nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @result OUT, 'result'
DECLARE @targetUrl nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @targetUrl OUT, 'targetUrl'
DECLARE @success int
EXEC sp_OAMethod @jResp, 'BoolOf', @success OUT, 'success'
DECLARE @error nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @error OUT, 'error'
DECLARE @unAuthorizedRequest int
EXEC sp_OAMethod @jResp, 'BoolOf', @unAuthorizedRequest OUT, 'unAuthorizedRequest'
DECLARE @v__abp int
EXEC sp_OAMethod @jResp, 'BoolOf', @v__abp OUT, '__abp'
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @json
EXEC @hr = sp_OADestroy @sbResponseBody
EXEC @hr = sp_OADestroy @jResp
END
GO
Curl Command
curl -X POST
-H "Authorization: Bearer <access_token>"
-d '{
"password": "{{password}}",
"usernameOrEmailAddress": "{{usernameOrEmailAddress}}",
"tenancyName": "{{tenant}}"
}'
https://domain.com/api/Account/Authenticate
Postman Collection Item JSON
{
"name": "Authenticate (OnPrem)",
"event": [
{
"listen": "test",
"script": {
"exec": [
"//test status code\r",
"pm.test(\"Status code is 200\", function () {\r",
" pm.response.to.have.status(200);\r",
"});"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "POST",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\r\n \"password\": \"{{password}}\",\r\n \"usernameOrEmailAddress\": \"{{usernameOrEmailAddress}}\",\r\n \"tenancyName\": \"{{tenant}}\"\r\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{OnPremUrl}}/api/Account/Authenticate",
"host": [
"{{OnPremUrl}}"
],
"path": [
"api",
"Account",
"Authenticate"
]
}
},
"response": [
{
"name": "Authenticate (OnPrem)",
"originalRequest": {
"method": "POST",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\r\n \"password\": \"{{password}}\",\r\n \"usernameOrEmailAddress\": \"{{usernameOrEmailAddress}}\",\r\n \"tenancyName\": \"{{tenant}}\"\r\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{OnPremUrl}}/api/Account/Authenticate",
"host": [
"{{OnPremUrl}}"
],
"path": [
"api",
"Account",
"Authenticate"
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Cache-Control",
"value": "no-cache, no-store, must-revalidate"
},
{
"key": "Pragma",
"value": "no-cache"
},
{
"key": "Transfer-Encoding",
"value": "chunked"
},
{
"key": "Content-Type",
"value": "application/json; charset=utf-8"
},
{
"key": "Content-Encoding",
"value": "gzip"
},
{
"key": "Expires",
"value": "-1"
},
{
"key": "Vary",
"value": "Accept-Encoding"
},
{
"key": "Request-Context",
"value": "appId=cid-v1:947add8d-3c5d-4dda-a0ab-9f714fdafac3"
},
{
"key": "X-Robots-Tag",
"value": "noindex, nofollow"
},
{
"key": "X-Download-Options",
"value": "noopen"
},
{
"key": "X-XSS-Protection",
"value": "1"
},
{
"key": "X-Content-Type-Options",
"value": "nosniff"
},
{
"key": "X-Frame-Options",
"value": "Deny"
},
{
"key": "Strict-Transport-Security",
"value": "max-age=31536000; includeSubDomains"
},
{
"key": "Content-Security-Policy",
"value": "default-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: https://*.blob.core.windows.net https://*.amazonaws.com blob:;font-src 'self' data:;connect-src 'self' wss: https://sentry.io https://studio-feedback.azure-api.net https://*.service.signalr.net https://*.blob.core.windows.net https://*.amazonaws.com dc.services.visualstudio.com;worker-src 'self' blob:"
},
{
"key": "X-Correlation-ID",
"value": "b707aed0-bdf0-4a36-a74f-e87176e3d256"
},
{
"key": "api-supported-versions",
"value": "11.0"
},
{
"key": "Date",
"value": "Fri, 09 Apr 2021 13:27:46 GMT"
}
],
"cookie": [
],
"body": "{\n \"result\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6IjVENzg4QTgyMEE4QzAzMkJBNzg1Mjk4QjNBMTlEMkNGMEQyODI2ODYiLCJ0eXAiOiJKV1QiLCJ4NXQiOiJYWGlLZ2dxTUF5dW5oU21MT2huU3p3MG9Kb1kifQ.eyJuYmYiOjE2MTc5NzQ1NjYsImV4cCI6MTYxNzk3ODQ2NiwiaXNzIjoiaHR0cHM6Ly9wdGFvcmNoMjAxMC1pcy5henVyZXdlYnNpdGVzLm5ldC9pZGVudGl0eSIsImF1ZCI6Ik9yY2hlc3RyYXRvckFwaVVzZXJBY2Nlc3MiLCJjbGllbnRfaWQiOiI0ZDdmMmJmMi05MDkzLTQ5NTktOWQ1Mi1iNGE2NjBmMTQ4NWYiLCJzdWIiOiJkNGFiODFlNi00NjU5LTRjMjUtOGFjNy0wYTQ4MGFhZTE3ZjAiLCJhdXRoX3RpbWUiOjE2MTc5NzQ4NjYsImlkcCI6ImxvY2FsIiwiQXNwTmV0LklkZW50aXR5LlNlY3VyaXR5U3RhbXAiOiJTWFoyTUFJV0wzSUxBNUtLWVZBM1pWWFdURERKRVU2WCIsInBydF9pZCI6IjNkZDg0NGQwLWZjY2YtMGUyZC04ZTE4LWMyZTNiMzExYTBhZiIsImhvc3QiOiJGYWxzZSIsImZpcnN0X25hbWUiOiJDb2RlIFNjaWVuY2UiLCJsYXN0X25hbWUiOiJRQSIsInBydF9hZG0iOiJGYWxzZSIsInByZWZlcnJlZF91c2VybmFtZSI6ImNvZGVzY2llbmNlcWEiLCJuYW1lIjoiY29kZXNjaWVuY2VxYSIsInNjb3BlIjpbImVtYWlsIiwib3BlbmlkIiwicHJvZmlsZSIsInRlbmFudCIsIk9yY2hlc3RyYXRvckFwaVVzZXJBY2Nlc3MiXSwiYW1yIjpbInB3ZCJdfQ.rQfDqz83R5qujADvcEBhSKREDCrW_L3LwCeRDlSf1NIpIykyCjTdprPp7QgbOmB5FRf7H1778ZY3pkPY4C_EH60lTqraNKe66E09vTpRPlASQoWrbUprNSxkVd7KLTQ16QUthelVsml_D39uSCBfhiUJR0N4Bpr9GF5IVsGOuRgwQtXiw4Gi-7hlWBX5qhnj3GO29uVO5oiSJJtKlMTqWO8iIZloURFdVxYUpXuywH6nEmeUFdIvOsUcFKjPOkpUW2SdIPqWjy7yTplAXoXny1yKBfPbEkwtivvOrzRz6fz6rPQO8qNTKcAf28oeO2iLYWRN7u4AIKLgPdpkbXjwgrrVXgY3Duvw6yjBsC2Yt9Iu6DJMXq2ereBA9E_PgiMTv7D3NbKcyqLUNmTScVfWBM92qMw9UzKh1_fl5qjN3DtfdRWek8AJowxkgDskNScemdkemXAS2cGSgFc7JxEsxmZWa8CSxuSuVw9XSsFc37GaZo3t2XusJR8P55frEzcycfnxfDOJfp8iFmaMY9slUiAXX1Y4lo6_LJBBld1_y_AxRzHBskvsNc5WZwFCfrMM27NjFATfrODToECkWq-S3s-rI6h-mjQZECta4PG9cDYK5cyPB6yYp9VY2FqMg4znUIphyQIVRgHUsC2cGSo-UGZdCrgX5J4za5b3ze9OoAY\",\n \"targetUrl\": null,\n \"success\": true,\n \"error\": null,\n \"unAuthorizedRequest\": false,\n \"__abp\": true\n}"
}
]
}