Chilkat Online Tools

PureBasic / Coupa Postman Collection - OAuth - Master / Create Supplier Site

Back to Collection Items

IncludeFile "CkStringBuilder.pb"
IncludeFile "CkHttp.pb"
IncludeFile "CkHttpResponse.pb"
IncludeFile "CkXml.pb"

Procedure ChilkatExample()

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

    http.i = CkHttp::ckCreate()
    If http.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    success.i

    ; 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"?>
    ; <supplier-site>
    ;     <active>true</active>
    ;     <addresses>
    ;         <address>
    ;             <id>5064</id>
    ;         </address>
    ;     </addresses>
    ;     <buyer-hold>false</buyer-hold>
    ;     <code>Supplier code13</code>
    ;     <contacts>
    ;         <contact>
    ;             <id>3803</id>
    ;         </contact>
    ;     </contacts>
    ;     <content-groups/>
    ;     <cxml-domain nil="true"/>
    ;     <cxml-http-username nil="true"/>
    ;     <cxml-identity nil="true"/>
    ;     <cxml-protocol nil="true"/>
    ;     <cxml-secret nil="true"/>
    ;     <cxml-ssl-version nil="true"/>
    ;     <cxml-supplier-domain nil="true"/>
    ;     <cxml-supplier-identity nil="true"/>
    ;     <cxml-url nil="true"/>
    ;     <default-locale>en</default-locale>
    ;     <disable-cert-verify>false</disable-cert-verify>
    ;     <name>Supplier load4 site name13</name>
    ;     <po-change-method>prompt</po-change-method>
    ;     <po-email nil="true"/>
    ;     <po-method>prompt</po-method>
    ; </supplier-site>
    ; 

    xml.i = CkXml::ckCreate()
    If xml.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkXml::setCkTag(xml, "supplier-site")
    CkXml::ckUpdateChildContent(xml,"active","true")
    CkXml::ckUpdateChildContentInt(xml,"addresses|address|id",5064)
    CkXml::ckUpdateChildContent(xml,"buyer-hold","false")
    CkXml::ckUpdateChildContent(xml,"code","Supplier code13")
    CkXml::ckUpdateChildContentInt(xml,"contacts|contact|id",3803)
    CkXml::ckUpdateChildContent(xml,"content-groups","")
    CkXml::ckUpdateAttrAt(xml,"cxml-domain",1,"nil","true")
    CkXml::ckUpdateAttrAt(xml,"cxml-http-username",1,"nil","true")
    CkXml::ckUpdateAttrAt(xml,"cxml-identity",1,"nil","true")
    CkXml::ckUpdateAttrAt(xml,"cxml-protocol",1,"nil","true")
    CkXml::ckUpdateAttrAt(xml,"cxml-secret",1,"nil","true")
    CkXml::ckUpdateAttrAt(xml,"cxml-ssl-version",1,"nil","true")
    CkXml::ckUpdateAttrAt(xml,"cxml-supplier-domain",1,"nil","true")
    CkXml::ckUpdateAttrAt(xml,"cxml-supplier-identity",1,"nil","true")
    CkXml::ckUpdateAttrAt(xml,"cxml-url",1,"nil","true")
    CkXml::ckUpdateChildContent(xml,"default-locale","en")
    CkXml::ckUpdateChildContent(xml,"disable-cert-verify","false")
    CkXml::ckUpdateChildContent(xml,"name","Supplier load4 site name13")
    CkXml::ckUpdateChildContent(xml,"po-change-method","prompt")
    CkXml::ckUpdateAttrAt(xml,"po-email",1,"nil","true")
    CkXml::ckUpdateChildContent(xml,"po-method","prompt")

    ; Adds the "Authorization: Bearer <access_token>" header.
    CkHttp::setCkAuthToken(http, "<access_token>")

    sbRequestBody.i = CkStringBuilder::ckCreate()
    If sbRequestBody.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkXml::ckGetXmlSb(xml,sbRequestBody)

    resp.i = CkHttp::ckPTextSb(http,"POST","[" + Chr(34) + "id" + Chr(34) + "," + Chr(34) + "supplier_id" + Chr(34) + "," + Chr(34) + "kind" + Chr(34) + "," + Chr(34) + "name_given" + Chr(34) + "," + Chr(34) + "name_family" + Chr(34) + "," + Chr(34) + "email" + Chr(34) + "]}]",sbRequestBody,"utf-8","application/xml",0,0)
    If CkHttp::ckLastMethodSuccess(http) = 0
        Debug CkHttp::ckLastErrorText(http)
        CkHttp::ckDispose(http)
        CkXml::ckDispose(xml)
        CkStringBuilder::ckDispose(sbRequestBody)
        ProcedureReturn
    EndIf

    Debug Str(CkHttpResponse::ckStatusCode(resp))
    Debug CkHttpResponse::ckBodyStr(resp)
    CkHttpResponse::ckDispose(resp)



    CkHttp::ckDispose(http)
    CkXml::ckDispose(xml)
    CkStringBuilder::ckDispose(sbRequestBody)


    ProcedureReturn
