我想从react应用程序请求“ Mailjet” API。为此,我想使用提取API。
根据文档,我可以使用curl:
curl -s \
-X POST \
--user "$MJ_APIKEY_PUBLIC:$MJ_APIKEY_PRIVATE" \
https://api.mailjet.com/v3.1/send \
-H 'Content-Type: application/json' \
-d '{
"Messages":[
{
"From": {
"Email": "toto@toto.fr","Name": "toto"
},"To": [
{
"Email": "passenger1@example.com","Name": "passenger 1"
}
],"TemplateID": 1074249,"TemplateLanguage": true,"Subject": "Hi there !","Variables": {}
}
]
}'
我尝试获取以下代码:
fetch('https://api.mailjet.com/v3.1/send',{
method : 'POST',mode : 'no-cors',headers : {
'Content-Type': 'application/json','client_id':'xxx111','client_secret':'xxx000'
},body : {
"Messages":[
{
"From": {
"Email": "toto@toto.fr","Name": "Toto"
},"To": [
{
"Email": "email@email.com"
}
],"TemplateID": 1094249,"Subject": "Hi there","Variables": {
}
}
]
}
})
.then(resp=>resp.json())
.then(data => {
console.log('data mailjet',data);
})
.catch(err => err)
我总是收到401错误“未授权”。我确定我的API密钥设置不正确,但是我真的不知道如何使用访存设置它们。 我可以从我的react-app进行此API调用,还是需要创建自己的API并通过node请求资源? 非常感谢!