Multi-Report Queries

In some cases, you may want to request a metric across more than one Report ID. This is known as "Meta-Analysis" and requires an additional step to retrieve the results of the query.

Sending a Query

In this example, we're querying for Impressions across two sample Reports: abc123 and xyz987.

All the parameters should be constructed as a JSON object. Here, we specify the reportIds and the metrics fields:

{
  "reportIds": [
    "abc123",
    "xyz987"
  ],
  "metrics": [
    { "name": "impressions" }
  ]
}

Then, we construct the query, authenticating with Base64-encoded username:password string. We use POST to send this query to the /data endpoint.

curl -X POST "https://mapi.placed.com/data" \
-H "Authorization: Basic <your_base64_encoded_credentials>" \
-H "Content-Type: application/json" \
-d '{
    "reportIds": [
        "abc123",
        "xyz9877"  
    ],
    "metrics": [
        { "name": "impressions" }
    ]
}'

$url = "https://mapi.placed.com/data";
$ch = curl_init($url);
$cred = base64_encode("<your username>:<your password>");
$headers = array(
    "Authorization: Basic " . $cred,
    "Content-Type: application/json"
);
$payload = '{
    "reportIds": [
        "abc123",
        "xyz9877" 
    ],
    "metrics": [
        { "name": "impressions" }
    ]
}';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
$output = curl_exec($ch);
var_dump(json_decode($output));
curl_close($ch);


Initial Response

Since we've included multiple Report IDs, there will be a short delay while we process the results. The initial response will give us a Request ID, a Result URL, and a State of the query.

{
  "status": {
    "requestId": "123456-7890-9876-5432101234",
    "resultUrl": "mapi.placed.com/data/123456-7890-9876-5432101234",
    "state": "PENDING"
  }
}

Retrieving Results

To retrieve the results of your initial query, simply send a request using POST or GET to the Result URL provided in the initial response. The body of the request should be empty, aside from any options you want to pass. If the results have been processed, you will get a response which includes the data broken our by Report ID.

Note: You can add ".csv" to the end of Result URL to retrieve comma-separated data.

Example

$url = "https://mapi.placed.com/data/123456-7890-9876-5432101234"; //grab by querying /data endpoint as seen above
$ch = curl_init($url);
$cred = base64_encode("<your username>:<your password>");
$headers = array("Authorization: Basic " . $cred,
"Content-Type:application/json"
);
$payload = ''; 
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
$output = curl_exec($ch);
var_dump(json_decode($output));
curl_close($ch);
curl -X POST "https://mapi.placed.com/data/123456-7890-9876-5432101234" \
-H "Authorization: Basic <your_base64_encoded_credentials>" \
-H "Content-Type: application/json" \
-d ''