Chilkat Online Tools

Objective-C / Coupa Postman Collection - OAuth - Master / Create SIM SIte using SIM ID in POST URL

Back to Collection Items

#import <CkoHttp.h>
#import <CkoXml.h>
#import <CkoStringBuilder.h>
#import <CkoHttpResponse.h>

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

CkoHttp *http = [[CkoHttp alloc] init];
BOOL success;

// 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>
// 

CkoXml *xml = [[CkoXml alloc] init];
xml.Tag = @"supplier-information-site";
[xml UpdateChildContent: @"active" value: @"true"];
[xml UpdateChildContentInt: @"addresses|address|id" value: [NSNumber numberWithInt: 686]];
[xml UpdateChildContentInt: @"addresses|address[1]|id" value: [NSNumber numberWithInt: 687]];
[xml UpdateChildContent: @"buyer-hold" value: @"false"];
[xml UpdateChildContent: @"code" value: @"SIM load4 code13"];
[xml UpdateChildContentInt: @"contacts|contact|id" value: [NSNumber numberWithInt: 519]];
[xml UpdateChildContent: @"content-groups" value: @""];
[xml UpdateAttrAt: @"cxml-domain" autoCreate: YES attrName: @"nil" attrValue: @"true"];
[xml UpdateAttrAt: @"cxml-http-username" autoCreate: YES attrName: @"nil" attrValue: @"true"];
[xml UpdateAttrAt: @"cxml-identity" autoCreate: YES attrName: @"nil" attrValue: @"true"];
[xml UpdateAttrAt: @"cxml-protocol" autoCreate: YES attrName: @"nil" attrValue: @"true"];
[xml UpdateAttrAt: @"cxml-secret" autoCreate: YES attrName: @"nil" attrValue: @"true"];
[xml UpdateAttrAt: @"cxml-ssl-version" autoCreate: YES attrName: @"nil" attrValue: @"true"];
[xml UpdateAttrAt: @"cxml-supplier-domain" autoCreate: YES attrName: @"nil" attrValue: @"true"];
[xml UpdateAttrAt: @"cxml-supplier-identity" autoCreate: YES attrName: @"nil" attrValue: @"true"];
[xml UpdateAttrAt: @"cxml-url" autoCreate: YES attrName: @"nil" attrValue: @"true"];
[xml UpdateChildContent: @"default-locale" value: @"en"];
[xml UpdateChildContent: @"disable-cert-verify" value: @"false"];
[xml UpdateChildContent: @"name" value: @"SIM load4 site name13"];
[xml UpdateChildContent: @"po-change-method" value: @"prompt"];
[xml UpdateAttrAt: @"po-email" autoCreate: YES attrName: @"nil" attrValue: @"true"];
[xml UpdateChildContent: @"po-method" value: @"prompt"];

// Adds the "Authorization: Bearer <access_token>" header.
http.AuthToken = @"<access_token>";

CkoStringBuilder *sbRequestBody = [[CkoStringBuilder alloc] init];
[xml GetXmlSb: sbRequestBody];

CkoHttpResponse *resp = [http PTextSb: @"POST" url: @"[\"id\",\"supplier_information_id\",\"kind\",\"name_given\",\"name_family\",\"email\"]}]" textData: sbRequestBody charset: @"utf-8" contentType: @"application/xml" md5: NO gzip: NO];
if (http.LastMethodSuccess == NO) {
    NSLog(@"%@",http.LastErrorText);
    return;
}

NSLog(@"%d",[resp.StatusCode intValue]);
NSLog(@"%@",resp.BodyStr);

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": [
  ]
}