Chilkat Online Tools

SQL Server / Coupa Postman Collection - OAuth - Master / Create SIM SIte using SIM ID in POST URL

Back to Collection Items

-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    DECLARE @iTmp0 int
    -- Important: Do not use nvarchar(max).  See the warning about using nvarchar(max).
    DECLARE @sTmp0 nvarchar(4000)
    -- This example assumes the Chilkat API to have been previously unlocked.
    -- See Global Unlock Sample for sample code.

    DECLARE @http int
    -- Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0
    EXEC @hr = sp_OACreate 'Chilkat.Http', @http OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    DECLARE @success int

    -- 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-information-site>
    --     <active>true</active>
    --     <addresses>
    --         <address>
    --             <id>686</id>
    --         </address>
    --         <address>
    --             <id>687</id>
    --         </address>
    --     </addresses>
    --     <buyer-hold>false</buyer-hold>
    --     <code>SIM load4 code13</code>
    --     <contacts>
    --         <contact>
    --             <id>519</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>SIM load4 site name13</name>
    --     <po-change-method>prompt</po-change-method>
    --     <po-email nil="true"/>
    --     <po-method>prompt</po-method>
    -- </supplier-information-site>
    -- 

    DECLARE @xml int
    -- Use "Chilkat_9_5_0.Xml" for versions of Chilkat < 10.0.0
    EXEC @hr = sp_OACreate 'Chilkat.Xml', @xml OUT

    EXEC sp_OASetProperty @xml, 'Tag', 'supplier-information-site'
    EXEC sp_OAMethod @xml, 'UpdateChildContent', NULL, 'active', 'true'
    EXEC sp_OAMethod @xml, 'UpdateChildContentInt', NULL, 'addresses|address|id', 686
    EXEC sp_OAMethod @xml, 'UpdateChildContentInt', NULL, 'addresses|address[1]|id', 687
    EXEC sp_OAMethod @xml, 'UpdateChildContent', NULL, 'buyer-hold', 'false'
    EXEC sp_OAMethod @xml, 'UpdateChildContent', NULL, 'code', 'SIM load4 code13'
    EXEC sp_OAMethod @xml, 'UpdateChildContentInt', NULL, 'contacts|contact|id', 519
    EXEC sp_OAMethod @xml, 'UpdateChildContent', NULL, 'content-groups', ''
    EXEC sp_OAMethod @xml, 'UpdateAttrAt', @success OUT, 'cxml-domain', 1, 'nil', 'true'
    EXEC sp_OAMethod @xml, 'UpdateAttrAt', @success OUT, 'cxml-http-username', 1, 'nil', 'true'
    EXEC sp_OAMethod @xml, 'UpdateAttrAt', @success OUT, 'cxml-identity', 1, 'nil', 'true'
    EXEC sp_OAMethod @xml, 'UpdateAttrAt', @success OUT, 'cxml-protocol', 1, 'nil', 'true'
    EXEC sp_OAMethod @xml, 'UpdateAttrAt', @success OUT, 'cxml-secret', 1, 'nil', 'true'
    EXEC sp_OAMethod @xml, 'UpdateAttrAt', @success OUT, 'cxml-ssl-version', 1, 'nil', 'true'
    EXEC sp_OAMethod @xml, 'UpdateAttrAt', @success OUT, 'cxml-supplier-domain', 1, 'nil', 'true'
    EXEC sp_OAMethod @xml, 'UpdateAttrAt', @success OUT, 'cxml-supplier-identity', 1, 'nil', 'true'
    EXEC sp_OAMethod @xml, 'UpdateAttrAt', @success OUT, 'cxml-url', 1, 'nil', 'true'
    EXEC sp_OAMethod @xml, 'UpdateChildContent', NULL, 'default-locale', 'en'
    EXEC sp_OAMethod @xml, 'UpdateChildContent', NULL, 'disable-cert-verify', 'false'
    EXEC sp_OAMethod @xml, 'UpdateChildContent', NULL, 'name', 'SIM load4 site name13'
    EXEC sp_OAMethod @xml, 'UpdateChildContent', NULL, 'po-change-method', 'prompt'
    EXEC sp_OAMethod @xml, 'UpdateAttrAt', @success OUT, 'po-email', 1, 'nil', 'true'
    EXEC sp_OAMethod @xml, 'UpdateChildContent', NULL, 'po-method', 'prompt'

    -- Adds the "Authorization: Bearer <access_token>" header.
    EXEC sp_OASetProperty @http, 'AuthToken', '<access_token>'

    DECLARE @sbRequestBody int
    -- Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0
    EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @sbRequestBody OUT

    EXEC sp_OAMethod @xml, 'GetXmlSb', @success OUT, @sbRequestBody

    DECLARE @resp int
    EXEC sp_OAMethod @http, 'PTextSb', @resp OUT, 'POST', '["id","supplier_information_id","kind","name_given","name_family","email"]}]', @sbRequestBody, 'utf-8', 'application/xml', 0, 0
    EXEC sp_OAGetProperty @http, 'LastMethodSuccess', @iTmp0 OUT
    IF @iTmp0 = 0
      BEGIN
        EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @http
        EXEC @hr = sp_OADestroy @xml
        EXEC @hr = sp_OADestroy @sbRequestBody
        RETURN
      END

    EXEC sp_OAGetProperty @resp, 'StatusCode', @iTmp0 OUT
    PRINT @iTmp0
    EXEC sp_OAGetProperty @resp, 'BodyStr', @sTmp0 OUT
    PRINT @sTmp0
    EXEC @hr = sp_OADestroy @resp


    EXEC @hr = sp_OADestroy @http
    EXEC @hr = sp_OADestroy @xml
    EXEC @hr = sp_OADestroy @sbRequestBody


