Chilkat Online Tools

delphiDll / New FreshBooks / Upload App Logo

Back to Collection Items

var
http: HCkHttp;
success: Boolean;
req: HCkHttpRequest;
resp: HCkHttpResponse;

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,'/uploads/images');
CkHttpRequest_putContentType(req,'multipart/form-data');
success := CkHttpRequest_AddFileForUpload2(req,'content',' path to file','application/octet-stream');

CkHttpRequest_AddHeader(req,'Authorization','Bearer <access_token>');
CkHttpRequest_AddHeader(req,'Expect','100-continue');

resp := CkHttp_SynchronousRequest(http,'api.freshbooks.com',443,True,req);
if (CkHttp_getLastMethodSuccess(http) = False) then
  begin
    Memo1.Lines.Add(CkHttp__lastErrorText(http));
    Exit;
  end;

Memo1.Lines.Add(IntToStr(CkHttpResponse_getStatusCode(resp)));
Memo1.Lines.Add(CkHttpResponse__bodyStr(resp));
CkHttpResponse_Dispose(resp);

CkHttp_Dispose(http);
CkHttpRequest_Dispose(req);

Curl Command

curl -X POST
	-H "Authorization: Bearer <access_token>"
	-H "Content-Type: multipart/form-data"
	--form 'content=@"/path/to/file"'
https://api.freshbooks.com/uploads/images

Postman Collection Item JSON

{
  "name": "Upload App Logo",
  "event": [
    {
      "listen": "test",
      "script": {
        "exec": [
          "let jsonData = JSON.parse(responseBody); ",
          "pm.environment.set(\"uploadFile\", \"\\'\" + jsonData.attachment.jwt + \"\\\"\")"
        ],
        "type": "text/javascript"
      }
    }
  ],
  "request": {
    "method": "POST",
    "header": [
      {
        "key": "Content-Type",
        "name": "Content-Type",
        "type": "text",
        "value": "multipart/form-data",
        "disabled": true
      }
    ],
    "body": {
      "mode": "formdata",
      "formdata": [
        {
          "key": "content",
          "type": "file",
          "src": [
          ]
        }
      ]
    },
    "url": {
      "raw": "https://api.freshbooks.com/uploads/images",
      "protocol": "https",
      "host": [
        "api",
        "freshbooks",
        "com"
      ],
      "path": [
        "uploads",
        "images"
      ]
    }
  },
  "response": [
  ]
}