Im not getting more than 25 ads from my ad account with this request. I work at a company and this is how the previous guy have built it, so I would appreciate a solution for this way of calling the api. Everything works, its just that im not getting more than 25 records.
I have read that you could add a "limit" parameter to the URI/request followed by a number (shown here, at part 9: https://mixedanalytics.com/knowledge-base/import-facebook-ad-data-to-google-sheets/#num9)
In my case, I have tried adding a "limit" variable in the interface, in the fields array, I have tried sneaking in "limit" in the account.getAds() call. Pretty much everything that seems logical in the presented code below:
import logger from "../****/****";
import { FB_ACCESS_TOKEN } from "../****/****";
import { AdAccount, FacebookAdsApi } from "facebook-nodejs-business-sdk";
let isInitialized = false;
function initFacebookApi(): void {
if (!isInitialized) {
FacebookAdsApi.init(FB_ACCESS_TOKEN);
isInitialized = true;
}
}
interface FacebookAdParam {
filtering?: {
field: string;
operator: string;
value: string;
}[];
}
export async function searchFBAds(facebookAccountId: string, search: string | undefined) {
try {
initFacebookApi();
const fullAccountId = `act_${facebookAccountId}`;
const account = new AdAccount(fullAccountId);
const params: FacebookAdParam = {};
const fields = ['id', 'name'];
if (search) { //Our GUI features a search function, to filter by name, after fetching all records
params.filtering = [
{
field: 'name',
operator: 'CONTAIN',
value: search,
},
];
}
const ads: any[] = await account.getAds(fields, params);
return ads.map(({ id, name }) => {
return {
id: id,
name: name
};
});
}
catch (e) {
logger.error('Something went wrong when searching for a facebook ad', e);
}
}
Thanks in advance //Ibrahim, junior dev.