node-trustpilot icon indicating copy to clipboard operation
node-trustpilot copied to clipboard

415 on get invitation-link

Open benoit03 opened this issue 5 years ago • 2 comments

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.

benoit03 avatar Oct 13 '20 12:10 benoit03

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

addict67 avatar Jul 02 '21 13:07 addict67

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",
    },
  }
);

AmericasEngineer avatar Feb 02 '22 15:02 AmericasEngineer