A space to discuss GraphQL queries, mutations, troubleshooting, throttling, and best practices.
We're moving the community! Starting July 7, the current community will be read-only for approx. 2 weeks. You can browse content, but posting will be temporarily unavailable. Learn more
I’m trying to get the product id for a hidden product (toggle subscription) within the cart through an AJAX API call from the client. As a first step, I’m just trying to return all products. I’ve tried creating a private app using the Admin API, but I’m unable to get the Basic HTTP Authentication to return the needed JSON. It returns an HTML document with additional login links. Any thoughts on what I may be doing wrong?
I understand what I'd be exposing, but access is read only for Products. Building a public app seems unnecessary and likely overkill for this simple need, but I’m open to suggestions.
$.ajax
({
type: "GET",
url: "/admin/api/2019-10/products.json",
beforeSend: function(xhr) {
xhr.setRequestHeader("Authorization", "Basic " + "BASE64 encoded credentials")
},
success: function(json){
console.log(json)
}
});
Return:
<html>
<body>
<noscript>
<a href="XXX ">Continue</a>
</noscript>
<script type="text/javascript">
window.location = "https:\/\/app.shopify.com\/services\/login\/identity?.... =shop";
</script>
</body>
</html>
This is not the right way to get that info.
You're trying to make a AJAX call from the front end to the secure Admin API that requires authentication. Even if you passed over a key and password via AJAX you'd be doing that in plain text so this is a terrible ideal on many fronts. You're risking exposing those details to the public.
You should be creating some middleware that handles the authentication vs trying to go directly to the Admin API.
Why do you need the unpublished ID on the front end? That context could help in terms of talking about different approaches.