Posting Image to Pinterest API

2.8k Views Asked by At

I am trying to post a image to Pinterest using their SDK (PDK). The specific method I am using is

PDK.request('/pins/', 'POST', { board: board.id, note: "description", link: "link", image_base64: "" }, function(e){ console.log(e); });

There are three options to send the image.

  1. sending the image_url in the options object.
  2. sending the image_base64 (data url) which is what is shown in my code
  3. using a multipart form data

Pinterest docs

I can only use options 2 and 3. For options 2 it works for small images until the dataURL gets too big. Pinterest API does not have any helpful errors when this occurs and this is only my speculation.

The alternative is to use a multipart form data but I am not sure how to do that.

Can someone help me posting using the multipart form data for image posting?

1

There are 1 best solutions below

1
Tom On

I also couldn't make their SDK work, but I've sorted this out, at least for dataurl:

var sendForm = new FormData();
sendForm.append('board', pathname);
sendForm.append('note', label);
sendForm.append('link', linkURL);
sendForm.append('image_base64', dataUrl);

var url = "https://api.pinterest.com/v1/pins/?access_token=" + window.pinterestAccessToken;

$.ajax({
   url: url,
   data: sendForm,
   processData: false, //this is very important for making sure the formdata object is sent in the correct format
   contentType: false,
   type: 'POST'
});

Hope it helps.