Back to Collection Items
; This example assumes the Chilkat API to have been previously unlocked.
; See Global Unlock Sample for sample code.
$oHttp = ObjCreate("Chilkat.Http")
Local $bSuccess
$oReq = ObjCreate("Chilkat.HttpRequest")
$oReq.HttpVerb = "POST"
$oReq.Path = "/invoices/:id/attachments"
$oReq.ContentType = "multipart/form-data"
$bSuccess = $oReq.AddFileForUpload2("attachment[file]"," path to file","application/octet-stream")
$oReq.AddHeader "Authorization","Bearer <access_token>"
$oReq.AddHeader "Expect","100-continue"
Local $oResp = $oHttp.SynchronousRequest("domain.com",443,True,$oReq)
If ($oHttp.LastMethodSuccess = False) Then
ConsoleWrite($oHttp.LastErrorText & @CRLF)
Exit
EndIf
ConsoleWrite($oResp.StatusCode & @CRLF)
ConsoleWrite($oResp.BodyStr & @CRLF)
Curl Command
curl -X POST
-H "Authorization: Bearer <access_token>"
--form 'attachment[file]=@"/path/to/file"'
https://domain.com/invoices/:id/attachments
Postman Collection Item JSON
{
"name": "Add Attachment (File) to an Invoice",
"request": {
"method": "POST",
"header": [
],
"body": {
"mode": "formdata",
"formdata": [
{
"key": "attachment[file]",
"type": "file",
"src": "/Users/siyadmohammed/Documents/Learning/EmptyFiles/Test.pdf"
}
]
},
"url": {
"raw": "{{URL}}/invoices/:id/attachments",
"host": [
"{{URL}}"
],
"path": [
"invoices",
":id",
"attachments"
],
"variable": [
{
"key": "id",
"value": "841"
}
]
}
},
"response": [
]
}