facebook-nodejs-business-sdk icon indicating copy to clipboard operation
facebook-nodejs-business-sdk copied to clipboard

Creation of adSet overwrite adAccount

Open arkszafran opened this issue 2 years ago • 5 comments

Which SDK version are you using?

13.0.0

What's the issue?

When i try to create adSet using adAccount.createAdSet(fields, params) adAccount properties are overwritten by created adSet.

Steps/Sample code to reproduce the issue

adAccount.createAdSet(fields, params)

Observed Results:

Id property of adAccount is new adSet id, when i try to call adAccount.createAdImage api return error because of wrong account_id.

Expected Results:

Cause of this behaviour is related to last change of line 491 file src/objects/ad-account.js, there should be AdSet instead of null.

arkszafran avatar Apr 26 '22 18:04 arkszafran

Similar issue with adAccount.createAdImage() the POST request that is sent, does contain the acountId, but without "act_" as prefix.

error message that is returned in this case: message: "Unsupported post request. Object with ID '23850867044130230' does not exist, cannot be loaded due to missing permissions, or does not support this operation. Please read the Graph API documentation at https://developers.facebook.com/docs/graph-api",

request is sent to:

 method: 'POST',
  url: 'https://graph.facebook.com/v13.0/23850867044130230/adimages?access_token=...',
  data: {
    bytes: '

the request url is missing the "act_"

It's not always happening, threfore I also think it has to be related with this ticket.

simllll avatar May 11 '22 10:05 simllll

Workaround is recreation of AdAccount directly before createAdImage call.

arkszafran avatar May 11 '22 10:05 arkszafran

I will try to just create a new adAcount after createAdSet(). The related line is according to you: https://github.com/facebook/facebook-nodejs-business-sdk/blob/9de67beb49a26b58f56c1cc37ad3f76bf821a6ee/src/objects/ad-account.js#L491 I don't understand the change actually, but it's this one: image

this causes that image is called.

Because of the null, I guess it's modifying the actualy adAccount instance, instead of the previous AdSet instance.

simllll avatar May 11 '22 12:05 simllll

By the way, this pattern occurs 4 times, could be a bug in all cases?

  • createAdSet
  • createManagedPartnerAd
  • createCreateAndApplyPublisherBlockList
  • createAdsPixel

simllll avatar May 11 '22 12:05 simllll

It seems like the reason is that in the "createAdSet" (also "createAdsPixel") method in the AdAccount class "null" is passed for the targetClassConstructor argument, which leads to a reset of the AbstractObject fields.

Just fix the "createAdSet" method in cjs.js in line 27255 by replacing "this.createEdge('/adsets', fields, params, null, pathOverride);" with "this.createEdge('/adsets', fields, params, AdSet, pathOverride);". It worked for me.

leon1232123 avatar Jun 12 '22 11:06 leon1232123