Back to Collection Items
#include <C_CkHttp.h>
#include <C_CkJsonObject.h>
#include <C_CkHttpResponse.h>
void ChilkatSample(void)
{
HCkHttp http;
BOOL success;
HCkJsonObject json;
HCkHttpResponse resp;
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
http = CkHttp_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.
// {
// "type": "Summary",
// "format": "JSON",
// "queryParameters": {
// "dateFrom": "2020-10-01T21:00:28.451Z",
// "dateTo": "2020-12-30T21:00:28.451Z",
// "statuses": [
// "Valid",
// "Cancelled",
// "Rejected"
// ],
// "productsInternalCodes": [
// ],
// "receiverSenderId": "",
// "receiverSenderType": "0",
// "branchNumber": "",
// "itemCodes": [
// {
// "codeValue": "",
// "codeType": ""
// }
// ],
// "documentTypeNames": [
// ]
// }
// }
json = CkJsonObject_Create();
CkJsonObject_UpdateString(json,"type","Summary");
CkJsonObject_UpdateString(json,"format","JSON");
CkJsonObject_UpdateString(json,"queryParameters.dateFrom","2020-10-01T21:00:28.451Z");
CkJsonObject_UpdateString(json,"queryParameters.dateTo","2020-12-30T21:00:28.451Z");
CkJsonObject_UpdateString(json,"queryParameters.statuses[0]","Valid");
CkJsonObject_UpdateString(json,"queryParameters.statuses[1]","Cancelled");
CkJsonObject_UpdateString(json,"queryParameters.statuses[2]","Rejected");
CkJsonObject_UpdateNewArray(json,"queryParameters.productsInternalCodes");
CkJsonObject_UpdateString(json,"queryParameters.receiverSenderId","");
CkJsonObject_UpdateString(json,"queryParameters.receiverSenderType","0");
CkJsonObject_UpdateString(json,"queryParameters.branchNumber","");
CkJsonObject_UpdateString(json,"queryParameters.itemCodes[0].codeValue","");
CkJsonObject_UpdateString(json,"queryParameters.itemCodes[0].codeType","");
CkJsonObject_UpdateNewArray(json,"queryParameters.documentTypeNames");
// Adds the "Authorization: Bearer <access_token>" header.
CkHttp_putAuthToken(http,"<access_token>");
resp = CkHttp_PostJson3(http,"https://domain.com/api/v1/documentPackages/requests","application/json",json);
if (CkHttp_getLastMethodSuccess(http) == FALSE) {
printf("%s\n",CkHttp_lastErrorText(http));
CkHttp_Dispose(http);
CkJsonObject_Dispose(json);
return;
}
printf("%d\n",CkHttpResponse_getStatusCode(resp));
printf("%s\n",CkHttpResponse_bodyStr(resp));
CkHttpResponse_Dispose(resp);
CkHttp_Dispose(http);
CkJsonObject_Dispose(json);
}
Curl Command
curl -X POST
-H "Authorization: Bearer <access_token>"
-d '{
"type": "Summary",
"format": "JSON",
"queryParameters": {
"dateFrom": "2020-10-01T21:00:28.451Z",
"dateTo": "2020-12-30T21:00:28.451Z",
"statuses": [
"Valid",
"Cancelled",
"Rejected"
],
"productsInternalCodes": [],
"receiverSenderId": "",
"receiverSenderType": "0",
"branchNumber": "",
"itemCodes": [
{
"codeValue": "",
"codeType": ""
}
],
"documentTypeNames": []
}
}'
https://domain.com/api/v1/documentPackages/requests
Postman Collection Item JSON
{
"name": "5. Request Document Package",
"request": {
"auth": {
"type": "bearer",
"bearer": [
{
"key": "token",
"value": "{{generatedAccessToken}}",
"type": "string"
}
]
},
"method": "POST",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\r\n \"type\": \"Summary\",\r\n \"format\": \"JSON\",\r\n \"queryParameters\": {\r\n \"dateFrom\": \"2020-10-01T21:00:28.451Z\",\r\n \"dateTo\": \"2020-12-30T21:00:28.451Z\",\r\n \"statuses\": [\r\n \"Valid\",\r\n \"Cancelled\",\r\n \"Rejected\"\r\n ],\r\n \"productsInternalCodes\": [],\r\n \"receiverSenderId\": \"\",\r\n \"receiverSenderType\": \"0\",\r\n \"branchNumber\": \"\",\r\n \"itemCodes\": [\r\n {\r\n \"codeValue\": \"\",\r\n \"codeType\": \"\"\r\n }\r\n ],\r\n \"documentTypeNames\": []\r\n }\r\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{apiBaseUrl}}/api/v1/documentPackages/requests",
"host": [
"{{apiBaseUrl}}"
],
"path": [
"api",
"v1",
"documentPackages",
"requests"
]
}
},
"response": [
]
}