Start with Shoppi API

https://www.shoppiapp.com/api/[CLASS]/[METHOD]/[OUTPUT]

[CLASS] The class of methods such as login
[METHOD] The method such as auth
[OUTPUT] The type of data format (json, jsonp, text) default is xmlrpc

Analyzing the return data structure

Array representation Variables
Array( “result”=>[RESULT], “feedback”=>[FEEDBACK], “redirect”=>[REDIRECT] );
[RESULT] Ok, ko, warning, error
[FEEDBACK] String or array
[REDIRECT] Abs or rel URL

PHP API FUNCTION

function api($class,$method,$args='',$lkey='',$uid=''){ $server = 'https://www.shoppiapp.com/api/'.$class.'/'.$method.'/json'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$server); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($curl,CURLOPT_HTTPHEADER,array('lkey:$lkey','uid:$uid')); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($args)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $server_output = curl_exec($ch); curl_close ($ch); return $server_output; }

Messenger bot

PHP EXAMPLE

<?php
 
$access_token 
"<<TOKEN HERE>>";
$verify_token "fb_savelgo_bot";
$hub_verify_token null;
if(isset(
$_REQUEST['hub_challenge'])) {
    
$challenge $_REQUEST['hub_challenge'];
    
$hub_verify_token $_REQUEST['hub_verify_token'];
}
if (
$hub_verify_token === $verify_token) {
    echo 
$challenge;
}
$input json_decode(file_get_contents('php://input'), true);
$sender $input['entry'][0]['messaging'][0]['sender']['id'];
$message $input['entry'][0]['messaging'][0]['message']['text'];
$message_to_reply '';


 
$message_to_reply 'Huh! nothing founded! Try again';

/**
 * Some Basic rules to validate incoming messages
 */
    
$message preg_replace('[search|find]',"",$message);

$words explode(" ",$message);

foreach(
$words as $word){
    if(
strlen($word) < 4){ continue; }
    
    
//CALL api for products/services with term
    //RETURN $ITEMS
}

foreach(
$items as $element){

    
    
$data = array(
        
'title' => cut_string($element['title'],20),
        
'image_url' => $element['photo'],
        
'subtitle' => cut_string(strip_tags($element['content']),20),
        
'buttons' => array(
            array(
                
'type' => 'web_url',
                
'url' => "http://www.savelgo.com".$element['link'],
                
'title' => 'View Story',
            ),
        ),
    );
    
$elements[] = $data;



    
$elements json_encode($elements);


    
$jsonData '{
      "recipient":{
         "id":"'
.$sender.'"
      },
      "message":{
        "attachment":{
          "type":"template",
          "payload":{
            "template_type":"generic",
            elements: '
.$elements.'
          }
        }
      }
    }'
;

        
}

//API Url
$url 'https://graph.facebook.com/v2.6/me/messages?access_token='.$access_token;
//Initiate cURL.
$ch curl_init($url);
//The JSON data.
if(!$jsonData){
    
$jsonData '{
        "recipient":{
            "id":"'
.$sender.'"
        },
        "message":{
            "text":"'
.$message_to_reply.'"
        }
    }'
;
}
//Encode the array into JSON.
$jsonDataEncoded $jsonData;
//Tell cURL that we want to send a POST request.
curl_setopt($chCURLOPT_POST1);
//Attach our encoded JSON string to the POST fields.
curl_setopt($chCURLOPT_POSTFIELDS$jsonDataEncoded);
//Set the content type to application/json
curl_setopt($chCURLOPT_HTTPHEADER, array('Content-Type: application/json'));
//curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));
//Execute the request
if(!empty($input['entry'][0]['messaging'][0]['message'])){
    
$result curl_exec($ch);
}
?>

Page

https://www.shoppiapp.com/api/view_page/info/json

Parameter Description
pageId Integer
Return Description
category array
title string
photo string
content string
loc lat,long

News

https://www.shoppiapp.com/api/content/news/json

Parameter Description
id Integer
Return Description
category array
title string
photo string
content string
loc lat,long

Photo

https://www.shoppiapp.com/api/content/photo/json

Parameter Description
id Integer
Return Description
category array
title string
content string
loc lat,long

Video

https://www.shoppiapp.com/api/content/video/json

Parameter Description
id Integer
Return Description
category array
title string
photo string
yt_vid string
loc lat,long

Section

https://www.shoppiapp.com/api/content/section/json

Parameter Description
id Integer
Return Description
category array
title string
photo string
loc lat,long

Product (Goods)

https://www.shoppiapp.com/api/content/product/json

Parameter Description
id Integer
Return Description
category array
title string
photo string
loc lat,long

Service (Service)

https://www.shoppiapp.com/api/content/service/json

Parameter Description
id Integer
Return Description
category array
title string
photo string
loc lat,long

File (Digital Content)

https://www.shoppiapp.com/api/content/file/json

Parameter Description
id Integer
Return Description
category array
title string
photo string
loc lat,long

Place an order

https://www.shoppiapp.com/api/cart/buy/json

Parameter Description
id integer
type string (product, service, file)
email string
Return Description
id integer
message string
result string (ok/ko)

Place an order

https://www.shoppiapp.com/api/show/list/json

Parameter Description
pageId integer
status string (pending,paid,delay,chargeback)
Return Description
id integer
title string
status string
currency string
total float
ship_cost float
country string
city string
result string (ok/ko)