Support for

FLAPI: PHP platform example

Alistair Wilson
by Alistair Wilson 10 years ago
 

Interface

You might like to use an interface to manage your API session, package your requests, and include authentication credentials.

In the example below, we use Pest, available at

https://github.com/educoder/pest

Here’s an code snippet that gets and displays FLAPI data (from the developer sandbox) in PHP

PHP
// Load the library (Pest folder must be in PHP's include path)
require_once 'Pest/PestJSON.php';
include '../data/flapi_credentials.php'; // e.g. contains: $flapi = [ ‘user’, ‘pass’ ];

// Init the library (put in your TC credentials here)
$apiClient = new PestJSON( 'https://dev.flyerlink.com/api.php' ); 
//  $apiClient->setupAuth( 'username', 'password' );
$apiClient->setupAuth($flapi[0],$flapi[1]);

// Make a simple get call (this returns tag types in JSON format)
try {
    $result = $apiClient->get('/product_categories/?format=json');
}
catch (Exception $e) {
    // Handle error. In practice there are several exception types,
    // which you can use to differentiate between different error conditions
    die( $e->getMessage() );
}

// Examine successful result
// This just outputs to the page; you'll want to present it nicely.
echo '<pre>';
print_r( $result );
echo '</pre>';
 

Jump to contents page of

Flyerlink API Guide

 
 
 

All content is (c) Nettl Systems Limited, 2024 and may not be used, copied or distributed without permission.