Making API Calls

API calls are handled as HTTPS requests returning JSON response objects.

Forming a Call

Along with your advertiser API key, you need to know the controller and method you want to call, along with what parameters you want to pass. A basic example is retrieving a list of all available aggregate network statistics via the getStats method in the Advertiser_Report controller (Advertiser_Report::getStats). The call to do this looks like:

https://NETWORKID.api.hasoffers.com/Apiv3/json?api_key=APIKEY&Target=Advertiser_Report&Method=getStats

Breaking the URL down:

  • Base URL: https://NETWORKID.api.hasoffers.com/Apiv3/json?
  • API Key: api_key=APIKEY
  • Controller: Target=Advertiser_Report
  • Method: Method=getStats

Replace "NETWORKID" and "APIKEY" with your values. You can test your API access with this call, as it doesn't make any changes to the data you are accessing.

Adding Parameters

Nearly all methods have parameters. Most "get" methods (including Advertiser_Report::getStats) have parameters for specifying what fields to return and what values to filter for or sort by. To give an example, if you want to return just the total sales amount and cost for offers with this network, form the call like so:

https://NETWORKID.api.hasoffers.com/Apiv3/json?api_key=APIKEY&Target=Advertiser_Report&Method=getStats&fields[]=Stat.total_sales&fields[]=Stat.cost

Refer to the method's documentation for the list of parameters and expected values. For more on using filtering, see our Filtering, Sorting & Paging article.

Parsing the Response

The HTTPS response to a call is a JSON object containing two objects: request and response. The data you passed in the request is returned to you in the request object, and the result of the call in the response object. Here's a sample response from the previous call:

{
    "request": {
        "Target": "Advertiser_Report",
        "Format": "json",
        "Service": "HasOffers",
        "Version": "2",
        "Method": "getStats",
        "api_key": "APIKEY",
        "fields": [
            "Stat.total_sales",
            "Stat.cost"
        ]
    },
    "response": {
        "status": 1,
        "httpStatus": 200,
        "data": {
            "page": 1,
            "current": 50,
            "count": 1,
            "pageCount": 1,
            "data": [
                {
                    "Stat": {
                        "total_sales": "1035.000000",
                        "cost": "5662.028000"
                    }
                }
            ],
        },
        "errors": [],
        "errorMessage": null
    }
}

The contents of any results returned are in data. Any errors are listed in errorMessage, with more detail potentially in errors.

Using Our API Call Builder

The documentation for each method includes an API call builder for you to compose and execute API calls.

Important: API calls you make in the builder are actually executed on your network, including ones that change data.

On null values: Our API call builder doesn't generate code for any form fields that are empty; empty fields are treated as fields you don't want to use. To render code for null values, use "(NULL)" without quotes as the field's value.

Continuing From Here

The Advertiser API Setup & Essentials pages cover core topics on using our API, including the common field/parameter types and how to handle filtering, sorting, and paging.

Have a Question? Please contact [email protected] for technical support.