Chilkat Online Tools

DataFlex / Coupa Postman Collection - OAuth - Master / Add Attachment (File) to a Purchase Order

Back to Collection Items

Use ChilkatAx-9.5.0-win32.pkg

Procedure Test
    Handle hoHttp
    Boolean iSuccess
    Variant vReq
    Handle hoReq
    Variant vResp
    Handle hoResp
    String sTemp1
    Integer iTemp1
    Boolean bTemp1

    // This example assumes the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    Get Create (RefClass(cComChilkatHttp)) To hoHttp
    If (Not(IsComObjectCreated(hoHttp))) Begin
        Send CreateComObject of hoHttp
    End

    Get Create (RefClass(cComChilkatHttpRequest)) To hoReq
    If (Not(IsComObjectCreated(hoReq))) Begin
        Send CreateComObject of hoReq
    End
    Set ComHttpVerb Of hoReq To "POST"
    Set ComPath Of hoReq To "/purchase_orders/:id/attachments"
    Set ComContentType Of hoReq To "multipart/form-data"
    Get ComAddFileForUpload2 Of hoReq "attachment[file]" " path to file" "application/octet-stream" To iSuccess

    Send ComAddHeader To hoReq "Authorization" "Bearer <access_token>"
    Send ComAddHeader To hoReq "Expect" "100-continue"

    Get pvComObject of hoReq to vReq
    Get ComSynchronousRequest Of hoHttp "domain.com" 443 True vReq To vResp
    If (IsComObject(vResp)) Begin
        Get Create (RefClass(cComChilkatHttpResponse)) To hoResp
        Set pvComObject Of hoResp To vResp
    End
    Get ComLastMethodSuccess Of hoHttp To bTemp1
    If (bTemp1 = False) Begin
        Get ComLastErrorText Of hoHttp To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get ComStatusCode Of hoResp To iTemp1
    Showln iTemp1
    Get ComBodyStr Of hoResp To sTemp1
    Showln sTemp1
    Send Destroy of hoResp


End_Procedure

Curl Command

curl -X POST
	-H "Authorization: Bearer <access_token>"
	--form 'attachment[file]=@"/path/to/file"'
https://domain.com/purchase_orders/:id/attachments

Postman Collection Item JSON

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