trustpilot / node-trustpilot

HTTP client for Trustpilot
MIT License
31 stars 4 forks source link

415 on get invitation-link #74

Open benoit03 opened 3 years ago

benoit03 commented 3 years ago

Hello, i receive a 415 when i try to generate an invitation-link with your module.

i have an access token, my businessID, everything work fine to get all review : await client("/v1/private/business-units/${process.env.TRUSTPILOT_BUSINESS_ID}/reviews")

but when i try to generate an invitation-link, i have a 415, it's a problem of media type. Maybe the content type : apllication/json is not set. But i don't know how to set it with your module.

This is my request :

await client.post("/v1/private/business-units/${process.env.TRUSTPILOT_BUSINESS_ID}/invitation-links", { name: user.name, locale: "fr-FR", redirectUri: "https://stootie.com", email: user.email, });

everything work fine on POSTMAN.

addict67 commented 3 years ago

It's a bit of a late answer but if it can help other people, it's fine I guess.

node-trustpilot uses Request (which is deprecated btw) so if you want to use queryStrings or change the Content-Type header, you can use the qs and headers properties, like this:

await client.post(
    '/v1/private/business-units/${process.env.TRUSTPILOT_BUSINESS_ID}/invitation-links',
    {
        qs: {
            name: user.name,
            locale: 'fr-FR',
            redirectUri: 'https://stootie.com',
            email: user.email
        },
        headers: {
            'Content-Type': 'application/json'
        }
    }
);

More informations on those options in Request's core repository

AmericasEngineer commented 2 years ago

It's a bit of a late answer but if it can help other people, it's fine I guess.

node-trustpilot uses Request (which is deprecated btw) so if you want to use queryStrings or change the Content-Type header, you can use the qs and headers properties, like this:

await client.post(
    '/v1/private/business-units/${process.env.TRUSTPILOT_BUSINESS_ID}/invitation-links',
    {
        qs: {
            name: user.name,
            locale: 'fr-FR',
            redirectUri: 'https://stootie.com',
            email: user.email
        },
        headers: {
            'Content-Type': 'application/json'
        }
    }
);

More informations on those options in Request's core repository

Somehow qs: gave an empty body error.(A non-empty request body is required.) Instead, I used body:

await client.post(
  `/v1/private/business-units/${process.env.BUSINESS_UNIT_ID}/invitation-links`,
  {
    body: {
      name: user.name,
      locale: "en-US",
      redirectUri: `${process.env.REDIRECT_URI}`,
      email: user.email,
    },
    headers: {
      "Content-Type": "application/json",
    },
  }
);