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"?>
// <order-header>
// <type>ExternalOrderHeader</type>
// <po-number>PO-957645-14</po-number>
// <order-lines type="array">
// <order-line>
// <description>Testing Kit 2</description>
// <line-num>3</line-num>
// <price type="decimal">100.00</price>
// <quantity type="decimal">1.0</quantity>
// <type>OrderQuantityLine</type>
// <account-allocations type="array">
// <account-allocation>
// <amount type="decimal">10.00</amount>
// <pct type="decimal">10.0</pct>
// <account>
// <code>SF-IT-Assets</code>
// <account-type>
// <name>Ace Corporate</name>
// </account-type>
// </account>
// </account-allocation>
// <account-allocation>
// <amount type="decimal">90.00</amount>
// <pct type="decimal">90.0</pct>
// <account>
// <code>SF-Sales-Assets</code>
// <account-type>
// <name>Ace Corporate</name>
// </account-type>
// </account>
// </account-allocation>
// </account-allocations>
// <currency>
// <code>USD</code>
// </currency>
// <uom>
// <code>EA</code>
// </uom>
// </order-line>
// </order-lines>
// </order-header>
//
CkoXml *xml = [[CkoXml alloc] init];
xml.Tag = @"order-header";
[xml UpdateChildContent: @"type" value: @"ExternalOrderHeader"];
[xml UpdateChildContent: @"po-number" value: @"PO-957645-14"];
[xml UpdateAttrAt: @"order-lines" autoCreate: YES attrName: @"type" attrValue: @"array"];
[xml UpdateChildContent: @"order-lines|order-line|description" value: @"Testing Kit 2"];
[xml UpdateChildContentInt: @"order-lines|order-line|line-num" value: [NSNumber numberWithInt: 3]];
[xml UpdateAttrAt: @"order-lines|order-line|price" autoCreate: YES attrName: @"type" attrValue: @"decimal"];
[xml UpdateChildContent: @"order-lines|order-line|price" value: @"100.00"];
[xml UpdateAttrAt: @"order-lines|order-line|quantity" autoCreate: YES attrName: @"type" attrValue: @"decimal"];
[xml UpdateChildContent: @"order-lines|order-line|quantity" value: @"1.0"];
[xml UpdateChildContent: @"order-lines|order-line|type" value: @"OrderQuantityLine"];
[xml UpdateAttrAt: @"order-lines|order-line|account-allocations" autoCreate: YES attrName: @"type" attrValue: @"array"];
[xml UpdateAttrAt: @"order-lines|order-line|account-allocations|account-allocation|amount" autoCreate: YES attrName: @"type" attrValue: @"decimal"];
[xml UpdateChildContent: @"order-lines|order-line|account-allocations|account-allocation|amount" value: @"10.00"];
[xml UpdateAttrAt: @"order-lines|order-line|account-allocations|account-allocation|pct" autoCreate: YES attrName: @"type" attrValue: @"decimal"];
[xml UpdateChildContent: @"order-lines|order-line|account-allocations|account-allocation|pct" value: @"10.0"];
[xml UpdateChildContent: @"order-lines|order-line|account-allocations|account-allocation|account|code" value: @"SF-IT-Assets"];
[xml UpdateChildContent: @"order-lines|order-line|account-allocations|account-allocation|account|account-type|name" value: @"Ace Corporate"];
[xml UpdateAttrAt: @"order-lines|order-line|account-allocations|account-allocation[1]|amount" autoCreate: YES attrName: @"type" attrValue: @"decimal"];
[xml UpdateChildContent: @"order-lines|order-line|account-allocations|account-allocation[1]|amount" value: @"90.00"];
[xml UpdateAttrAt: @"order-lines|order-line|account-allocations|account-allocation[1]|pct" autoCreate: YES attrName: @"type" attrValue: @"decimal"];
[xml UpdateChildContent: @"order-lines|order-line|account-allocations|account-allocation[1]|pct" value: @"90.0"];
[xml UpdateChildContent: @"order-lines|order-line|account-allocations|account-allocation[1]|account|code" value: @"SF-Sales-Assets"];
[xml UpdateChildContent: @"order-lines|order-line|account-allocations|account-allocation[1]|account|account-type|name" value: @"Ace Corporate"];
[xml UpdateChildContent: @"order-lines|order-line|currency|code" value: @"USD"];
[xml UpdateChildContent: @"order-lines|order-line|uom|code" value: @"EA"];
// Adds the "Authorization: Bearer <access_token>" header.
http.AuthToken = @"<access_token>";
[http SetRequestHeader: @"Accept" value: @"application/json"];
CkoStringBuilder *sbRequestBody = [[CkoStringBuilder alloc] init];
[xml GetXmlSb: sbRequestBody];
CkoHttpResponse *resp = [http PTextSb: @"PUT" url: @"https://domain.com/purchase_orders/:id?fields=[\"id\"]" 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 PUT
-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-14</po-number>
<order-lines type="array">
<order-line>
<description>Testing Kit 2</description>
<line-num>3</line-num>
<price type="decimal">100.00</price>
<quantity type="decimal">1.0</quantity>
<type>OrderQuantityLine</type>
<account-allocations type="array">
<account-allocation>
<amount type="decimal">10.00</amount>
<pct type="decimal">10.0</pct>
<account>
<code>SF-IT-Assets</code>
<account-type>
<name>Ace Corporate</name>
</account-type>
</account>
</account-allocation>
<account-allocation>
<amount type="decimal">90.00</amount>
<pct type="decimal">90.0</pct>
<account>
<code>SF-Sales-Assets</code>
<account-type>
<name>Ace Corporate</name>
</account-type>
</account>
</account-allocation>
</account-allocations>
<currency>
<code>USD</code>
</currency>
<uom>
<code>EA</code>
</uom>
</order-line>
</order-lines>
</order-header>'
https://domain.com/purchase_orders/:id?fields=["id"]
Postman Collection Item JSON
{
"name": "Add line w/ allocations to external PO",
"request": {
"method": "PUT",
"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-14</po-number>\n <order-lines type=\"array\">\n <order-line>\n <description>Testing Kit 2</description>\n <line-num>3</line-num>\n <price type=\"decimal\">100.00</price>\n <quantity type=\"decimal\">1.0</quantity>\n <type>OrderQuantityLine</type>\n <account-allocations type=\"array\">\n <account-allocation>\n <amount type=\"decimal\">10.00</amount>\n <pct type=\"decimal\">10.0</pct>\n <account>\n <code>SF-IT-Assets</code>\n <account-type>\n <name>Ace Corporate</name>\n </account-type>\n </account>\n </account-allocation>\n <account-allocation>\n <amount type=\"decimal\">90.00</amount>\n <pct type=\"decimal\">90.0</pct>\n <account>\n <code>SF-Sales-Assets</code>\n <account-type>\n <name>Ace Corporate</name>\n </account-type>\n </account>\n </account-allocation>\n </account-allocations>\n <currency>\n <code>USD</code>\n </currency>\n <uom>\n <code>EA</code>\n </uom>\n </order-line>\n </order-lines>\n</order-header>",
"options": {
"raw": {
"language": "xml"
}
}
},
"url": {
"raw": "{{URL}}/purchase_orders/:id?fields=[\"id\"]",
"host": [
"{{URL}}"
],
"path": [
"purchase_orders",
":id"
],
"query": [
{
"key": "fields",
"value": "[\"id\"]"
}
],
"variable": [
{
"key": "id",
"value": "3238"
}
]
}
},
"response": [
]
}