Making requests

This page contains general information that you might need, when making requests to Supermetrics API.

Authentication

All endpoints that require authentication, accept either an api_key parameter, or an Authorization header. Read more from authentication.

Authorization: Bearer <your api key>

GET method

When endpoint supports the GET method, you can choose to either use the traditional GET query parameters, as defined in RFC 1738, or a JSON string representing the query parameters, sent as the json parameter.

The documentation shows examples mostly with the latter approach.

Example
GET /enterprise/v2/query/data/json?json={
  "api_key": "<api key>",
  "ds_id": "GA",
  "ds_accounts": "567890",
  "start_date": "2020-01-01",
  "end_date": "today",
  "fields": "date, impressions",
  "settings": {"no_headers": true},
  "filter": "impressions > 0 AND impressions < 100",
  "order_rows": "impressions desc,date desc",
  "max_rows": 1000
} HTTP/1.1
Host: api.supermetrics.com
Accept: */*
Accept-Encoding: gzip,deflate)

@fancy_anchor({"id": "post-method"})
#### POST method

When endpoint supports the _POST_ method, you either choose to send the request body 
as POST fields with content type _application/x-www-form-urlencoded_, or as a JSON 
string with content type _application/json_.

###### Example

@fancy_endpoint_example(
POST /enterprise/v2/query/data/json HTTP/1.1
Content-Type: application/json; charset=utf-8
Host: api.supermetrics.com
Accept: */*
Accept-Encoding: gzip,deflate
Authorization: Bearer <your api key>

{
  "ds_id": "GA",
  "ds_accounts": "567890",
  "start_date": "2020-01-01",
  "end_date": "today",
  "fields": "date, impressions",
  "settings": {"no_headers": true},
  "filter": "impressions > 0 AND impressions < 100",
  "order_rows": "impressions desc,date desc",
  "max_rows": 1000
}

Pretty JSON

URL query parameter pretty can be used to pretty-print JSON responses in human-readable format. Please note that this also increases the response size, and it should not be used for automated requests.

GET /enterprise/v2/query/data/json?json={...}&pretty=true

CORS support

Currently, we discourage making authenticated requests to Supermetrics API from browser applications, as they are likely to expose credentials to end users. Therefore, we do not accept cross-origin HTTP requests by default. Please contact us if this behaviour is vital to your integration.

Postman examples

The following Postman collection contains request examples for Supermetrics API endpoints. You can either download the file and import it into Postman, or have Postman import it from the URL the link below points to. See Postman's documentation on how to import collections.

Please remember to enter your API key into your Postman variables, and to add suitable parameter values to the requests, before running them.

Last updated 2022-10-19 UTC.