Hi everyone,
I'm running into an issue with the Meta Ads API where the time_range and date_preset parameters don't seem to affect the data returned in my /ads endpoint GET request. Despite providing valid values for these parameters, the results don't match the expected date range. Here's what I've done and observed:
My Setup I’m using the following API request setup with TypeScript and Axios:
typescript
Copy code
let baseUrl = https://graph.facebook.com/v19.0/${accountId}/ads
;
let params: {
fields: any;
limit: number;
access_token: string;
effective_status?: string[];
time_range?: { since: string; until: string };
date_preset?: string;
} = {
fields: metaAdsFields,
limit: 50,
time_range: {
since: dates?.since ?? defaultDates?.startDate,
until: dates?.until ?? defaultDates?.endDate,
},
access_token,
};
// Optional: effective_status filtering // params.effective_status = ['ACTIVE'];
const response = await axios.get(baseUrl, { params: params, }); I dynamically provide either a time_range or date_preset depending on user inputs. The fields include standard ad insights fields, and I’ve confirmed the access_token has the necessary permissions (ads_read).
The Problem Behavior:
When I provide a time_range (e.g., { since: "2024-11-01", until: "2024-11-07" }), the data returned doesn’t align with these dates. When I use a date_preset (e.g., "last_7d"), the data doesn’t match the expected range for the preset. Parameters Included in the Request: I’ve tried using time_range and date_preset independently and together. Neither seems to impact the data returned.
Additional Observations:
If both time_range and date_preset are included, the API might prioritize one over the other or ignore both. The access_token is valid, and other API calls (e.g., fetching active ads) work as expected. I’ve checked the account data availability to ensure that data exists for the requested time ranges. What I've Tried Ensured the since and until dates in time_range are valid and within the data availability range for the account. Tested with only date_preset or only time_range. Verified that the access_token has the required ads_read permissions. Experimented with different combinations of parameters, such as adding effective_status to narrow the results. Questions for the Community Are there any known issues with using time_range or date_preset in the /ads endpoint? Could this behavior be related to how the API prioritizes these parameters when both are included? Is there a way to debug what date range the API is actually using when it processes the request? I’d appreciate any insights or suggestions for debugging this issue further. If you’ve encountered something similar or have ideas for what might be going wrong, please let me know.
Thanks in advance for your help!
Let me know if you need more information, such as a full API response or additional request details.