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

etsy oauth image upload #354

Open
oguzhanbulut opened this issue Aug 12, 2020 · 2 comments
Open

etsy oauth image upload #354

oguzhanbulut opened this issue Aug 12, 2020 · 2 comments

Comments

@oguzhanbulut
Copy link

oguzhanbulut commented Aug 12, 2020

I am having a problem with this.

I have been experimenting for 3 days, but I cannot upload the image uploaded by postman with javascript.

I used such a code.
`
var authHeader = oa.authHeader(
"https://openapi.etsy.com/v2/listings/"+listingId+"/images",
req.session.oauth.access_token,
req.session.oauth.access_token_secret,
);

console.log(authHeader);

var options = {
    "method": "POST",
    "url": "https://openapi.etsy.com/v2/listings/"+listingId+"/images",
    "headers": {
        "Authorization": authHeader,
    },
    formData: {
        "image": {
            "value": fs.createReadStream(path.join(__dirname, "images/"+image_path+".jpg")),
            "options": {
                "filename": path.join(__dirname, "images/"+image_path+".jpg"),
                "contentType": null
            }
        }
    }
};
request(options, function (error, response) {
    if (error) throw new Error(error);
    console.log(response.body);
});

`

I get this error.

OAuth oauth_consumer_key="cpuao0wzd2q3l152x30nzebp",oauth_nonce="R88aVNfFRhz17yA3nQYeX4ZE1PfG1Zhb",oauth_signature_method="HMAC-SHA1",oauth_timestamp="1597230278",oauth_token="a02ee077a56d97527ade2ecd24423c",oauth_version="1.0A",oauth_ signature="iCBcTHEXb638wXabJPJ2RUQeeew%3D" oauth_problem=signature_invalid&debug_sbs=POST&https%3A%2F%2Fopenapi.etsy.com%2Fv2%2Flistings%2F839582160%2Fimages&oauth_consumer_key%3Dcpuao0wzd2q3l152x30nzebp%26oauth_nonce%3DR88aVNfFRhz17yA3nQYeX4ZE1PfG1Zhb%26oauth_signa ture_method%3DHMAC-SHA1%26oauth_timestamp%3D1597230278%26oauth_token%3Da02ee077a56d97527ade2ecd24423c%26oauth_version%3D1.0A

@ngr900
Copy link

ngr900 commented Dec 4, 2020

I have not been able to resolve this problem using node-oauth but I did manage to get the image upload working using request. It's a deprecated package but I needed something that worked, quickly. Here is the code:

function uploadListingImage(listingId, image) {
    const req = request.post({
      url: `https://openapi.etsy.com/v2/listings/${listingId}/images`,
      oauth: {
        consumer_key: etsyKeys.key,
        consumer_secret: etsyKeys.secret,
        token: etsyKeys.user_token,
        token_secret: etsyKeys.user_secret
      }
    }, (err, response, body) => {
      if (err) {
        // error
      }
      if (response.statusCode === 201) {
        // success
        console.log(body.results[0]);
      }
    });
    const form = req.form();
    form.append('image', image, {
      filename: 'cover-image.jpg',
      contentType: 'image/jpeg'
    });
  }

Where listingId is self-explanatory and image is a buffer of the image read using fs.readFile.

@SteveMcArthur
Copy link

I think the problem is that node-oauth puts the authorization parameters in the header, whilst the etsy api expects them to be in the post body. I tried to hack it to make it work but in the end did more or less the same thing as you. In my case I used oauth-1.0a to generate authorization content.

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

3 participants