END
GO

Curl Command

curl -X POST
	-H "Authorization: Bearer <access_token>"
	-d '<supplier-information-site>
    <active>true</active>
    <addresses>
        <address>
            <id>686</id>
        </address>
        <address>
            <id>687</id>
        </address>
    </addresses>
    <buyer-hold>false</buyer-hold>
    <code>SIM load4 code13</code>
    <contacts>
        <contact>
            <id>519</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>SIM load4 site name13</name>
    <po-change-method>prompt</po-change-method>
    <po-email nil="true"/>
    <po-method>prompt</po-method>
</supplier-information-site>'
https://domain.com/supplier_information/:id/supplier_information_sites?fields=["id","name","code","supplier_information_id",{"addresses": ["id","supplier_information_id","kind","location_code","address_name","street_address","street_address2","city","postal_code","state",{"country": ["id","code","name"]},{"custom_fields": {}}]},{"contacts": ["id","supplier_information_id","kind","name_given","name_family","email"]}]

Postman Collection Item JSON

{
  "name": "Create SIM SIte using SIM ID in POST URL",
  "request": {
    "method": "POST",
    "header": [
    ],
    "body": {
      "mode": "raw",
      "raw": "<supplier-information-site>\n    <active>true</active>\n    <addresses>\n        <address>\n            <id>686</id>\n        </address>\n        <address>\n            <id>687</id>\n        </address>\n    </addresses>\n    <buyer-hold>false</buyer-hold>\n    <code>SIM load4 code13</code>\n    <contacts>\n        <contact>\n            <id>519</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>SIM 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-information-site>",
      "options": {
        "raw": {
          "language": "xml"
        }
      }
    },
    "url": {
      "raw": "{{URL}}/supplier_information/:id/supplier_information_sites?fields=[\"id\",\"name\",\"code\",\"supplier_information_id\",{\"addresses\": [\"id\",\"supplier_information_id\",\"kind\",\"location_code\",\"address_name\",\"street_address\",\"street_address2\",\"city\",\"postal_code\",\"state\",{\"country\": [\"id\",\"code\",\"name\"]},{\"custom_fields\": {}}]},{\"contacts\": [\"id\",\"supplier_information_id\",\"kind\",\"name_given\",\"name_family\",\"email\"]}]",
      "host": [
        "{{URL}}"
      ],
      "path": [
        "supplier_information",
        ":id",
        "supplier_information_sites"
      ],
      "query": [
        {
          "key": "fields",
          "value": "[\"id\",\"name\",\"code\",\"supplier_information_id\",{\"addresses\": [\"id\",\"supplier_information_id\",\"kind\",\"location_code\",\"address_name\",\"street_address\",\"street_address2\",\"city\",\"postal_code\",\"state\",{\"country\": [\"id\",\"code\",\"name\"]},{\"custom_fields\": {}}]},{\"contacts\": [\"id\",\"supplier_information_id\",\"kind\",\"name_given\",\"name_family\",\"email\"]}]"
        }
      ],
      "variable": [
        {
          "key": "id",
          "value": "650"
        }
      ]
    }
  },
  "response": [
  ]
}