# Sending data (server)

Each request(trace) can be sent either through the browser or server side. In order to re-identify customers after they leave their email address (login, register, sign up for newsletter etc). edrone adds unique identifiers stored inside cookies(first-party&third-party) or localStorage to each request. Even after customers are logged out from the store, edrone is able to re-identifiy them. This is the main reason why the browser is a default option.

In cases when the store has access to customer email, those additional identifieres are not needed anymore.

You will find cases (based on action_type) where store can send request via server below:

# SUBSCRIBE

Subscription Change
The "subscribe" event allows to change customer subscription status. It's important to change field "sender_type" to server. Subscription change won't work without that.


<?php
  function subscriptionChange(){
    $edroneData = 'version=' . '1.0.0' .
       '&app_id=' . 'YOUR APP ID' .
       '&email=' . 'email@example.pl' .
       '&subscriber_status=' . '0/1' .
       '&action_type=' . 'subscribe' .
       '&sender_type=' . 'server';
       return $edroneData;
    }

function httpPost($url, $params) {
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HEADER, false);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));
    $output = curl_exec($ch);
    curl_close($ch);
    return $output;
}
  httpPost('https://api.edrone.me/trace', subscriptionChange());


# ORDER CANCEL

Order cancel
The "order_cancel" event allows marking orders in edrone CRM system as deleted.


<?php
  function orderCancel(){
    $edroneData = 'version=' . '1.0.0' .
       '&app_id=' . 'YOUR APP ID' .
       '&email=' . 'email@example.pl' .
       '&order_id=' . '00001' .
       '&action_type=' . 'order_cancel' .
       '&sender_type=' . 'server';
       return $edroneData;
    }

function httpPost($url, $params) {
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HEADER, false);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));
    $output = curl_exec($ch);
    curl_close($ch);
    return $output;
}
  httpPost('https://api.edrone.me/trace', orderCancel());

# ORDER


<?php
function order(){
    $product_ids = array('P123', 'P456', 'P789');
    $product_titles = array('Product 1', 'Product 2', 'Product 3');
    $product_images = array('https://example.com/product1.jpg', 'https://example.com/product2.jpg', 'https://example.com/product3.jpg');
    $product_urls = array('https://example.com/product1', 'https://example.com/product2', 'https://example.com/product3');
    $product_counts = array(1, 2, 1);
    $product_category_ids = array('C123', 'C456', 'C789');
    $product_category_names = array('Category 1', 'Category 2', 'Category 3');

    $order = new stdClass();
    $order->email = 'john@example.com';
    $order->first_name = 'John';
    $order->last_name = 'Doe';
    $order->order_id = 'ORD123';
    $order->order_payment_value = 100.00;
    $order->order_currency = 'USD';
    $order->country = 'US';
    $order->city = 'New York';
    $order->phone = '1234567890';
    $order->customer_tags = array('tag1', 'tag2');
    $order->event_date = '2023-04-17T12:34:56Z';

    $edroneData = 'version=' . '1.0.0' .
        '&app_id=' . 'YOUR APP ID' .
        '&email=' . $order->email .
        '&first_name=' . $order->first_name .
        '&last_name=' . $order->last_name .
        '&product_ids=' . join('|', $product_ids) .
        '&product_titles=' . join('|', $product_titles) .
        '&product_images=' . join('|', $product_images) .
        '&product_urls=' . join('|', $product_urls) .
        '&product_counts=' . join('|', $product_counts) .
        '&product_category_ids=' . join('|', $product_category_ids) .
        '&product_category_names=' . join('|', $product_category_names) .
        '&order_id=' . $order->order_id .
        '&order_payment_value=' . $order->order_payment_value .
        '&base_payment_value=' . $order->order_payment_value .
        '&sender_type=' . 'server' .
        '&base_currency=' . $order->order_currency .
        '&order_currency=' . $order->order_currency .
        '&action_type=' . 'order' .
        '&country=' . $order->country .
        '&city=' . $order->city .
        '&phone=' . $order->phone .
        '&customer_tags=' . join('|', $order->customer_tags) .
        '&subscriber_status=' . '' .
        '&event_utc_date=' . $order->event_date;
    return $edroneData;
}


function httpPost($url, $params) {
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HEADER, false);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));
    $output = curl_exec($ch);
    curl_close($ch);
    return $output;
}


httpPost('https://api.edrone.me/trace', order());