MailChimp. Error 401 (Unauthorized) when sending a request for adding a new list member

こ雲淡風輕ζ 提交于 2021-01-05 09:17:06

问题


Here is how I'm trying to send a request:

fetch('https://us17.api.mailchimp.com/3.0/lists/185415c92c/members', {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
        'Authorization': 'anystring:8ec49e64f2041073d3fe56e0abc5fe5f-us17',
      },
      body: JSON.stringify({
        email_address: 'email@mail.ru',
        status: 'subscribed',
      }),
      mode: 'no-cors',
    })

And I get such error:

POST https://us17.api.mailchimp.com/3.0/lists/185415c92c/members 401 (Unauthorized)

What am I doing wrong?


回答1:


The Authorization header contains both type and credentials, but in your code the header only contains the latter. The following should work:

Authorization: Basic <base64-encoding of anystring:8ec49e64f2041073d3fe56e0abc5fe5f-us17>

https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Authorization

EDIT: The real reason why it wasn't working: CORS, which MailChimp understandably doesn't support.




回答2:


I kept having the same issue, I checked my Key from MailChimp in my account setting. Under KEY, it said my key "was disabled" and under LABEL it said "posted in public, do not enable". Sometimes it's not our code, it's the key itself. Try checking the key you are currently using.



来源:https://stackoverflow.com/questions/48903714/mailchimp-error-401-unauthorized-when-sending-a-request-for-adding-a-new-list

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!