PowerBuilder / New FreshBooks / Upload Image Without AccountId
Back to Collection Items
integer li_rc
oleobject loo_Http
integer li_Success
oleobject loo_Req
oleobject loo_Resp
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
loo_Http = create oleobject
// Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0
li_rc = loo_Http.ConnectToNewObject("Chilkat.Http")
if li_rc < 0 then
destroy loo_Http
MessageBox("Error","Connecting to COM object failed")
return
end if
loo_Req = create oleobject
// Use "Chilkat_9_5_0.HttpRequest" for versions of Chilkat < 10.0.0
li_rc = loo_Req.ConnectToNewObject("Chilkat.HttpRequest")
loo_Req.HttpVerb = "POST"
loo_Req.Path = "/uploads/images"
loo_Req.ContentType = "multipart/form-data"
li_Success = loo_Req.AddFileForUpload2("content"," path to file","application/octet-stream")
loo_Req.AddHeader("Authorization","Bearer <access_token>")
loo_Req.AddHeader("Expect","100-continue")
loo_Resp = loo_Http.SynchronousRequest("api.freshbooks.com",443,1,loo_Req)
if loo_Http.LastMethodSuccess = 0 then
Write-Debug loo_Http.LastErrorText
destroy loo_Http
destroy loo_Req
return
end if
Write-Debug string(loo_Resp.StatusCode)
Write-Debug loo_Resp.BodyStr
destroy loo_Resp
destroy loo_Http
destroy loo_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 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": [
]
}