0

I am trying to use the facebook node business sdk and I am having some issues. I am using an api key from the ad sandbox account.

I am trying to call createAdImage but I get hit with an error that says "The provided image file is invalid". However, it works with the exact same parameters when I just hit the graph API with curl.

Here is my function code

const createAdImage = async (url) => {
  console.log("here");
  account
    .createAdImage([AdImage.Fields.Hash], {
      [AdImage.Fields.filename]: url,
    })
    .then((result) => {
      console.log(result);
      return result.hash;
    })
    .catch((error) => {
      console.log(error);
    });
};

createAdImage("/home/philowe2001/fb-test/AdsSample/philoicon.jpg");

Here is some of the relevant console output

message: 'The provided image file is invalid: The provided image file is invalid. Please check your image path again.',
  status: 400,
  response: {
    error: {
      message: 'Invalid parameter',
      type: 'OAuthException',
      code: 100,
      error_subcode: 2490361,
      is_transient: false,
      error_user_title: 'The provided image file is invalid',
      error_user_msg: 'The provided image file is invalid. Please check your image path again.',
      fbtrace_id: 'AcOHTk6MviAmBmqB5J242i7'
    }
  },

Also just in case this is useful, here is my curl code that works

curl \
  -F 'filename=@/home/philowe2001/fb-test/AdsSample/philoicon.jpg' \
  -F 'access_token=EAAJT1aMW9V0BAGTlre3ZBkkQju5HrQo1zi1CDG9r6sok74PGk7yFynPffGqbGPUZBCNBlYe6EiFNFrc8hoghi4bidCqIVAhx3SNmQEY9JTHc3cb7scgwaok98TXMiJll8o7ZAlWrK1LNBbz0KWpaZByNQmJa2DaAIZAJvXX2Q3aeWo30lbEwdIZCX8KqaEy6EZD' \
  https://graph.facebook.com/v15.0/act_1431237097286304/adimages

Thank you.

philowe
  • 11
  • 1
  • I doubt that `[AdImage.Fields.filename]: url` performs an actual file upload, the way the cURL statement does. The only example usage of that `createAdImage` method in the SDK is https://github.com/facebook/facebook-nodejs-business-sdk/blob/3e62192b3e385eeece9ac7a6b0bb8b3c490de45c/examples/BasicExample.js#L143, and there they are passing the actual byte content of the image. – CBroe Jan 27 '23 at 07:27

1 Answers1

0

Thanks to CBroe for this

They were correct, you cannot use a url with the node sdk. You must instead pass the bytes.

Here is a correct call that works:

.createAdImage([], {
      bytes: imageBytes,
    })
philowe
  • 11
  • 1