Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Omitting 'fields' Query Parameter in FacebookAdsApiBatch via APIRequest with facebook-nodejs-business-sdk #289

Open
gharesagar opened this issue Jun 8, 2024 · 0 comments

Comments

@gharesagar
Copy link

gharesagar commented Jun 8, 2024

I am currently using facebook-nodejs-business-sdk:"^18.0.0" graph api for Insights.

I have below piece of code in map which returns array of Api requests. Using the the instance of FacebookAdsApiBatch i am putting each request into it which should return multiple results as it batch

return new APIRequest( http://graph.facebook.com/v18.0/${levelId}`
'GET',
'insights'
)
.addParam('access_token', XX_X_X)
.addParam('fields', 'impression, clicks')
.addParam('level', levelType)`

Above Array of APIRequest passed in below fucntion

`async getBatchRequestResult(requests: APIRequest[]): Promise {
const batchApi = new FacebookAdsApiBatch(
getFbApiInstance(),
(res) =>{
console.log('batch instance success ', res)
},
(error) => {
console.log('batch instance error', error)
}
)

reqests.forEach((request) => {
batchApi.addRequest(
request,
(data) => {
console.log(' Success addRequest: ${JSON.stringify(data)}')
},
(error) => {
console.log('error', error)
}
)
})

return new Promise((resolve, reject) => {
batchApi
.execute()
.then((responses) => {
console.log('RESPONSES*', responses);
resolve(responses)
})
.catch((error) => {
console.log('ERROR*', error);
reject(error)
})

})
}`

Current in lambda logs I am seeing 3 types of logs in order.

  1. batch instance success: { kind of same json as below }

  2. Muliple "Success addRequest" logs. One of mentioned below Success addRequest:

{ "_body": { "https://graph.facebook.com/v18.0/<CAMPAIGN_ID>/insights" } "status": 200, "_headers": [ long list of objects ], "_call": { "method": "GET", "relative_url": "https://graph.facebook.com/v18.0/<CAMPAIGN_ID>/insights? access_token=XX_X_X &**fields**=&level=campaign" "attachedFiles": "" } ....... ....... } }

RESPONSES = Null

Question is, If we pay attention on relative_url the fields value is empty despite the fact I am passing string 'impression, clicks'. I tried with array ["impression", "clicks"] and addParams({ key:Val }) but it still not passing that value. Really not sure why it is ommitting. All other parameters are fine. I doubt that this is the why I am facing issue of Null as final result. fields is important for me because I have to fetch tons of other measures as well.

Can someone please help me to figure out what is the issue? If anyone need further detail I am ready to give as much I can. Thank you in advance.

Currently in codebase we have "new Campaign" instance which has getInsights(null, query) fun which working fine. I am replacing this and trying batch call to avoid timeout error from FB for all kind of insights (campaign, adsets, ad) and therir breakdowns and mesures. By achiveing above batch call, the number of API calling to FB would be significantly reduced.

Reference: https://www.npmjs.com/package/facebook-nodejs-business-sdk?activeTab=code
^Go under BatchExample.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant