Chilkat Online Tools

C++ / New FreshBooks / Upload Image Without AccountId

Back to Collection Items

#include <CkHttp.h>
#include <CkHttpRequest.h>
#include <CkHttpResponse.h>

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

    CkHttp http;
    bool success;

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

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

    CkHttpResponse *resp = http.SynchronousRequest("api.freshbooks.com",443,true,req);
    if (http.get_LastMethodSuccess() == false) {
        std::cout << http.lastErrorText() << "\r\n";
        return;
    }

    std::cout << resp->get_StatusCode() << "\r\n";
    std::cout << resp->bodyStr() << "\r\n";
    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": [
  ]
}