1

We are using Walmart Open APIs and getting CORS issue. For example, when attempting to call tending items API, we are getting the following response: (replacing API key, publisher ID and domain for security)

Access to XMLHttpRequest at 'https://api.walmartlabs.com/v1/trends?apiKey={api_key}&amp&publisherId={publisher_id}&format=json' from origin 'https://example.com' 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.

How do we whitelist our domain for cross origin ? Please advise.

Attempted to call the Walmart open API from javascript code on our website. Not sure how to resolve CORS issue.

Was expecting to get back list of trending items from Walmart APIs.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
BZN
  • 19
  • 1
  • They don't support calling the API from JavaScript, probably because that exposes the key to the whole world in the developer tools of every client visiting your website – Ferrybig Oct 18 '19 at 06:11
  • Does this answer your question? [XMLHttpRequest cannot load XXX No 'Access-Control-Allow-Origin' header](https://stackoverflow.com/questions/35553500/xmlhttprequest-cannot-load-xxx-no-access-control-allow-origin-header) – Quentin Jun 01 '22 at 09:52

1 Answers1

3

Try using this piece of line in package.json
"proxy": "http://192.165.1.220:28080",

where this host and port will be of walmart and install "http-proxy-middleware" using npm and try again.

CORS: EXPLANATION Cross-Origin Resource Sharing (CORS) is a mechanism that uses additional HTTP headers to tell browsers to give a web application running at one origin, access to selected resources from a different origin. A web application executes a cross-origin HTTP request when it requests a resource that has a different origin (domain, protocol, or port) from its own. Means your localhost is trying to connect other domain so for security purpose it is blocking. You need to enable it for connecting to their IP.

For more clear and wider views :https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS

Nimantha
  • 6,405
  • 6
  • 28
  • 69
Ayushi Keshri
  • 680
  • 7
  • 18