sendgrid新收件人api v3 401未经授权的错误

时间:2019-11-05 19:14:14

标签: javascript axios sendgrid sendgrid-api-v3

我已经设置了一个脚本,在针对电子邮件输入的html文件中使用axios:

<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script>
    const axios = window.axios;
    const button = document.getElementById('post-btn');
    const emailInput = document.getElementById('signup-input');
    const successMessage = document.getElementById('success_message');
    const signupText = document.getElementById('sign_up_text');
    button.addEventListener('click', async _ => {

        const email = emailInput.value.toLowerCase();
        const message = `${email} has signed up to our early access list.`;
        try {
            const sendGrid = await axios.post('https://api.sendgrid.com/v3/contactdb/recipients', JSON.stringify({ email }), {
                'Authorization': 'Bearer XXXXXXXXXXXXXXXXXXXX'
            });
            emailInput.style.display = "none";
            button.style.display = "none";
            signupText.style.display = "none";
            successMessage.style.display = "block";
            console.log('sendgrid response', sendGrid);
        } catch (err) {
            console.error(`Error: ${err}`);
        }
    });
</script>

但是,脚本始终返回POST https://api.sendgrid.com/v3/contactdb/recipients 401 (UNAUTHORIZED)错误。 api密钥是正确的,并且具有完全的读/写访问权限,因此这不应该成为问题。关于潜在问题有什么想法吗?

0 个答案:

没有答案