Search code examples
facebookfacebook-graph-apifacebook-marketing-api

Return value of ads insights in graph api


I currently don't have any campaigns that have been launched with ACTIVE status in Facebook so whenever I try to query the insights endpoint I receive an empty array of data[] which doesn't allow me to do much.

I would like to know how a response would look for an adset that has been launched with an active status and actually contains insights' data, using a query like this one:

GET graph.facebook.com/v8.0/{adset_id}/insights?date_preset=lifetime&fields=reach,unique_ctr,cpm&access_token={access_token}

I think is that it might look something like this, but I would like to get the exact response structure:

{
    "data": [
        {
            "name": "metric_name",
            "values": [
                {
                    "end_time": "some_date_string",
                    "value": numeric_string,
                }
            ]
        }
   ]
}

Solution

  • I've made <adset_id>/insights?date_preset=lifetime&fields=reach,unique_ctr,cpm

    Example output:

    {
      "data": [
        {
          "reach": "12739",
          "unique_ctr": "1.420834",
          "cpm": "13.740269",
          "date_start": "2020-02-25",
          "date_stop": "2021-01-28"
        }
      ],
      "paging": {
        "cursors": {
          "before": "MAZDZD",
          "after": "MAZDZD"
        }
      }
    }