Chilkat Online Tools

unicodeCpp / New FreshBooks / Upload Image Without AccountId

Back to Collection Items

#include <CkHttpW.h>
#include <CkHttpRequestW.h>
#include <CkHttpResponseW.h>

void ChilkatSample(void)
    {
    // This example assumes the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    CkHttpW http;
    bool success;

    CkHttpRequestW req;
    req.put_HttpVerb(L"POST");
    req.put_Path(L"/uploads/images");
    req.put_ContentType(L"multipart/form-data");
    success = req.AddFileForUpload2(L"content",L" path to file",L"application/octet-stream");

    req.AddHeader(L"Authorization",L"Bearer <access_token>");
    req.AddHeader(L"Expect",L"100-continue");

    CkHttpResponseW *resp = http.SynchronousRequest(L"api.freshbooks.com",443,true,req);
    if (http.get_LastMethodSuccess() == false) {
        wprintf(L"%s\n",http.lastErrorText());
        return;
    }

    wprintf(L"%d\n",resp->get_StatusCode());
    wprintf(L"%s\n",resp->bodyStr());
    delete resp;
    }

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 Image Without AccountId",
  "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": [
  ]
}