Back to Collection Items
#include <C_CkHttp.h>
#include <C_CkJsonObject.h>
#include <C_CkHttpResponse.h>
#include <C_CkStringBuilder.h>
void ChilkatSample(void)
{
HCkHttp http;
BOOL success;
HCkJsonObject json;
HCkHttpResponse resp;
HCkStringBuilder sbResponseBody;
HCkJsonObject jResp;
int respStatusCode;
const char *collected_at;
const char *internal_identification;
const char *pdf;
const char *rfc;
const char *outcome;
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
http = CkHttp_Create();
CkHttp_putBasicAuth(http,TRUE);
CkHttp_putLogin(http,"{{secretId}}");
CkHttp_putPassword(http,"{{secretPassword}}");
// Use this online tool to generate code from sample JSON: Generate Code to Create JSON
// The following JSON is sent in the request body.
// {
// "link": "d4617561-1c01-4b2f-83b6-a594f7b3bc57",
// "attach_pdf": false,
// "save_data": true
// }
json = CkJsonObject_Create();
CkJsonObject_UpdateString(json,"link","d4617561-1c01-4b2f-83b6-a594f7b3bc57");
CkJsonObject_UpdateBool(json,"attach_pdf",FALSE);
CkJsonObject_UpdateBool(json,"save_data",TRUE);
CkHttp_SetRequestHeader(http,"Content-Type","application/json");
resp = CkHttp_PostJson3(http,"https://domain.com/api/tax-compliance-status/","application/json",json);
if (CkHttp_getLastMethodSuccess(http) == FALSE) {
printf("%s\n",CkHttp_lastErrorText(http));
CkHttp_Dispose(http);
CkJsonObject_Dispose(json);
return;
}
sbResponseBody = CkStringBuilder_Create();
CkHttpResponse_GetBodySb(resp,sbResponseBody);
jResp = CkJsonObject_Create();
CkJsonObject_LoadSb(jResp,sbResponseBody);
CkJsonObject_putEmitCompact(jResp,FALSE);
printf("Response Body:\n");
printf("%s\n",CkJsonObject_emit(jResp));
respStatusCode = CkHttpResponse_getStatusCode(resp);
printf("Response Status Code = %d\n",respStatusCode);
if (respStatusCode >= 400) {
printf("Response Header:\n");
printf("%s\n",CkHttpResponse_header(resp));
printf("Failed.\n");
CkHttpResponse_Dispose(resp);
CkHttp_Dispose(http);
CkJsonObject_Dispose(json);
CkStringBuilder_Dispose(sbResponseBody);
CkJsonObject_Dispose(jResp);
return;
}
CkHttpResponse_Dispose(resp);
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// {
// "collected_at": "<dateTime>",
// "internal_identification": "<string>",
// "pdf": "<binary>",
// "rfc": "<string>",
// "outcome": "<string>"
// }
// Sample code for parsing the JSON response...
// Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code
// Chilkat functions returning "const char *" return a pointer to temporary internal memory owned and managed by Chilkat.
collected_at = CkJsonObject_stringOf(jResp,"collected_at");
internal_identification = CkJsonObject_stringOf(jResp,"internal_identification");
pdf = CkJsonObject_stringOf(jResp,"pdf");
rfc = CkJsonObject_stringOf(jResp,"rfc");
outcome = CkJsonObject_stringOf(jResp,"outcome");
CkHttp_Dispose(http);
CkJsonObject_Dispose(json);
CkStringBuilder_Dispose(sbResponseBody);
CkJsonObject_Dispose(jResp);
}
Curl Command
curl -X POST
-u '{{secretId}}:{{secretPassword}}'
-H "Content-Type: application/json"
-d '{
"link": "d4617561-1c01-4b2f-83b6-a594f7b3bc57",
"attach_pdf": false,
"save_data": true
}'
https://domain.com/api/tax-compliance-status/
Postman Collection Item JSON
{
"name": "Retrieve",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"link\": \"d4617561-1c01-4b2f-83b6-a594f7b3bc57\",\n \"attach_pdf\": false,\n \"save_data\": true\n}"
},
"url": {
"raw": "{{baseUrl}}/api/tax-compliance-status/",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"tax-compliance-status",
""
]
},
"description": "Retrieve the Tax compliance status information for a specific fiscal link."
},
"response": [
{
"name": "Ok (when save_data=false)",
"originalRequest": {
"method": "POST",
"header": [
{
"description": "Added as a part of security scheme: basic",
"key": "Authorization",
"value": "Basic <credentials>"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"link\": \"<uuid>\",\n \"attach_pdf\": false,\n \"encryption_key\": \"<string>\",\n \"save_data\": true\n}"
},
"url": {
"raw": "{{baseUrl}}/api/tax-compliance-status",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"tax-compliance-status"
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n\t\"collected_at\": \"<dateTime>\",\n\t\"internal_identification\": \"<string>\",\n\t\"pdf\": \"<binary>\",\n\t\"rfc\": \"<string>\",\n\t\"outcome\": \"<string>\"\n}"
},
{
"name": "Created (when save_data=true)",
"originalRequest": {
"method": "POST",
"header": [
{
"description": "Added as a part of security scheme: basic",
"key": "Authorization",
"value": "Basic <credentials>"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"link\": \"<uuid>\",\n \"attach_pdf\": false,\n \"encryption_key\": \"<string>\",\n \"save_data\": true\n}"
},
"url": {
"raw": "{{baseUrl}}/api/tax-compliance-status",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"tax-compliance-status"
]
}
},
"status": "Created",
"code": 201,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n\t\"id\": \"<uuid>\",\n\t\"collected_at\": \"<dateTime>\",\n\t\"internal_identification\": \"<string>\",\n\t\"pdf\": \"<binary>\",\n\t\"rfc\": \"<string>\",\n\t\"outcome\": \"<string>\"\n}"
},
{
"name": "Bad request error",
"originalRequest": {
"method": "POST",
"header": [
{
"description": "Added as a part of security scheme: basic",
"key": "Authorization",
"value": "Basic <credentials>"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"link\": \"<uuid>\",\n \"attach_pdf\": false,\n \"encryption_key\": \"<string>\",\n \"save_data\": true\n}"
},
"url": {
"raw": "{{baseUrl}}/api/tax-compliance-status",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"tax-compliance-status"
]
}
},
"status": "Bad Request",
"code": 400,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "[\n\t{\n\t\t\"code\": \"<string>\",\n\t\t\"message\": \"<string>\",\n\t\t\"request_id\": \"<string>\"\n\t},\n\t{\n\t\t\"code\": \"<string>\",\n\t\t\"message\": \"<string>\",\n\t\t\"request_id\": \"<string>\"\n\t}\n]"
},
{
"name": "Unauthorized",
"originalRequest": {
"method": "POST",
"header": [
{
"description": "Added as a part of security scheme: basic",
"key": "Authorization",
"value": "Basic <credentials>"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"link\": \"<uuid>\",\n \"attach_pdf\": false,\n \"encryption_key\": \"<string>\",\n \"save_data\": true\n}"
},
"url": {
"raw": "{{baseUrl}}/api/tax-compliance-status",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"tax-compliance-status"
]
}
},
"status": "Unauthorized",
"code": 401,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "[\n\t{\n\t\t\"code\": \"<string>\",\n\t\t\"message\": \"<string>\",\n\t\t\"request_id\": \"<string>\"\n\t},\n\t{\n\t\t\"code\": \"<string>\",\n\t\t\"message\": \"<string>\",\n\t\t\"request_id\": \"<string>\"\n\t}\n]"
},
{
"name": "Request Timeout",
"originalRequest": {
"method": "POST",
"header": [
{
"description": "Added as a part of security scheme: basic",
"key": "Authorization",
"value": "Basic <credentials>"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"link\": \"<uuid>\",\n \"attach_pdf\": false,\n \"encryption_key\": \"<string>\",\n \"save_data\": true\n}"
},
"url": {
"raw": "{{baseUrl}}/api/tax-compliance-status",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"tax-compliance-status"
]
}
},
"status": "Request Timeout",
"code": 408,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "[\n\t{\n\t\t\"code\": \"<string>\",\n\t\t\"message\": \"<string>\",\n\t\t\"request_id\": \"<string>\"\n\t},\n\t{\n\t\t\"code\": \"<string>\",\n\t\t\"message\": \"<string>\",\n\t\t\"request_id\": \"<string>\"\n\t}\n]"
},
{
"name": "Unexpected Error",
"originalRequest": {
"method": "POST",
"header": [
{
"description": "Added as a part of security scheme: basic",
"key": "Authorization",
"value": "Basic <credentials>"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"link\": \"<uuid>\",\n \"attach_pdf\": false,\n \"encryption_key\": \"<string>\",\n \"save_data\": true\n}"
},
"url": {
"raw": "{{baseUrl}}/api/tax-compliance-status",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"tax-compliance-status"
]
}
},
"status": "Internal Server Error",
"code": 500,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "[\n\t{\n\t\t\"code\": \"<string>\",\n\t\t\"message\": \"<string>\",\n\t\t\"request_id\": \"<string>\"\n\t},\n\t{\n\t\t\"code\": \"<string>\",\n\t\t\"message\": \"<string>\",\n\t\t\"request_id\": \"<string>\"\n\t}\n]"
}
]
}