API for Backend

Call with Server Signature

Call From PHP

<?php
try {
    $res = $this->api->for('backend')->url($this->microservice->module_customer->getRoute(), 'extension/module/customer/api/index/getAddresses', array('customer_id' => $order_info['customer_id']))->simplePost()->json();
    $this->data['addresses'] = $res['payload'];

} catch (\Exception $e) {
    $this->data['addresses'] = array();
}

Call with API Token

PHP


curl -X POST -d ‘username=default&key=jH6CMpny2v84zyqT1mxRKIlug…’ http://192.168.0.100:8888/practice/phspark/_backend/index.php?route=api/login curl -X POST -H ‘Authorization: Bearer 128e3dddbf16e08f640de0f4ed’ http://192.168.0.100:8888/practice/phspark/_backend/index.php?route=api/test/index

JS

<script type="text/javascript" src="jquery-v3.1.1.js"></script>
// Backend API Login

// Required Info
var apiUsername = "xxx";
var apiKey = "jH6CMpny2v84zyqT1mxRK......";

$.ajax({
    headers: {
        Accept: "application/json",
        "Content-Type": "application/json"
    },
    type: "POST",
    url: "http://127.0.0.1:8888/practice/phspark/_backend/index.php?route=api/login",
    data: "username=" + apiUsername + "&key=" + apiKey,
    dataType: "JSON",
    beforeSend: function() {},
    complete: function() {},
    success: function(response) {
        console.log(response);
    },
    error: function(xhr, ajaxOptions, thrownError) {
        console.log(xhr.responseText);
    }
});


var apiToken = '55b5ca8fd24e6b4e9260......'; // Api token will be found when call for login [look at above]

// Call for Backend API data

$.ajax({
    type: "POST",
    url: "http://127.0.0.1:8888/practice/phspark/_backend/index.php?route=api/test/index&api_token=" + apiToken,
    data: "",
    dataType: "JSON",
    beforeSend: function() {},
    complete: function() {},
    success: function(response) {
     console.log(response);
    },
    error: function(xhr, ajaxOptions, thrownError) {
        console.log(xhr.responseText);
    }
});


// Call for Extension's API data

$.ajax({
    type: "POST",
    url: "http://127.0.0.1:8888/practice/phspark/_backend/index.php?route=extension/module/customer/api/group/index&api_token=" + apiToken,
    data: "",
    dataType: "JSON",
    beforeSend: function() {},
    complete: function() {},
    success: function(response) {
     console.log(response);
    },
    error: function(xhr, ajaxOptions, thrownError) {
        console.log(xhr.responseText);
    }
});