smarkio/smarkio-supplier-api-client

Accelerator to communicate with the Smarkio Supplier API

1.7.2 2018-12-17 12:02 UTC

This package is not auto-updated.

Last update: 2024-12-21 17:35:10 UTC


README

An accelerator to communicate with © Smarkio API to create Leads

Installation and usage with Composer

Add the following to your composer.json file in order to fetch the latest stable version of the project:

{
    "require": {
        "smarkio/smarkio-supplier-api-client": "*"
    }
}

Then, in order to use the accelerator on your own PHP file, add the following:

require '[COMPOSER_VENDOR_PATH]/autoload.php';

Contents

  • src/Smarkio/Supplier - Code to interact with the Smarkio Lead API.
  • examples/ - Some examples on how to use this accelerator.

Before you start

You need to obtain one API token to use the API. This token is bound to each user of the Smarkio system details.

Usage

Send a Lead

$api_token = 'YOUR API TOKEN HERE';
$external_id = '1';
$campaign_external_id = '98';
$ip_address = '74.125.224.72';
$email = 'dummy@example.net';
$domain = 'mywebsite.example.net';

// create Lead with mandatory parameters
$lead = new Lead($api_token, $external_id, $campaign_external_id, $ip_address, $email, $domain);

// send the Lead
$response = $lead->send();

Send a Lead with Files associated

$api_token = 'YOUR API TOKEN HERE';
$external_id = '1';
$campaign_external_id = '98';
$ip_address = '74.125.224.72';
$email = 'dummy@example.net';
$domain = 'mywebsite.example.net';

// create Lead with mandatory parameters
$lead = new Lead($api_token, $external_id, $campaign_external_id, $ip_address, $email, $domain);

//Attach some files to it
$lead->setFiles([
    'photo' => "http://example.com/image.png",
    'cc' => "http://example.com/cc.png"
]);
// send the Lead
$response = $lead->send();

Send a Lead with additional fields

$api_token = 'YOUR API TOKEN HERE';
$external_id = '1';
$campaign_external_id = '98';
$ip_address = '74.125.224.72';
$email = 'dummy@example.net';
$domain = 'mywebsite.example.net';

// create Lead with mandatory parameters
$lead = new Lead($api_token, $external_id, $campaign_external_id, $ip_address, $email, $domain);

// set Lead's optional parameters
$lead->setFirstName('João');
$lead->setLastName('Silva');
$lead->setPayout('12.12');

// set Lead's extra information
$lead->addExtraField('profession', 'developer');
$lead->addExtraField('nationality', 'portuguese');

// send the Lead
$response = $lead->send();

Force new Lead creation

If you want to force the creation of a new Lead, bypassing the conditions that would update an existing one, use the method setForceNewLeadCreation():

$api_token = 'YOUR API TOKEN HERE';
$external_id = '1';
$campaign_external_id = '98';
$ip_address = '74.125.224.72';
$email = 'dummy@example.net';
$domain = 'mywebsite.example.net';

// create Lead with mandatory parameters
$lead = new Lead($api_token, $external_id, $campaign_external_id, $ip_address, $email, $domain);

// force new lead creation
$lead->setForceNewLeadCreation(true);

// send the Lead
$response = $lead->send();

Dump lead Info

If you want to receive lead info on response, use the method setDumpLeadInfo():

$api_token = 'YOUR API TOKEN HERE';
$external_id = '1';
$campaign_external_id = '98';
$ip_address = '74.125.224.72';
$email = 'dummy@example.net';
$domain = 'mywebsite.example.net';

// create Lead with mandatory parameters
$lead = new Lead($api_token, $external_id, $campaign_external_id, $ip_address, $email, $domain);

// dump lead info
$lead->setDumpLeadInfo();

// send the Lead
$response = $lead->send();

In this case, the $response will contain a new field called lead_info.

User custom API URL

European API URL (Default):
$response = $lead->send();

or

$response = $lead->send(Lead::API_BASE_URL_EU);
Brazilian API URL:
$response = $lead->send(Lead::API_BASE_URL_BR);
Custom API URL:
$response = $lead->send('https://api-custom-example.smark.io');

Response format

The response is a JSON containing at least a 'code' and 'message' fields. The code 200 indicates that the lead was integrated successfully.

{"code":"200","message":"OK","lead_id":"85177", "smkid": "1:rLJGWJLW2mNNS2qq"}

Fields available

The following lead fields are available:

Extra parameters can be sent via:

Processing flags (NOTE: if both lead field and flag with same name are filled, lead field will have precedence):