Back to Collection Items
#include <C_CkHttp.h>
#include <C_CkHttpRequest.h>
#include <C_CkHttpResponse.h>
#include <C_CkStringBuilder.h>
#include <C_CkJsonObject.h>
void ChilkatSample(void)
{
HCkHttp http;
BOOL success;
HCkHttpRequest req;
HCkHttpResponse resp;
HCkStringBuilder sbResponseBody;
HCkJsonObject jResp;
int respStatusCode;
const char *created_at;
const char *customer_id;
const char *document_id;
const char *file_name;
const char *id;
const char *project_id;
const char *size;
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
http = CkHttp_Create();
req = CkHttpRequest_Create();
CkHttpRequest_putHttpVerb(req,"POST");
CkHttpRequest_putPath(req,"/rest/v1/attachments");
CkHttpRequest_putContentType(req,"multipart/form-data");
CkHttpRequest_AddParam(req,"file","<string>");
CkHttpRequest_AddHeader(req,"Authorization","{{apiKey}}");
CkHttpRequest_AddHeader(req,"Accept","application/json");
resp = CkHttp_SynchronousRequest(http,"api.easybill.de",443,TRUE,req);
if (CkHttp_getLastMethodSuccess(http) == FALSE) {
printf("%s\n",CkHttp_lastErrorText(http));
CkHttp_Dispose(http);
CkHttpRequest_Dispose(req);
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);
CkHttpRequest_Dispose(req);
CkStringBuilder_Dispose(sbResponseBody);
CkJsonObject_Dispose(jResp);
return;
}
CkHttpResponse_Dispose(resp);
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// {
// "created_at": "<date>",
// "customer_id": null,
// "document_id": null,
// "file_name": "<string>",
// "id": "<long>",
// "project_id": null,
// "size": "<integer>"
// }
// 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.
created_at = CkJsonObject_stringOf(jResp,"created_at");
customer_id = CkJsonObject_stringOf(jResp,"customer_id");
document_id = CkJsonObject_stringOf(jResp,"document_id");
file_name = CkJsonObject_stringOf(jResp,"file_name");
id = CkJsonObject_stringOf(jResp,"id");
project_id = CkJsonObject_stringOf(jResp,"project_id");
size = CkJsonObject_stringOf(jResp,"size");
CkHttp_Dispose(http);
CkHttpRequest_Dispose(req);
CkStringBuilder_Dispose(sbResponseBody);
CkJsonObject_Dispose(jResp);
}
Curl Command
curl -X POST
-H "Authorization: {{apiKey}}"
-H "Content-Type: multipart/form-data"
-H "Accept: application/json"
--form 'file=<string>'
https://api.easybill.de/rest/v1/attachments
Postman Collection Item JSON
{
"name": "Create attachment",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "multipart/form-data"
},
{
"key": "Accept",
"value": "application/json"
}
],
"body": {
"mode": "formdata",
"formdata": [
{
"key": "file",
"value": "<string>",
"description": "(Required) ",
"type": "text"
}
]
},
"url": {
"raw": "{{baseUrl}}/attachments",
"host": [
"{{baseUrl}}"
],
"path": [
"attachments"
]
}
},
"response": [
{
"name": "Successful operation",
"originalRequest": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "multipart/form-data"
},
{
"key": "Accept",
"value": "application/json"
},
{
"description": "Added as a part of security scheme: apikey",
"key": "Authorization",
"value": "<API Key>"
}
],
"body": {
"mode": "formdata",
"formdata": [
{
"key": "file",
"value": "<string>",
"description": "(Required) ",
"type": "text"
}
]
},
"url": {
"raw": "{{baseUrl}}/attachments",
"host": [
"{{baseUrl}}"
],
"path": [
"attachments"
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n \"created_at\": \"<date>\",\n \"customer_id\": null,\n \"document_id\": null,\n \"file_name\": \"<string>\",\n \"id\": \"<long>\",\n \"project_id\": null,\n \"size\": \"<integer>\"\n}"
},
{
"name": "Too Many Requests",
"originalRequest": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "multipart/form-data"
},
{
"description": "Added as a part of security scheme: apikey",
"key": "Authorization",
"value": "<API Key>"
}
],
"body": {
"mode": "formdata",
"formdata": [
{
"key": "file",
"value": "<string>",
"description": "(Required) ",
"type": "text"
}
]
},
"url": {
"raw": "{{baseUrl}}/attachments",
"host": [
"{{baseUrl}}"
],
"path": [
"attachments"
]
}
},
"status": "Too Many Requests",
"code": 429,
"_postman_previewlanguage": "text",
"header": [
],
"cookie": [
],
"body": ""
}
]
}