0

Error: ㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤ

Access to fetch at 'https://api.attentivemobile.com/v1/subscriptions' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.`

Code:

async function smsSubscription() {
const subscribe = await fetch('https://api.attentivemobile.com/v1/subscriptions', {
    method: 'post',
    body: JSON.stringify({
            "user": {
              "phone": '(502)276-8568',
              "email": 'any@any.com'
            },
            "signUpSourceId": "2323"
          }),
    headers: {
      'Content-Type': 'application/json',
      'Authorization': '[hidden]'
    }
 });
Terry
  • 63,248
  • 15
  • 96
  • 118
  • You're missing a header called 'Access-Control-Allow-Origin' – Gabriel Lupu Sep 10 '21 at 07:02
  • 1
    @GabrielLupu - to be clear, the SERVER is not sending that header – Bravo Sep 10 '21 at 07:03
  • 1
    @Magentodeveloper - is `api.attentivemobile.com` your site? if not, then you can't access the API directly from a browser - you'll need to access it via your server, since server to server requests are not limited by CORS - [Learn CORS in 6 minutes](https://www.youtube.com/watch?v=PNtFSVU-YTI) – Bravo Sep 10 '21 at 07:07
  • 1
    @Magentodeveloper, you need to enable CORS on your api code, by doing that your issue will be resolved. I hope this will help you. thanks! – Ajay Choudhary Sep 10 '21 at 07:08
  • 2
    @Magentodeveloper — There's a comprehensive explanation of CORS on the duplicate. Bravo has also linked to a video. Please stop asking people to explain things that have been explained a thousand times already. – Quentin Sep 10 '21 at 07:19
  • @Quentin Thanks for the comment. i nowhere asked for explanation to anybody. I am just expecting some more information on fixing the issue, simple that's it no other explanation.If you have got idea about it then sir please help this question. I am thankful to Bravo for the helpful link. – Magentodeveloper Sep 10 '21 at 07:23
  • 2
    @Magentodeveloper — The information you asked people to provide *is already provided on the duplicate question* (and three times earlier in this comment thread) – Quentin Sep 10 '21 at 07:24

0 Answers0