Chilkat Online Tools

autoit / Coupa Postman Collection - OAuth - Master / Add Attachment (File) to a Requisition

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_9_5_0.Http")
Local $bSuccess

$oReq = ObjCreate("Chilkat_9_5_0.HttpRequest")
$oReq.HttpVerb = "POST"
$oReq.Path = "/requisitions/: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/requisitions/:id/attachments

Postman Collection Item JSON

{
  "name": "Add Attachment (File) to a Requisition",
  "protocolProfileBehavior": {
    "disabledSystemHeaders": {}
  },
  "request": {
    "method": "POST",
    "header": [
    ],
    "body": {
      "mode": "formdata",
      "formdata": [
        {
          "key": "attachment[file]",
          "type": "file",
          "src": "/Users/siyadmohammed/Documents/Learning/EmptyFiles/Test.pdf"
        }
      ]
    },
    "url": {
      "raw": "{{URL}}/requisitions/:id/attachments",
      "host": [
        "{{URL}}"
      ],
      "path": [
        "requisitions",
        ":id",
        "attachments"
      ],
      "variable": [
        {
          "key": "id",
          "value": "3512"
        }
      ]
    }
  },
  "response": [
  ]
}