Want to add a forum like this one to your store? Install Champ Now

Welcome to Champ's live demo

Did you know that this isn't just a demo?
This is our live pre-sales Q&A and support forum. Take a look around and say "Hello".

  • Forums
  • Support
  • Fetching data through API has been blocked by CORS policy
0

Fetching data through API has been blocked by CORS policy

Sep 18, 2019 - 2:44 AM

https://getchamp.myshopify.com/community/champ/forums/7/topics/10722 Copy
  • Hi all,
    I was using the API feature and succeeded in fetching data with Postman. However, when I tried to use Axios to send HTTP request in, say, champ-below-header.liquid, to fetch data, it returns 404 error stating 'No 'Access-Control-Allow-Origin' header is present on the requested resource'.
    What should I do to fetch the forum/topic/post data in the liquid?

    champ-cors-error.png

    0
  • This issue should now be fixed. I've enabled CORS on the API just now. Let me know if you're running into any issues.

    0

    Need help? Contact me at support@getchamp.net or here. Brand new! Add your own signature at https://getchamp.myshopify.com/community/champ/preference
  • Seems doesn't work either :( , another error came up. I tried to set the request header 'withCredentials' to be 'true' and 'false', but neither worked

    champ-cors-error-credentials.png

    0
  • Let me try and debug this today to see what's happening. I'll update this thread later today.

    0

    Need help? Contact me at support@getchamp.net or here. Brand new! Add your own signature at https://getchamp.myshopify.com/community/champ/preference
  • Update:

    It seems to work for me.

    Here's the code I used:

    $.ajax({
      url: 'https://api.getchamp.net/topics.json',
      type: 'GET',
      beforeSend: function (xhr) {
        xhr.setRequestHeader('X-API-SECRET', '<insert your api secret>');
        xhr.setRequestHeader('X-SHOPIFY-DOMAIN', 'getchamp.myshopify.com');
      },
      success: function (response) { console.log(response) }
    });
    

    I was able to call this from jQuery's own webpage.

    Let me know

    0

    Need help? Contact me at support@getchamp.net or here. Brand new! Add your own signature at https://getchamp.myshopify.com/community/champ/preference
Quick reply

How to format posts

Champ uses Markdown for formatting text in posts. Certain markup tags (eg. H1) are forbidden to ensure that pages remain semantically compliant. Other tags are automatically sanitized to ensure all content is secure.

  • Emphasis, aka italics, with *asterisks* or _underscores_.
  • Strong emphasis, aka bold, with **asterisks** or __underscores__.
  • Combined emphasis with **asterisks and _underscores_**.
  • Strikethrough uses two tildes. ~~Scratch this.~~
  • Links are added automatically, but can be formatted like so: [My link](https://mylink.com)
For more information, take a look at the Markdown Cheatsheet.