get json from a third-party source via javascript in shopify

max_max_max
Shopify Partner
35 0 3

I need to get json from a third-party source using a javascript, but when I do this I get a header error.

 

I did this using fetch() method:

 

fetch('https://orderarchive.okd.artpix3d.com/api/v1/shopify/shipping-methods', { mode: 'cors' });

 

And this option didn't help me - mode: 'cors'. I get this error:

 

has been blocked by CORS policy: 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.

 

Also, I made this solution:

 

$.getJSON('https://orderarchive.okd.artpix3d.com/api/v1/shopify/shipping-methods', function(data) {
    // Code
});

 

And also did a solution using XMLHttpRequest and etc. I have tried many methods and ways to get the json blacken javascript I want, but I always get the error I wrote above.

 

Please help me to get json through javascript, in shopify, or tell me how to do it.

 

I contacted the technical support shopify, but tech support could not give a specific answer to this question, and advised to write my question here.

 

Thank you.

 

Replies 6 (6)

Aument
Excursionist
34 0 9
What is it you're trying to do or solve? There seems to be some security protocol to consider but I'd be happy to help if I can.
Want more store sales, return customers, site conversions?
Try Aument free: apps.shopify.com/aument-platform
max_max_max
Shopify Partner
35 0 3

Thanks for the answer.
I just want to get json from a third-party source via javascript. Is this possible? If not, what could be the solution?

Aument
Excursionist
34 0 9


You should be able to, it might be a Cross Origin Resource Sharing (CORS) issue... Do you have that resource blocked for External IPS?


I reckon you'd get an answer in this forum: https://stackoverflow.com/ if none of us on Shopify manages to help!

Want more store sales, return customers, site conversions?
Try Aument free: apps.shopify.com/aument-platform
Aument
Excursionist
34 0 9

Hi Max! I was wondering if they helped over in stack overflow?

Want more store sales, return customers, site conversions?
Try Aument free: apps.shopify.com/aument-platform
max_max_max
Shopify Partner
35 0 3

Hello. Yes, I asked that question on stackoverflow. And I was told that this problem cannot be solved without reference to the server side. I need to write my own application to do this. This is so silly!

Aument
Excursionist
34 0 9

That's so frustrating! Shame we didn't find a solution for it. 😞

Want more store sales, return customers, site conversions?
Try Aument free: apps.shopify.com/aument-platform