Getting Started

Not sure how to use an API? Our tutorial and sample code will guide you through the process.

What is an API, and how does it work?

API stands for Application Program Interface-- a set of methods and tools for building software applications. In this case, we provide companies tools for buying books online.

You'll need a site capable of using back-end code, such as PHP. We'll provide a way to retrieve metadata, your Amazon Pepr price for items, and remote inventory controls. You will invoke commands using formatted URLs (which we'll show you how to make), and receive data in return from Amazon Pepr.

If this is your first time using an API, we'll guide you through the basics with our tutorial. Our API Glossary will cover each of the functions we offer in detail.

Too Technical?

Not to worry! If this is too advanced and you don't have your own programmer to implement the system, you can contact Berding Consulting and we'll gladly give you an installation quote.

Beginning Tutorial

We're going to show you how to manage your buyback functions in PHP. If you use another language, don't worry-- these concepts translate easily.

The first thing we're going to do is fetch an item's metedata. If we look at the glossary at Get Metadata, we'll see we need our company API username and API key, how we want our results formatted, the method name ('get_metadata'), and the item's ISBN.

Your company will have received a username and an API key upon signing up, so we'll assume you already have those (not sure where to look? Try your Company Controls page!). Our method name is supplied, so now we need to decide whether to get our results back in json or xml format. Either is fine, but let's assume we picked json.

Here is what our URL looks like:[sampleUsername]&api_key=[sampleApiKey]&method=get_metadata&isbn=9781429234146&results=json

Assuming your credentials are right, if you visited this URL, you'd get a json object containing our success (true or false), our success or error message, and a metedata array.

Of course, you won't be expected to manually save your metadata. Let's automate that, shall we?


    $url = '[sampleUsername]&api_key=[sampleApiKey]&method=get_metadata&isbn=9781429234146&results=json';
    $results = json_decode(file_get_contents($url));
        $metadata = $results['metadata'];

And done! We have our metadata.

That's really all there is to it. You can find information about each of the functions in our glossary, including how its results are formatted in xml or json. If you need help after covering all our material, check out our FAQ. Still having trouble? Tell us about it and we'll do our best to solve your problem.

Developing with an API

Once you've got the basics down, here's a few sample functions to make developing a little easier.

This function will build your API queries for you:

function getApiData($methodName, $params = array()){
    // function buildBaseQuery formats the elements of api call that doesn't change 
    $query = buildBaseQuery($methodName);

    foreach($params as $key => $data){
        $query .= '&'.$key.'='.rawurlencode($data);
    return json_decode(file_get_contents($query), true);

function buildBaseQuery($methodName){
    $url = '';
    $apiUsername = 'insert_api_username_here';   // insert api username here
    $apiKey = 'insert_api_key_here'; // insert api key here
//    $results = 'xml'; // Commented out to demonstrate the XML option
    $results = 'json';
    $method = 'method='.$methodName;
    $baseQuery = $url.'api_username='.$companyUsername.'&api_key='.$apiKey.'&results='.$results.'&'.$method;
    return $baseQuery;

Fill out the API username, API key, and your preferred results format in the buildBaseQuery() function, then put these functions somewhere accessible. Your API calls now look something like this:

$results = getApiData('get_metadata', array('isbn' => $isbn));
    // Success message here
    echo 'Success! '.$results['message'];
    $metadata = $results['metadata'];
} else {
    // Failure message here
    echo 'Failure: '.$results['message'];