The Clothes2order API is designed to be simple to integrate into any existing platform. Below is a basic PHP code example to get you started. The example is available to suit both XML and JSON formats (click the option in the top right to change your preference).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
<?php /* API Post Order Test Script Clothes2order.com */ //Defines define('API_KEY','your-api-key'); define('API_URL','https://www.clothes2order.com/api/post-order/'); //Set your data here $post_data = ' <xml> <api_key>' . API_KEY . '</api_key> <order> <order_id>123456</order_id> <order_notes><![CDATA[Any extra information here]]></order_notes> <delivery_method>standard</delivery_method> </order> <customer> <name>Name Here</name> <email>email@email.com</email> <telephone>0161123456</telephone> </customer> <address> <delivery_name>Name</delivery_name> <company_name>Quayside Clothing Ltd</company_name> <address_line_1>Unit 9 Wheel Forge Way</address_line_1> <address_line_2>Trafford Park</address_line_2> <city>Manchester</city> <postcode>M17 1EH</postcode> <country>United Kingdom</country> </address> <products> <product> <sku>594-117-15</sku> <quantity>2</quantity> <logos> <logo> <unique_id>TEST_02</unique_id> <file><![CDATA[http://www.clothes2order.com/images/c2o_new_2013/layout/carousel/15.jpg]]></file> <position>3</position> <width>8</width> <type>print</type> </logo> <logo> <unique_id>TEST_03</unique_id> <file><![CDATA[http://www.clothes2order.com/images/c2o_new_2013/layout/carousel/14.jpg]]></file> <position>5</position> <width>12</width> <type>print</type> </logo> </logos> </product> <product> <sku>1316-1-13</sku> <quantity>1</quantity> <logos> <logo> <unique_id>TEST_04</unique_id> <file><![CDATA[http://www.clothes2order.com/images/c2o_new_2013/layout/carousel/32.jpg]]></file> <position>5</position> <width>10</width> <type>embroidery</type> </logo> <logo> <unique_id></unique_id> <file><![CDATA[http://www.clothes2order.com/images/c2o_new_2013/layout/carousel/16.jpg]]></file> <position>9</position> <width>25</width> <type>print_1colour</type> </logo> </logos> </product> </products> </xml> '; //Post data to the API $ch = curl_init(API_URL); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/xml', 'Accept: application/xml' ) ); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); $ch_result = curl_exec($ch); $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); //Get response $obj = simplexml_load_string($ch_result); //Check HTTP status if ($http_code == 200) { //All OK echo 'All seems OK: ' . $obj->status->msg . "<br />\n"; //Lets echo some values echo 'Clothes2order order ID: ' . $obj->order_details->order_id . "<br />\n"; echo 'This order has cost you: £' . $obj->order_details->net_order_value . "<br />\n"; echo 'Estimated dispatch date: ' . $obj->order_details->est_dispatch_date . "<br />\n"; if (sizeof($obj->warnings->warning) > 0) { foreach ((array)$obj->warnings->warning as $warning) { echo 'Warning: ' . $warning . "<br />\n"; } } if (sizeof($obj->test_msgs->msg) > 0) { foreach ((array)$obj->test_msgs->msg as $test_msg) { echo 'Test message: ' . $test_msg . "<br />\n"; } } } elseif ($http_code == 400) { //There was an error echo 'Error occured: ' . $obj->status->msg . "<br />\n"; } exit; ?> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
<?php /* API Post Order Test Script Clothes2order.com */ //Defines define('API_KEY','your-api-key'); define('API_URL','https://www.clothes2order.com/api/post-order/'); //Set your data here $post_data = ' { "api_key": "' . API_KEY . '", "order": { "order_id": "123456", "order_notes": "Any extra information here", "delivery_method": "standard" }, "customer": { "name": "Name Here", "email": "email@email.com", "telephone": "0161123456" }, "address": { "delivery_name": "Name", "company_name": "Quayside Clothing Ltd", "address_line_1": "Unit 9 Wheel Forge Way", "address_line_2": "Trafford Park", "city": "Manchester", "postcode": "M17 1EH", "country": "United Kingdom" }, "products": { "product": [ { "sku": "594-117-15", "quantity": "2", "logos": { "logo": [ { "unique_id": "TEST_02", "file": "http:\/\/www.clothes2order.com\/images\/c2o_new_2013\/layout\/carousel\/15.jpg", "position": "3", "width": "8", "type": "print" }, { "unique_id": "TEST_03", "file": "http:\/\/www.clothes2order.com\/images\/c2o_new_2013\/layout\/carousel\/14.jpg", "position": "5", "width": "12", "type": "print" } ] } }, { "sku": "1316-1-13", "quantity": "1", "logos": { "logo": [ { "unique_id": "TEST_04", "file": "http:\/\/www.clothes2order.com\/images\/c2o_new_2013\/layout\/carousel\/32.jpg", "position": "5", "width": "10", "type": "embroidery" }, { "unique_id": "", "file": "http:\/\/www.clothes2order.com\/images\/c2o_new_2013\/layout\/carousel\/16.jpg", "position": "9", "width": "25", "type": "print_1colour" } ] } } ] } } '; //Post data to the API $ch = curl_init(API_URL); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Accept: application/json' ) ); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); $ch_result = curl_exec($ch); $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); //Get response $obj = json_decode($ch_result); //Check HTTP status if ($http_code == 200) { //All OK echo 'All seems OK: ' . $obj->status->msg . "<br />\n"; //Lets echo some values echo 'Clothes2order order ID: ' . $obj->order_details->order_id . "<br />\n"; echo 'This order has cost you: £' . $obj->order_details->net_order_value . "<br />\n"; echo 'Estimated dispatch date: ' . $obj->order_details->est_dispatch_date . "<br />\n"; if (sizeof($obj->warnings->warning) > 0) { foreach ((array)$obj->warnings->warning as $warning) { echo 'Warning: ' . $warning . "<br />\n"; } } if (sizeof($obj->test_msgs->msg) > 0) { foreach ((array)$obj->test_msgs->msg as $test_msg) { echo 'Test message: ' . $test_msg . "<br />\n"; } } } elseif ($http_code == 400) { //There was an error echo 'Error occured: ' . $obj->status->msg . "<br />\n"; } exit; ?> |
You can download these example files on our code resources page.