API Call Tutorial

There are 4 ingredients to a successful POOL API call.

Below are some coding examples with different languages in how to implement a POOL API call. The userid and token are not valid, so be sure to use your own API credentials when you attempt.

  1. PHP API call example using Curl.
    <?php
        $userid = 3947023;
        $token = "92acv86j8zs9ah57nv829cw4g2m294s8";

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, "https://api.promoonly.com/test");
        curl_setopt($ch, CURLOPT_HTTPHEADER, array("Authorization: Bearer ".base64_encode($userid.":".$token)));
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

        $result_json = curl_exec($ch);
        curl_close($ch);

        header("Content-type:application/json");
        echo $result_json;
    ?>
  2. Python API call example
    #!/usr/bin/env python

    import requests
    import base64
    import urllib

    userid = 3947023
    token = "92acv86j8zs9ah57nv829cw4g2m294s8"

    b64_key = base64.b64encode("%s:%s" % (userid, token))
    headers = {"Authorization": "Bearer %s" % b64_key}
    result_return = requests.get(user_url, headers=headers)

    print(result_return.text)
  3. Javascript API call example using jQuery
    function b64EncodeUnicode(str)
    {
        return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g,
            function toSolidBytes(match, p1)
            {
                return String.fromCharCode('0x' + p1);
            }));
    }

    var userid = 3947023;
    var token = "92acv86j8zs9ah57nv829cw4g2m294s8";
    var auth_str = 'Bearer ' + b64EncodeUnicode(userid + ":" + token);

    $.ajax({
        type: "GET",
        url: "https://api.promoonly.com/test",
        headers: { "Authorization": auth_str },
        dataType: "json",
        success: function (data)
        {
            console.log(data);
        }
    });

Outputs:

    {
        "connection": "Successful API connection!",
        "userid": 3947023,
        "access_token": 92acv86j8zs9ah57nv829cw4g2m294s8
    }