Comment pouvons nous vous aider ? 👋

API createOrder

1. Code to use

<?php
    // ================================================================================
    // DATA PREPARATION
    // ================================================================================
    $post_data = array();
    // ---------------------------- Profile attributes -------------------------------
    $post_data["data"]["customer_email"] = "john@doe.com";
    $post_data["data"]["external_id"] = "12345xxx6789";
    if (isset($_COOKIE['sbt'])) // Save the customer's authentication cookie if it is present.
    {
       $post_data["data"]["customer_cookie"] = $_COOKIE['sbt'];
    }
    $post_data["data"]["customer_name"] = "Doe";
    $post_data["data"]["customer_firstname"] = "John";
    $post_data["data"]["customer_isoptin"] = "1"; // 1:optin / 0:not optin / -1: unknown
    $post_data["data"]["customer_gender"] = "male"; // "male" or "female"
    $post_data["data"]["customer_address"] = "8, rue de la place";
    $post_data["data"]["customer_address2"] = "bâtiment A";
    $post_data["data"]["customer_address3"] = "appartement 23";
    $post_data["data"]["customer_cp"] = "76000";
    $post_data["data"]["customer_city"] = "Rouen";
    $post_data["data"]["customer_country"] = "FR";
    $post_data["data"]["customer_tel"] = "0235000000";
    $post_data["data"]["customer_mobile"] = "060606606";
    $post_data["data"]["customer_fonction"] = "developer";
    $post_data["data"]["customer_company"] = "SPREAD";
    $post_data["data"]["customer_birthday"] = "1970-12-31";
    $post_data["data"]["customer_lang"] = "fr_FR";
    $post_data["data"]["add_tag"] = array("tag1", "tag2"); // Adding customer tags
    $post_data["data"]["del_tag"] = array("tag3", "tag4"); // Removal of customer tags
    $post_data["data"]["action"] = "order";
    // Custom fields
    $post_data["data"]["custom_fields"][327] = "value"; // ID of the custom_field to be found in your BackOffice, at the bottom of "Intégration > Tracker > Intégration > Exemple de codes".
    // --------------------------- Attributes of the command ---------------------------
     $post_data["data"]["order_idorder"] = "0000001";
    $post_data["data"]["order_state"] = "10"; // 10:taked / 20:paid / 50:sent / 100:recieved
    $post_data["data"]["order_amount"] = 158.31;
    $post_data["data"]["order_crea_dt"] = "2014-06-21 14:31:08"; // Y-m-d H:i:s (UTC)
    $post_data["data"]["order_start_service"] = "2019-06-05"; // Y-m-d
    $post_data["data"]["order_end_service"] = "2019-06-14"; // Y-m-d
    // Product attributes of the order
    $post_data["data"]["product_attributes"] = array(
        array("size:xl", "type:shirt"), // product 1
        array("size:s", "color:blue"), // product 2
    );
    //$post_data["data"]["product_attributes"] = array(); //Leave empty to remove all attributes
    // Order tags
    $post_data["data"]["add_order_tag"] = array("tag_commande_1", "tag_commande_2"); // Adding tags to the order
    $post_data["data"]["del_order_tag"] = array("tag_commande_3", "tag_commande_4"); // Removal of tags on the order

    // ================================================================================
    // CURL CALL
    // ================================================================================
    $curl_post_data = http_build_query($post_data);
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, "https://social-sb.com/api/createOrder");
    curl_setopt($curl, CURLOPT_POST, true);
    curl_setopt($curl, CURLOPT_POSTREDIR, CURL_REDIR_POST_ALL);
    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
    curl_setopt($curl, CURLOPT_USERPWD, "PUBLIC_KEY:PRIVATE_KEY"); // To be replaced by your public and private API keys in your back office, menu "Integration > Tracker" at the bottom of the page
    curl_setopt($curl, CURLOPT_POSTFIELDS,$curl_post_data );
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    $curl_return = curl_exec($curl);
    curl_close($curl);
 ?>

2. Explications

Connect the site with the SPREAD BackOffice

In the CURL call at the end of the code, insert your public and private API keys. You can find them in your BackOffice, tab Intégration > Tracker.

 

Profile attributes

Notion image
 

Custom Fields

You can add more information to SPREAD profiles by creating custom fields. These can be filled in different ways and you can upload information to them in PHP.

To do this, use $post_data["data"]["custom_fields"][327] = "value";

327 is a custom field identifier here, find yours at the bottom of this page.

Notion image
 

Order attributes

To pull up orders, you must include at least this information:

  • customer_email and/or external_id as the profile ID,
  • order_idorder as the order reference,
  • order_state for the order status,
  • order_amount for the order amount,
  • order_crea_dt for the order date.
 

Matching of order statuses

  • 0 : cancelled orders These orders are not included in the sales figures.
  • 10 : status of orders for which payment has not yet been validated These orders do not count as sales unless you configure it in the SPREAD BackOffice, Integration > Tracker > Statut de commande.
  • 20 : status of paid orders
  • 50 : status of shipped orders
  • 100 : status of completed orders, with payment made and order delivered to customer
 

Management of the idorder

The idorder value is the unique identifier of the order on the store.

The first time this ID is used, the order is recorded in the CRM. If the order id is presented a second time, the data is updated.

This ID is especially useful to change the status of the order (cancel it or put it to ship).

You can also complete the order information with:

  • Order tags,
  • Start and end dates of the service,
  • Product attributes.
 

Tagging orders

This allows you to categorize the order. For example: indicate the establishment concerned, the type of order (reservation, subscription...)

To do this, use :

  • add_order_tag to add one or more tags during the upload,
  • del_order_tag to delete one or more tags during the upload.

Performance dates

This allows you to indicate the start and end dates of a service such as a subscription with a limited duration, reservations (stays, hotel...)

For this, use the format yyyy-mm-dd :

  • order_start_service
  • order_end_service
 

Product attributes

You can add product attributes to return to the profile about the products included in his order.

You do this with the following code:

$post_data["data"]["product_attributes"] = array(
        array("size:xl", "type:shirt"), // product 1
        array("size:s", "color:blue"), // product 2
    );
 

Newsletter Subscription

Newsletter subscriptions require the profile email address.

In SPREAD, each consent has a technical ID that you can customize.

You can retrieve the newsletter and SMS subscriptions with these settings:

  • customer_isoptin
  • customer_mobile_isoptin
 
 
🆘
If you have any further questions about this topic, you can contact support. 💬
Cela a-t-il répondu à votre question ?
😞
😐
🤩