Back to Collection Items
var
http: HCkHttp;
success: Boolean;
req: HCkHttpRequest;
resp: HCkHttpResponse;
sbResponseBody: HCkStringBuilder;
jResp: HCkJsonObject;
respStatusCode: Integer;
created_at: PWideChar;
customer_id: PWideChar;
document_id: PWideChar;
file_name: PWideChar;
id: PWideChar;
project_id: PWideChar;
size: PWideChar;
begin
// 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) then
begin
Memo1.Lines.Add(CkHttp__lastErrorText(http));
Exit;
end;
sbResponseBody := CkStringBuilder_Create();
CkHttpResponse_GetBodySb(resp,sbResponseBody);
jResp := CkJsonObject_Create();
CkJsonObject_LoadSb(jResp,sbResponseBody);
CkJsonObject_putEmitCompact(jResp,False);
Memo1.Lines.Add('Response Body:');
Memo1.Lines.Add(CkJsonObject__emit(jResp));
respStatusCode := CkHttpResponse_getStatusCode(resp);
Memo1.Lines.Add('Response Status Code = ' + IntToStr(respStatusCode));
if (respStatusCode >= 400) then
begin
Memo1.Lines.Add('Response Header:');
Memo1.Lines.Add(CkHttpResponse__header(resp));
Memo1.Lines.Add('Failed.');
CkHttpResponse_Dispose(resp);
Exit;
end;
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
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": ""
}
]
}