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 = "/contracts/:id/attachments"
loo_Req.ContentType = "multipart/form-data"
li_Success = loo_Req.AddFileForUpload2("attachment[file]"," path to file","application/octet-stream")
loo_Req.AddHeader("Authorization","Bearer <access_token>")
loo_Req.AddHeader("Accept","application/xml")
loo_Req.AddHeader("Expect","100-continue")
loo_Resp = loo_Http.SynchronousRequest("domain.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 "Accept: application/xml"
-H "Content-Type: multipart/form-data"
--form 'attachment[file]=@"/path/to/file"'
https://domain.com/contracts/:id/attachments
Postman Collection Item JSON
{
"name": "Contracts - Add New Attachment",
"request": {
"method": "POST",
"header": [
{
"key": "Accept",
"value": "application/xml",
"type": "text"
},
{
"key": "Content-Type",
"name": "Content-Type",
"value": "multipart/form-data",
"type": "text"
}
],
"body": {
"mode": "formdata",
"formdata": [
{
"key": "attachment[file]",
"type": "file",
"src": "/Users/siyadmohammed/Documents/Learning/Sample Files/ContractAttachment.pdf"
},
{
"key": "file",
"type": "file",
"src": [
],
"disabled": true
}
]
},
"url": {
"raw": "{{URL}}/contracts/:id/attachments",
"host": [
"{{URL}}"
],
"path": [
"contracts",
":id",
"attachments"
],
"query": [
{
"key": "",
"value": "",
"disabled": true
}
],
"variable": [
{
"key": "id",
"value": "372"
}
]
}
},
"response": [
]
}