EndProcedure

Curl Command

curl -X POST
	-H "Authorization: Bearer <access_token>"
	-d '<supplier-site>
    <active>true</active>
    <addresses>
        <address>
            <id>5064</id>
        </address>
    </addresses>
    <buyer-hold>false</buyer-hold>
    <code>Supplier code13</code>
    <contacts>
        <contact>
            <id>3803</id>
        </contact>
    </contacts>
    <content-groups/>
    <cxml-domain nil="true"/>
    <cxml-http-username nil="true"/>
    <cxml-identity nil="true"/>
    <cxml-protocol nil="true"/>
    <cxml-secret nil="true"/>
    <cxml-ssl-version nil="true"/>
    <cxml-supplier-domain nil="true"/>
    <cxml-supplier-identity nil="true"/>
    <cxml-url nil="true"/>
    <default-locale>en</default-locale>
    <disable-cert-verify>false</disable-cert-verify>
    <name>Supplier load4 site name13</name>
    <po-change-method>prompt</po-change-method>
    <po-email nil="true"/>
    <po-method>prompt</po-method>
</supplier-site>'
https://domain.com/suppliers/:id/supplier_sites?fields=["id","name","code","supplier_id",{"addresses": ["id","supplier_id","kind","location_code","address_name","street_address","street_address2","city","postal_code","state",{"country": ["id","code","name"]},{"custom_fields": {}}]},{"contacts": ["id","supplier_id","kind","name_given","name_family","email"]}]

Postman Collection Item JSON

{
  "name": "Create Supplier Site",
  "request": {
    "method": "POST",
    "header": [
    ],
    "body": {
      "mode": "raw",
      "raw": "<supplier-site>\n    <active>true</active>\n    <addresses>\n        <address>\n            <id>5064</id>\n        </address>\n    </addresses>\n    <buyer-hold>false</buyer-hold>\n    <code>Supplier code13</code>\n    <contacts>\n        <contact>\n            <id>3803</id>\n        </contact>\n    </contacts>\n    <content-groups/>\n    <cxml-domain nil=\"true\"/>\n    <cxml-http-username nil=\"true\"/>\n    <cxml-identity nil=\"true\"/>\n    <cxml-protocol nil=\"true\"/>\n    <cxml-secret nil=\"true\"/>\n    <cxml-ssl-version nil=\"true\"/>\n    <cxml-supplier-domain nil=\"true\"/>\n    <cxml-supplier-identity nil=\"true\"/>\n    <cxml-url nil=\"true\"/>\n    <default-locale>en</default-locale>\n    <disable-cert-verify>false</disable-cert-verify>\n    <name>Supplier load4 site name13</name>\n    <po-change-method>prompt</po-change-method>\n    <po-email nil=\"true\"/>\n    <po-method>prompt</po-method>\n</supplier-site>",
      "options": {
        "raw": {
          "language": "xml"
        }
      }
    },
    "url": {
      "raw": "{{URL}}/suppliers/:id/supplier_sites?fields=[\"id\",\"name\",\"code\",\"supplier_id\",{\"addresses\": [\"id\",\"supplier_id\",\"kind\",\"location_code\",\"address_name\",\"street_address\",\"street_address2\",\"city\",\"postal_code\",\"state\",{\"country\": [\"id\",\"code\",\"name\"]},{\"custom_fields\": {}}]},{\"contacts\": [\"id\",\"supplier_id\",\"kind\",\"name_given\",\"name_family\",\"email\"]}]",
      "host": [
        "{{URL}}"
      ],
      "path": [
        "suppliers",
        ":id",
        "supplier_sites"
      ],
      "query": [
        {
          "key": "fields",
          "value": "[\"id\",\"name\",\"code\",\"supplier_id\",{\"addresses\": [\"id\",\"supplier_id\",\"kind\",\"location_code\",\"address_name\",\"street_address\",\"street_address2\",\"city\",\"postal_code\",\"state\",{\"country\": [\"id\",\"code\",\"name\"]},{\"custom_fields\": {}}]},{\"contacts\": [\"id\",\"supplier_id\",\"kind\",\"name_given\",\"name_family\",\"email\"]}]"
        }
      ],
      "variable": [
        {
          "key": "id",
          "value": "3505"
        }
      ]
    }
  },
  "response": [
  ]
}