facebook / facebook-nodejs-business-sdk

Node.js SDK for Meta Marketing APIs
https://developers.facebook.com/docs/business-sdk
Other
489 stars 226 forks source link

Can't figure out how to create a playable ad using SDK #253

Open 15bubbles opened 1 year ago

15bubbles commented 1 year ago

Which SDK version are you using?

"facebook-nodejs-business-sdk": "^16.0.2",

What's the issue?

Can't figure out how to create playable Ad with SDK

Steps/Sample code to reproduce the issue

I've tried to create a playable Ad using the SDK. I took this document and another document from the official documentation for reference. These documents show examples with source and source_zip fields, telling that I can upload playable ad in such way. I decided to use source_zip because it seems that I can pass binary content there, however when I'm trying to use these fields from the SDK, I get an error from the API:

FacebookRequestError: (#100) Invalid file or file handle. Double check the 'file' parameter

Here's example code I'm using:

export default class FacebookAdsPublisher {
  adAccount: AdAccount;

  constructor(config: IFacebookAdsPublisherConfig) {
    FacebookAdsApi.init(config.accessToken);
    this.adAccount = new AdAccount(config.accountId);
  }

  async uploadPlayable(campaign: ICampaign, data: Buffer) {
    const asset = await this.adAccount.createAdPlayable([], {
      name: `${campaign.name}_playable.zip`,
      source_zip: data,
    });

    return asset.id;
  }
}

Observed Results:

GraphQL API returns an error

FacebookRequestError: (#100) Invalid file or file handle. Double check the 'file' parameter

Expected Results:

I was expecting that playable ad will get uploaded via the API.

Can we add some example to the examples directory?