Back to Collection Items
#include <C_CkHttpW.h>
#include <C_CkJsonObjectW.h>
#include <C_CkStringBuilderW.h>
#include <C_CkHttpResponseW.h>
void ChilkatSample(void)
{
HCkHttpW http;
BOOL success;
HCkJsonObjectW json;
HCkStringBuilderW sbRequestBody;
HCkHttpResponseW resp;
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
http = CkHttpW_Create();
// Use this online tool to generate code from sample JSON: Generate Code to Create JSON
// The following JSON is sent in the request body.
// {
// "items": [
// {
// "codetype": "EGS",
// "itemCode": "EG-113317713-5598542",
// "comment": "create code usage reason"
// },
// {
// "codetype": "EGS",
// "itemCode": "EG-100000053-10015",
// "comment": "create code usage reason"
// }
// ]
// }
json = CkJsonObjectW_Create();
CkJsonObjectW_UpdateString(json,L"items[0].codetype",L"EGS");
CkJsonObjectW_UpdateString(json,L"items[0].itemCode",L"EG-113317713-5598542");
CkJsonObjectW_UpdateString(json,L"items[0].comment",L"create code usage reason");
CkJsonObjectW_UpdateString(json,L"items[1].codetype",L"EGS");
CkJsonObjectW_UpdateString(json,L"items[1].itemCode",L"EG-100000053-10015");
CkJsonObjectW_UpdateString(json,L"items[1].comment",L"create code usage reason");
CkHttpW_SetRequestHeader(http,L"Content-Type",L"application/json");
CkHttpW_SetRequestHeader(http,L"Accept-Language",L"en");
// Adds the "Authorization: Bearer <access_token>" header.
CkHttpW_putAuthToken(http,L"<access_token>");
sbRequestBody = CkStringBuilderW_Create();
CkJsonObjectW_EmitSb(json,sbRequestBody);
resp = CkHttpW_PTextSb(http,L"PUT",L"https://domain.com/api/v1.0/codetypes/requests/codeusages",sbRequestBody,L"utf-8",L"application/json",FALSE,FALSE);
if (CkHttpW_getLastMethodSuccess(http) == FALSE) {
wprintf(L"%s\n",CkHttpW_lastErrorText(http));
CkHttpW_Dispose(http);
CkJsonObjectW_Dispose(json);
CkStringBuilderW_Dispose(sbRequestBody);
return;
}
wprintf(L"%d\n",CkHttpResponseW_getStatusCode(resp));
wprintf(L"%s\n",CkHttpResponseW_bodyStr(resp));
CkHttpResponseW_Dispose(resp);
CkHttpW_Dispose(http);
CkJsonObjectW_Dispose(json);
CkStringBuilderW_Dispose(sbRequestBody);
}
Curl Command
curl -X PUT
-H "Authorization: Bearer <access_token>"
-H "Content-Type: application/json"
-H "Accept-Language: en"
-d '{
"items": [
{
"codetype": "EGS",
"itemCode": "EG-113317713-5598542",
"comment": "create code usage reason"
},
{
"codetype": "EGS",
"itemCode": "EG-100000053-10015",
"comment": "create code usage reason"
}
]
}'
https://domain.com/api/v1.0/codetypes/requests/codeusages
Postman Collection Item JSON
{
"name": "8. Request Code Reuse",
"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 \"items\": [\n {\n \"codetype\": \"EGS\",\n \"itemCode\": \"EG-113317713-5598542\",\n \"comment\": \"create code usage reason\"\n },\n {\n \"codetype\": \"EGS\",\n \"itemCode\": \"EG-100000053-10015\",\n \"comment\": \"create code usage reason\"\n }\n ]\n}"
},
"url": {
"raw": "{{apiBaseUrl}}/api/v1.0/codetypes/requests/codeusages",
"host": [
"{{apiBaseUrl}}"
],
"path": [
"api",
"v1.0",
"codetypes",
"requests",
"codeusages"
]
}
},
"response": [
]
}