未知grant_type状态代码401 TrustPilot电子邮件邀请身份验证



我正在尝试使用TrustPilot API发送评论电子邮件邀请。无论我做什么,结果都是未知的grant_type。文档说grant_type应该设置为";密码";为了获得令牌,以便我可以使用适当的选项发送邀请。

export const inviteBuyer = async (email, orderNumber) => {
const base64 = new Base64();
const secrets = base64.encode('APIKEY:APISECRET');
const authOptions = {
data: 'grant_type=password&username=myemail&password=mypassword',
headers: {
Authorization: 'Basic ' + secrets,
'Content-Type': 'application/x-www-form-urlencoded',
},
};
const authUrl = 'https://api.trustpilot.com/v1/oauth/oauth-business-users-for-applications/accesstoken';
try {
const getIdentity = await HTTP.call('POST', authUrl, authOptions);
} catch (err) {
console.log(err);
}
const options = {
headers: {
token: getIdentity.access_token,
},
parameters: {
consumerEmail: email,
consumerName: 'John Doe',
referenceNumber: orderNumber,
locale: 'en',
senderEmail: 'OurEMail', // potentiellmeent
serviceReviewInvitation: {
// preferredSendTime: '2013-09-07T13:37:00',
// redirectUri: 'http://trustpilot.com',
tags: ['buyer'],
// templateId: '507f191e810c19729de860ea',
},
},
};
try {
const resp = await HTTP.call(
'POST',
'https://invitations-api.trustpilot.com/v1/private/business-units/OurBusinessUnitId/email-invitations',
options
);
console.dir(resp);
} catch (err) {}
console.log(err);
};

最初的问题使用payload键来指定正文,后来在data上使用。

但是,要使用Meteor HTTP客户端发送原始HTTP请求体,必须使用content

const authOptions = {
content: 'grant_type=password&username=myemail&password=mypassword',
headers: {
Authorization: 'Basic ' + secrets,
'Content-Type': 'application/x-www-form-urlencoded',
},
};

相关内容

最新更新