TCL / New FreshBooks / Upload Expense Receipt
Back to Collection Items
load ./chilkat.dll
# This example assumes the Chilkat API to have been previously unlocked.
# See Global Unlock Sample for sample code.
set http [new_CkHttp]
set req [new_CkHttpRequest]
CkHttpRequest_put_HttpVerb $req "POST"
CkHttpRequest_put_Path $req "/uploads/account/{{accountId}}/attachments"
CkHttpRequest_put_ContentType $req "multipart/form-data"
set success [CkHttpRequest_AddFileForUpload2 $req "content" " path to file" "application/octet-stream"]
CkHttpRequest_AddHeader $req "Authorization" "Bearer <access_token>"
CkHttpRequest_AddHeader $req "Expect" "100-continue"
set resp [new_CkHttpResponse]
set success [CkHttp_HttpSReq $http "api.freshbooks.com" 443 1 $req $resp]
if {$success == 0} then {
puts [CkHttp_lastErrorText $http]
delete_CkHttp $http
delete_CkHttpRequest $req
delete_CkHttpResponse $resp
exit
}
puts [CkHttpResponse_get_StatusCode $resp]
puts [CkHttpResponse_bodyStr $resp]
delete_CkHttp $http
delete_CkHttpRequest $req
delete_CkHttpResponse $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/account/{{accountId}}/attachments
Postman Collection Item JSON
{
"name": "Upload Expense Receipt",
"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/account/{{accountId}}/attachments",
"protocol": "https",
"host": [
"api",
"freshbooks",
"com"
],
"path": [
"uploads",
"account",
"{{accountId}}",
"attachments"
]
}
},
"response": [
]
}