Como adicionar pedido via API ?

POST: http://www.nomedoseusite.com.br/api_ds_orders.php?action=add_orders

Header Parameter Format
Token base64_encode()
Secret base64_encode()
E-mail base64_encode()
Parameter Format Description
products_id JSON Use the API to list the order data to get the product_id
Format: int(11)
products_quantity JSON Quantity number
Only number is required
products JSON products_id & products_quantity
delivery_firstname JSON Firstname
Format: varchar(255)
* FIELD REQUIRED
delivery_lastname JSON Lastname
Format: varchar(255)
* FIELD REQUIRED
delivery_street_address JSON Street address
Format: varchar(255)
* FIELD REQUIRED
delivery_number JSON Delivery Number
Format: varchar(255)
* FIELD REQUIRED
delivery_suburb JSON Suburb
Format: varchar(255)
* FIELD REQUIRED
delivery_city JSON
City
Format: varchar(255)
* FIELD REQUIRED
delivery_postcode JSON Post Code
Format: varchar(11)
* FIELD REQUIRED
delivery_country JSON Country Name
Format: varchar(255)
* FIELD REQUIRED
delivery_state JSON State Name
Format: varchar(2)
* FIELD REQUIRED
payment_method JSON Use the API to payment_method
Format: varchar(255)
* FIELD REQUIRED
shipping_method JSON Use the API to calculate_shipping
Format: varchar(255)
* FIELD REQUIRED

PHP Sample

 // sample add_orders
 
 $url = $domain_url . '/api_ds_orders.php?action=add_orders';
 
 $data_products[0] = array("products_id" => "215", // Example: 130 (Only number is required) * FIELD REQUIRED
 "products_quantity" => "1" // Example: 1 (Only number is required) * FIELD REQUIRED
 );
 
 $data_products[1] = array("products_id" => "215", // Example: 130 (Only number is required) * FIELD REQUIRED
 "products_quantity" => "1" // Example: 1 (Only number is required) * FIELD REQUIRED
 );

 $data = array("products" => $data_products, // * FIELD REQUIRED
 "delivery_firstname" => utf8_encode("Name"), // Example: Name (Firstname) * FIELD REQUIRED
 "delivery_lastname" => utf8_encode("Surname"), // Example: Surname (Lastname) * FIELD REQUIRED
 "delivery_street_address" => utf8_encode("Street address"), // Example: Street address (Street Address) * FIELD REQUIRED
 "delivery_number" => "123", // Example: 123 (Delivery Number) * FIELD REQUIRED
 "delivery_suburb" => utf8_encode("Suburb"), // Example: Suburb (Suburb) * FIELD REQUIRED
 "delivery_city" => utf8_encode("Sao Paulo"), // Example: Sao Paulo (City) * FIELD REQUIRED
 "delivery_postcode" => "04267000", // Example: 04267000 (Post Code) * FIELD REQUIRED
 "delivery_country" => utf8_encode("Brazil"), // Example: Brazil (Country) * FIELD REQUIRED
 "delivery_state" => utf8_encode("SP"), // Example: SP (State) * FIELD REQUIRED
 "payment_method" => "paypal_standard", // Example: paypal_standard (Payment Method) * FIELD REQUIRED
 "shipping_method" => "sedex" // Example: sedex (Shipping Method) * FIELD REQUIRED
 );
 
 $data_string = json_encode($data); 
// print_r($data_string);
// die;

 $ch = curl_init($url);
 curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); 
 curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string); 
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
 curl_setopt($ch, CURLOPT_HTTPHEADER, array( 
 'Content-Type: application/json',
 "Cache-Control: no-cache", 
 'Token: ' . base64_encode($token),
 'Secret: ' . base64_encode($secret),
 'E-mail: ' . base64_encode($email),
 'Content-Length: ' . strlen($data_string))
 );
 
 $result = curl_exec($ch);
 curl_close($ch);

 print_r($result);
 // sample add_orders eof

Return Error:

code
message

Return Success:

code
products_model
products_id
message

Deixe um comentário 0