admin管理员组

文章数量:1399145

I have been trying to get the insights of the ads and its creatives from the endpoints. Though I get the ads and the insights but the response includes the ads that have no data in them and I want to filter out the ads without data in the requested time frame. When i try to filter depending on a variable such as the impressions, the filters are detected by the meta api (if I enter a wrong value to operator value, it gives an error to change it to allowed operators) but the returned data is not filtered. What seems to be at fault here?

    var timeRange = new
    {
        since = currentDateRange.StartDate.ToString("yyyy-MM-dd"),
        until = currentDateRange.EndDate.ToString("yyyy-MM-dd")
    };

    var newAdCreativeParameters = new
    {
        fields = $@"
    adcreatives.thumbnail_width(500).thumbnail_height(500){{id,thumbnail_url,image_url,video_id,object_type}},
    insights.level(ad).time_range({{since: '{timeRange.since}', until: '{timeRange.until}'}})
    .filtering([{{'field':'ad.impressions', 'operator':'GREATER_THAN', 'value':1}}]){{impressions,cpc,spend,purchase_roas}},
    id,name,campaign{{id,name}},adset{{id,name}},currency",
        level = "ad",
        limit = "150"
    };

    FacebookBatchParameter[] requests =
    {
        new FacebookBatchParameter($"{ApiVersion}/{adAccountId}/ads", newAdCreativeParameters),
    };

    _logger.LogInformation("Retrieving facebook creative analytics insights");


    NewCreativeAnalytics NewCreativeInsights = null;
    dynamic CreativeAnalytics = await _facebookClient.BatchTaskAsync(requests);

I have been trying to get the insights of the ads and its creatives from the endpoints. Though I get the ads and the insights but the response includes the ads that have no data in them and I want to filter out the ads without data in the requested time frame. When i try to filter depending on a variable such as the impressions, the filters are detected by the meta api (if I enter a wrong value to operator value, it gives an error to change it to allowed operators) but the returned data is not filtered. What seems to be at fault here?

    var timeRange = new
    {
        since = currentDateRange.StartDate.ToString("yyyy-MM-dd"),
        until = currentDateRange.EndDate.ToString("yyyy-MM-dd")
    };

    var newAdCreativeParameters = new
    {
        fields = $@"
    adcreatives.thumbnail_width(500).thumbnail_height(500){{id,thumbnail_url,image_url,video_id,object_type}},
    insights.level(ad).time_range({{since: '{timeRange.since}', until: '{timeRange.until}'}})
    .filtering([{{'field':'ad.impressions', 'operator':'GREATER_THAN', 'value':1}}]){{impressions,cpc,spend,purchase_roas}},
    id,name,campaign{{id,name}},adset{{id,name}},currency",
        level = "ad",
        limit = "150"
    };

    FacebookBatchParameter[] requests =
    {
        new FacebookBatchParameter($"{ApiVersion}/{adAccountId}/ads", newAdCreativeParameters),
    };

    _logger.LogInformation("Retrieving facebook creative analytics insights");


    NewCreativeAnalytics NewCreativeInsights = null;
    dynamic CreativeAnalytics = await _facebookClient.BatchTaskAsync(requests);
Share Improve this question asked Mar 25 at 7:52 fxcomandosfxcomandos 271 silver badge3 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

It sounds like your filtering logic is correctly recognized by the Meta API, but it’s not actually applying the filter to remove ads with no data. A few things you might want to check:

Verify the Filtering Logic – Make sure you're using the correct operator and value. For example, when filtering by impressions, try setting impressions > 0 to exclude ads with no data.

Check the API Response Structure – Sometimes, insights might return an empty array instead of null or 0. If that’s the case, you may need to filter the results in your code after retrieving the data.

Ensure Data Availability – If you’re requesting data for a specific timeframe, double-check that insights are actually available for that period. Some ads might not have data yet, depending on when they were run.

Use a Post-Request Filter – If the API isn’t filtering properly, consider fetching all results first and then filtering out empty or zero-value entries in your code.

If the issue persists, you might want to check the API documentation or test different filtering approaches to see if one works better. Let me know if you need more help!

本文标签: Facebook GraphQL filtering doesn39t seem to workStack Overflow