Datan tuominen LianaAutomationiin on melko suoraviivaista.
Ennen kuin voimme tuoda dataa, meidän täytyy luoda kanava LianaAutomationiin vastaanottamaan data. Tälle kanavalle täytyy olla sallittu datan tuonti.
Jokaisella tuontipyynnöllä voit tuoda dataa vain yhteen kanavaan kerrallaan. Voit kuitenkin tuoda useita tapahtumia useille kontakteille samassa tuontipyynnössä.
Luo kanava
Mene LianaAutomationiin
Luo kanava kohdassa Asetukset -> Kanavat
Anna kanavalle nimi ja halutessasi myös kuvake ja väri
Anna kanavalle nimi. Nimen täytyy olla yksilöllinen
-
Rastita seuraavat valintaruudut:
“Tuonti sallittu”
“Tapahtumankuuntelijat sallittu”
Tallenna kanava
Avaa kanava uudelleen ja merkitse ylös näytetyn Kanavan ID
Datarakenne
LianaAutomationissa data esitetään tapahtumina (Event), jotka liittyvät tiettyyn kontaktiin.
Kontakti tunnistetaan sähköpostiosoitteen, puhelinnumeron, järjestelmäsi uniikin avaimen tai tokenin (seuranta-skriptin evästeen) avulla (tässä prioriteettijärjestyksessä). Aina kun jokin näistä vastaa toista kontaktia järjestelmässä, tieto päivitetään uudella datalla jättäen määrittelemättömät tiedot ennalleen. Kun olemassa olevan kontaktin tiedot ovat jo tiedossa LianaAutomationissa, ne yhdistetään yhdeksi kontaktiksi, joka sisältää koko historian, mikäli ristiriitoja ei ole (lue lisää artikkelista Kontaktien yhdistyminen tuonnin yhteydessä).
Tapahtumat sisältävät varsinaisen datan. Esimerkiksi kontakti on luonut tilauksen, mikä näkyy LianaAutomationissa tilaus-tapahtumana. Tätä tilaustyyppiä kutsumme verbiksi. Jokaisella tapahtumalla on omat ominaisuutensa tai kohteensa, kuten id, tila, päivämäärä jne. Näitä kutsutaan kohteiksi.
Kun dataa lisätään useaan kertaan, duplikaattien laskuri kasvaa ja tapahtuman päivämäärä päivitetään viimeisimmän lisäyksen mukaan. Voit valita, ettei duplikaatteja luoda, jolloin tapahtuman päivämäärä säilyy alkuperäisenä no_duplicates-ominaisuuden avulla. Tämä tarkoittaa myös, että segmenttiä ei käynnistetä, jos tapahtuma on duplikaatti.
Esimerkki:
{
"channel": "3", // Your channel system name or id
"no_duplicates": false, // When true, duplicate events are ignored
"data": [ // Data section (array)
{
"identity": { // Identity section
"email": "someone@domain.com", // Email identifier
"sms": "+358123456789", // Phone number identifier
"extra1": "abcdef", // external identifier 1
"token": "afd4345ddfe" // cookie identifier
},
"events": [ // events section (array)
{
"verb": "order", // type of event
"items": { // event properties
"product": "phone", // first property
"status": "ordered" // second property etc..
}
}
]
}
]
}Koodiesimerkit
Käyttämällä yllä olevaa yhteyttä voit tehdä tämän pyynnön /v1/import-päätepisteeseen. Alta löydät täydelliset koodiesimerkit, jotka lähettävät joitakin tapahtumia useille kontakteille.
PHP
<?php
/**
* Account specific variables.
*
* These variables are given to you by or can be requested from your contact person at Liana Technologies.
*/
$user = "USER ID"; // The user id, integer
$secret = "USER SECRET"; // An hexadecimal secret string
$url = "REST API URL"; // The base url for your API installation
$realm = "REST API REALM"; // The realm of your API installation, all caps alphanumeric string
/**
* General variables
*/
$basePath = 'rest'; // Base path of the api end points
$contentType = 'application/json'; // Content will be send as json
$method = 'POST'; // Method is always POST
/**
* Send a API request to LianaAutomation
*
* This function will add the required headers and calculates the signature for the authorization header
*
* @param string $path The path of the end point
* @param array $data The content body (data) of the request
* @return mixed
*/
function send(string $path, array $data)
{
// Import variables
global $user, $secret, $url, $realm, $basePath, $contentType, $method;
// Encode our body content data
$data = json_encode($data);
// Get the current datetime in ISO 8601
$date = date('c');
// md5 hash our body content
$contentMd5 = md5($data);
// Create our signature
$signatureContent = implode(
"\n",
[
$method,
$contentMd5,
$contentType,
$date,
$data,
"/{$basePath}/{$path}"
],
);
$signature = hash_hmac('sha256', $signatureContent, $secret);
// Create the authorization header value
$auth = "{$realm} {$user}:" . $signature;
// Create our full stream context with all required headers
$ctx = stream_context_create([
'http' => [
'method' => $method,
'header' => implode(
"\r\n",
[
"Authorization: {$auth}",
"Date: {$date}",
"Content-md5: {$contentMd5}",
"Content-Type: {$contentType}"
]
),
'content' => $data
]
]);
// Build full path, open a data stream, and decode the json response
$fullPath = "{$url}/{$basePath}/{$path}";
$fp = fopen($fullPath, 'rb', false, $ctx);
$response = stream_get_contents($fp);
$response = json_decode($response, true);
return $response;
}
// Import Data
$response = send(
'v1/import',
[
"channel" => "3", // The channel ID
"no_duplicates" => false, // Duplicates event timestamp will be updated
"data" => [
[ // First person
"identity" => [
"email" => "someone@domain.com", // Email
"sms" => "+358123456789", // Phone number
"extra1" => "abcdef", // external identifier 1
],
"events" => [ // events for first person
[
"verb" => "order", // order event
"items" => [
"product" => "phone", // order-product: phone
"status" => "ordered" // order-status: ordered
]
],
[
"verb" => "payment", // payment event
"items" => [
"amount" => "599,98", // payment-amount: 599,98
"currency" => "eur" // payment-currency: eur
]
]
]
],
[ // Second person
"identity" => [
"email" => "someone2@domain.com", // Email
"sms" => "+358987654321", // Phone number
"extra1" => "zyxwvu", // external identifier 1
],
"events" => [ // events for first person
[
"verb" => "order", // order event
"items" => [
"product" => "lego", // order-product: lego
"status" => "delivered" // order-status: delivered
]
],
[
"verb" => "message", // message event
"items" => [
"type" => "inbound", // message-type: inbound
"reason" => "compliment" // message-reason: compliment
]
]
]
]
]
]
);
var_dump($response);
Node (Javascript)
/**
* Dependencies
*
* We use the CryptoJS library for hashing and fetch for making the http call
*/
import md5 from 'crypto-js/md5.js';
import hmacSHA256 from 'crypto-js/hmac-sha256.js';
import fetch from 'node-fetch';
/**
* Account specific variables.
*
* These variables are given to you by or can be requested from your contact person at Liana Technologies.
*/
var user = "USER ID"; // The user id, integer
var secret = "USER SECRET"; // An hexadecimal secret string
var url = "REST API URL"; // The base url for your API installation
var realm = "REST API REALM"; // The realm of your API installation, all caps alphanumeric string
/**
* General variables
*/
var basePath = 'rest'; // Base path of the api end points
var contentType = 'application/json'; // Content will be send as json
var method = 'POST'; // Method is always POST
async function send(path, data) {
// Format object to string
data = JSON.stringify(data);
// Get the current datetime in ISO 8601
let date = new Date().toISOString();
// md5 hash our body content
let contentMd5 = md5(data).toString();
// Create our signature
let signatureContent = [
method,
contentMd5,
contentType,
date,
data,
'/' + basePath + '/' + path
].join('\n');
let signature = hmacSHA256(signatureContent, secret).toString();
// Create the authorization header value
let auth = realm + ' ' + user + ':' + signature;
// Build the full path and create our request with all required headers
let fullPath = url + '/' + basePath + '/' + path;
let response = await fetch(fullPath, {
"method": method,
"headers": {
"Authorization": auth,
"Date": date,
"Content-md5": contentMd5,
"Content-Type": contentType
},
"body": data
});
// Return the response
return response.json().then(res => {
return res;
});
}
// Import data
send(
'v1/pingpong',
{
"channel": "3", // The channel ID
"no_duplicates": false, // Duplicates event timestamp will be updated
"data": [
{ // First person
"identity": {
"email": "someone@domain.com", // Email
"sms": "+358123456789", // Phone number
"extra1": "abcdef", // external identifier 1
},
"events": [ // events for first person
{
"verb": "order", // order event
"items": {
"product": "phone", // order-product: phone
"status": "ordered" // order-status: ordered
}
},
{
"verb": "payment", // payment event
"items": {
"amount": "599,98", // payment-amount: 599,98
"currency": "eur" // payment-currency: eur
}
}
]
},
{ // Second person
"identity": {
"email": "someone2@domain.com", // Email
"sms": "+358987654321", // Phone number
"extra1": "zyxwvu", // external identifier 1
},
"events": [ // events for first person
{
"verb": "order", // order event
"items": {
"product": "lego", // order-product: lego
"status": "delivered" // order-status: delivered
}
},
{
"verb": "message", // message event
"items": {
"type": "inbound", // message-type: inbound
"reason": "compliment" // message-reason: compliment
}
}
]
}
]
}
).then((data) => {
console.log(data);
});
Kommentit
0 kommenttia
Kommentointi on poistettu käytöstä.