Back to Collection Items
integer li_rc
oleobject loo_Http
integer li_Success
oleobject loo_Xml
oleobject loo_SbRequestBody
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
// Use this online tool to generate code from sample XML: Generate Code to Create XML
// The following XML is sent in the request body.
// <?xml version="1.0" encoding="UTF-8"?>
// <order-header>
// <type>ExternalOrderHeader</type>
// <po-number>PO-957645-17</po-number>
// <version type="integer">1</version>
// <payment-method>invoice</payment-method>
// <ship-to-attention nil="true"/>
// <transmission-method-override>do_not_transmit</transmission-method-override>
// <ship-to-address>
// <location-code>DUMMYST</location-code>
// </ship-to-address>
// <ship-to-user>
// <login>CoupaRequester</login>
// </ship-to-user>
// <supplier>
// <name>CoupaSupplier</name>
// </supplier>
// <payment-term>
// <code>2/10 Net 30</code>
// </payment-term>
// <currency>
// <code>USD</code>
// </currency>
// <order-lines type="array">
// <order-line>
// <description>Supplies</description>
// <line-num>1</line-num>
// <price type="decimal">40.00</price>
// <quantity type="decimal">1.0</quantity>
// <type>OrderQuantityLine</type>
// <uom>
// <code>EA</code>
// </uom>
// <account>
// <code>SF-Marketing-Assets</code>
// <account-type>
// <name>Ace Corporate</name>
// </account-type>
// </account>
// <currency>
// <code>USD</code>
// </currency>
// </order-line>
// </order-lines>
// </order-header>
//
loo_Xml = create oleobject
// Use "Chilkat_9_5_0.Xml" for versions of Chilkat < 10.0.0
li_rc = loo_Xml.ConnectToNewObject("Chilkat.Xml")
loo_Xml.Tag = "order-header"
loo_Xml.UpdateChildContent("type","ExternalOrderHeader")
loo_Xml.UpdateChildContent("po-number","PO-957645-17")
loo_Xml.UpdateAttrAt("version",1,"type","integer")
loo_Xml.UpdateChildContentInt("version",1)
loo_Xml.UpdateChildContent("payment-method","invoice")
loo_Xml.UpdateAttrAt("ship-to-attention",1,"nil","true")
loo_Xml.UpdateChildContent("transmission-method-override","do_not_transmit")
loo_Xml.UpdateChildContent("ship-to-address|location-code","DUMMYST")
loo_Xml.UpdateChildContent("ship-to-user|login","CoupaRequester")
loo_Xml.UpdateChildContent("supplier|name","CoupaSupplier")
loo_Xml.UpdateChildContent("payment-term|code","2/10 Net 30")
loo_Xml.UpdateChildContent("currency|code","USD")
loo_Xml.UpdateAttrAt("order-lines",1,"type","array")
loo_Xml.UpdateChildContent("order-lines|order-line|description","Supplies")
loo_Xml.UpdateChildContentInt("order-lines|order-line|line-num",1)
loo_Xml.UpdateAttrAt("order-lines|order-line|price",1,"type","decimal")
loo_Xml.UpdateChildContent("order-lines|order-line|price","40.00")
loo_Xml.UpdateAttrAt("order-lines|order-line|quantity",1,"type","decimal")
loo_Xml.UpdateChildContent("order-lines|order-line|quantity","1.0")
loo_Xml.UpdateChildContent("order-lines|order-line|type","OrderQuantityLine")
loo_Xml.UpdateChildContent("order-lines|order-line|uom|code","EA")
loo_Xml.UpdateChildContent("order-lines|order-line|account|code","SF-Marketing-Assets")
loo_Xml.UpdateChildContent("order-lines|order-line|account|account-type|name","Ace Corporate")
loo_Xml.UpdateChildContent("order-lines|order-line|currency|code","USD")
// Adds the "Authorization: Bearer <access_token>" header.
loo_Http.AuthToken = "<access_token>"
loo_Http.SetRequestHeader("Accept","application/json")
loo_SbRequestBody = create oleobject
// Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0
li_rc = loo_SbRequestBody.ConnectToNewObject("Chilkat.StringBuilder")
loo_Xml.GetXmlSb(loo_SbRequestBody)
loo_Resp = loo_Http.PTextSb("POST","https://domain.com/purchase_orders/?fields=[~"id~"]",loo_SbRequestBody,"utf-8","application/xml",0,0)
if loo_Http.LastMethodSuccess = 0 then
Write-Debug loo_Http.LastErrorText
destroy loo_Http
destroy loo_Xml
destroy loo_SbRequestBody
return
end if
Write-Debug string(loo_Resp.StatusCode)
Write-Debug loo_Resp.BodyStr
destroy loo_Resp
destroy loo_Http
destroy loo_Xml
destroy loo_SbRequestBody
Curl Command
curl -X POST
-H "Authorization: Bearer <access_token>"
-H "Accept: application/json"
-d '<?xml version="1.0" encoding="UTF-8"?>
<order-header>
<type>ExternalOrderHeader</type>
<po-number>PO-957645-17</po-number>
<version type="integer">1</version>
<payment-method>invoice</payment-method>
<ship-to-attention nil="true"/>
<transmission-method-override>do_not_transmit</transmission-method-override>
<ship-to-address>
<location-code>DUMMYST</location-code>
</ship-to-address>
<ship-to-user>
<login>CoupaRequester</login>
</ship-to-user>
<supplier>
<name>CoupaSupplier</name>
</supplier>
<payment-term>
<code>2/10 Net 30</code>
</payment-term>
<currency>
<code>USD</code>
</currency>
<order-lines type="array">
<order-line>
<description>Supplies</description>
<line-num>1</line-num>
<price type="decimal">40.00</price>
<quantity type="decimal">1.0</quantity>
<type>OrderQuantityLine</type>
<uom>
<code>EA</code>
</uom>
<account>
<code>SF-Marketing-Assets</code>
<account-type>
<name>Ace Corporate</name>
</account-type>
</account>
<currency>
<code>USD</code>
</currency>
</order-line>
</order-lines>
</order-header>'
https://domain.com/purchase_orders/?fields=["id"]
Postman Collection Item JSON
{
"name": "Create External PO",
"request": {
"method": "POST",
"header": [
{
"key": "Accept",
"value": "application/json",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<order-header>\n <type>ExternalOrderHeader</type>\n <po-number>PO-957645-17</po-number>\n <version type=\"integer\">1</version>\n <payment-method>invoice</payment-method>\n <ship-to-attention nil=\"true\"/>\n <transmission-method-override>do_not_transmit</transmission-method-override>\n <ship-to-address>\n <location-code>DUMMYST</location-code>\n </ship-to-address>\n <ship-to-user>\n <login>CoupaRequester</login>\n </ship-to-user>\n <supplier>\n <name>CoupaSupplier</name>\n </supplier>\n <payment-term>\n <code>2/10 Net 30</code>\n </payment-term>\n <currency>\n <code>USD</code>\n </currency>\n <order-lines type=\"array\">\n <order-line>\n <description>Supplies</description>\n <line-num>1</line-num>\n <price type=\"decimal\">40.00</price>\n <quantity type=\"decimal\">1.0</quantity>\n <type>OrderQuantityLine</type>\n <uom>\n <code>EA</code>\n </uom>\n <account>\n <code>SF-Marketing-Assets</code>\n <account-type>\n <name>Ace Corporate</name>\n </account-type>\n </account>\n <currency>\n <code>USD</code>\n </currency>\n </order-line>\n </order-lines>\n</order-header>",
"options": {
"raw": {
"language": "xml"
}
}
},
"url": {
"raw": "{{URL}}/purchase_orders/?fields=[\"id\"]",
"host": [
"{{URL}}"
],
"path": [
"purchase_orders",
""
],
"query": [
{
"key": "fields",
"value": "[\"id\"]"
}
]
}
},
"response": [
]
}