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.
-- {
-- "itemCode": "EG-113317713-ABCD",
-- "codeName": "ABCD Updated",
-- "codeNameAr": "ABCD Updated Arabic",
-- "activeFrom": "2021-04-06T00:00:00Z",
-- "activeTo": "2021-06-30T23:59:59Z",
-- "description": "Description of code 123",
-- "descriptionAr": " 2314 وصف الكود بالعربي",
-- "parentCode": "10000051",
-- "requestReason": "Request reason text Updated",
-- "linkedCode": "EG-728466198-Yes"
-- }
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, 'itemCode', 'EG-113317713-ABCD'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'codeName', 'ABCD Updated'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'codeNameAr', 'ABCD Updated Arabic'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'activeFrom', '2021-04-06T00:00:00Z'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'activeTo', '2021-06-30T23:59:59Z'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'description', 'Description of code 123'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'descriptionAr', ' 2314 وصف الكود بالعربي'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'parentCode', '10000051'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'requestReason', 'Request reason text Updated'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'linkedCode', 'EG-728466198-Yes'
EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Content-Type', 'application/json'
EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Accept-Language', 'en'
-- Adds the "Authorization: Bearer <access_token>" header.
EXEC sp_OASetProperty @http, 'AuthToken', '<access_token>'
DECLARE @sbRequestBody int
-- Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @sbRequestBody OUT
EXEC sp_OAMethod @json, 'EmitSb', @success OUT, @sbRequestBody
DECLARE @resp int
EXEC sp_OAMethod @http, 'PTextSb', @resp OUT, 'PUT', 'https://domain.com/api/v1.0/codetypes/requests/codes/:codeUsageRequestId', @sbRequestBody, 'utf-8', 'application/json', 0, 0
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
EXEC @hr = sp_OADestroy @sbRequestBody
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 @json
EXEC @hr = sp_OADestroy @sbRequestBody
END
GO
Curl Command
curl -X PUT
-H "Authorization: Bearer <access_token>"
-H "Content-Type: application/json"
-H "Accept-Language: en"
-d '{
"itemCode": "EG-113317713-ABCD",
"codeName": "ABCD Updated",
"codeNameAr": "ABCD Updated Arabic",
"activeFrom": "2021-04-06T00:00:00Z",
"activeTo": "2021-06-30T23:59:59Z",
"description": "Description of code 123",
"descriptionAr": " 2314 وصف الكود بالعربي",
"parentCode": "10000051",
"requestReason": "Request reason text Updated",
"linkedCode": "EG-728466198-Yes"
}'
https://domain.com/api/v1.0/codetypes/requests/codes/:codeUsageRequestId
Postman Collection Item JSON
{
"name": "11. Update EGS Code Usage",
"request": {
"auth": {
"type": "bearer",
"bearer": [
{
"key": "token",
"value": "{{generatedAccessToken}}",
"type": "string"
}
]
},
"method": "PUT",
"header": [
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Accept-Language",
"value": "en",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"itemCode\": \"EG-113317713-ABCD\",\n \"codeName\": \"ABCD Updated\",\n \"codeNameAr\": \"ABCD Updated Arabic\",\n \"activeFrom\": \"2021-04-06T00:00:00Z\",\n \"activeTo\": \"2021-06-30T23:59:59Z\",\n \"description\": \"Description of code 123\",\n \"descriptionAr\": \" 2314 وصف الكود بالعربي\",\n \"parentCode\": \"10000051\",\n \"requestReason\": \"Request reason text Updated\",\n \"linkedCode\": \"EG-728466198-Yes\"\n}"
},
"url": {
"raw": "{{apiBaseUrl}}/api/v1.0/codetypes/requests/codes/:codeUsageRequestId",
"host": [
"{{apiBaseUrl}}"
],
"path": [
"api",
"v1.0",
"codetypes",
"requests",
"codes",
":codeUsageRequestId"
],
"variable": [
{
"key": "codeUsageRequestId",
"value": ""
}
]
}
},
"response": [
]
}