I’m encountering a CORS issue while trying to connect to Shopify’s admin API from my Angular application using the HttpClient. Below is the service code I’m working with:
export class ShopifyConnectionService {
constructor(private httpClient: HttpClient) { }
getShopDetails() {
return this.httpClient.get('https://your-shop-name.myshopify.com/admin/api/2023-01/shop.json', {
headers: {
'Content-Type': 'application/json',
'X-Shopify-Access-Token': 'your_access_token',
'Access-Control-Allow-Origin': '*'
}
});
}
}
However, I keep receiving these errors when I try to execute this function:
CORS policy error: Access to XMLHttpRequest at 'https://your-shop-name.myshopify.com/admin/api/2023-01/shop.json' from origin 'http://localhost:4200' has been blocked because of CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
CORS error: Request failed with status 401
What can I do to fix this CORS issue when making requests to Shopify’s API from my Angular app?