Is It Possible To Only Get Active Campaigns?


We’re using the Ads Analytics API. We’re pulling #s at the campaign level.

Our client has over 2K campaigns, so we’re getting all of them back when we use this endpoint

Right now we’re going to have to cycle through all 2K and use end_time to decide if we need to query for stats for this campaign. Then query for stats on all those that have not ended.

Is there a more intelligent way that I missed? Perhaps something in the /stats/ endpoints?


@gsmoore: The end_time attribute can be useful (note that it’s possible for its value to be null). The campaign entities also include a servable attribute, which may be helpful:

$ twurl -H "/1/accounts/18ce54d4x5t/campaigns?sort_by=created_at-desc&count=1" | jq
  "request": {
    "params": {
      "count": 1,
      "account_id": "18ce54d4x5t",
      "sort_by": [
  "data": [
      "name": "campaign",
      "start_time": "2016-03-01T00:00:01Z",
      "reasons_not_servable": [
      "servable": false,
      "daily_budget_amount_local_micro": 500000,
      "end_time": null,
      "funding_instrument_id": "lygyi",
      "duration_in_days": null,
      "standard_delivery": true,
      "total_budget_amount_local_micro": 1000000,
      "id": "7qcdp",
      "entity_status": "PAUSED",
      "paused": true,
      "account_id": "18ce54d4x5t",
      "frequency_cap": null,
      "currency": "USD",
      "created_at": "2017-03-09T23:01:20Z",
      "updated_at": "2017-03-09T23:01:20Z",
      "deleted": false
  "data_type": "campaign",
  "total_count": 53,
  "next_cursor": "yocerqhl5ja53tin6za4g"

However, keep in mind that the decision to pull stats also depends on the last time stats were pulled for the entities you’re considering.

Let’s say a campaign was created on 2017-01-23 at 00:00:01 UTC and has an end date of 2017-01-24 at 00:00:01 UTC. If you have a job to pull stats every day at 12:00:00 UTC and use end_time as the criterion to determine whether you should pull stats for a specific entity, then on 2017-01-24 at 12:00:00 UTC, the specific campaign will have ended. If you decide not to pull stats, then you’ll miss the data between 2017-01-23 at 12:00:01 UTC (the time after the last pull) and 2017-01-24 at 00:00:01 UTC (the campaign’s end time).

Hope this helps!


Sounds like you’re saying that we’re going about this in the most logical way possible. That’s good.

Makes sense. We’ll build in some buffer to grab campaigns that haven’t ended yet and those that ended, say, in the past 48 hours or so.