Unable to get data on /admin/products.json

chandra
New Member
2 0 0

hi 

 

have unable to get data using jquery/json

it give athuntication error 

any buddy help.

 

Thanks...

 

 

 

 

 

Replies 4 (4)
Jason
Shopify Expert
11119 218 2266

Hi chandra,

We need more context to be able to help you here. Things that will help are:

  • What you need that data for
  • Examples of the code you're using,
  • Where you're calling it from (from an app, theme, something else?),
  • The error returned

Since you mentioned jQuery it sounds like you're trying to access the secure API via storefront / theme code. The API requires authentication and should not be accessed in that way. 

★ I jump on these forums in my free time to help and share some insights. Not looking to be hired, and not looking for work. http://freakdesign.com.au ★
chandra
New Member
2 0 0

hi Jason,

have try to on aspx page using jquery 

For Get product detail 

below given code have use

  <script type="text/javascript">
     $(document).ready(function () {
         alert("sssa");

         var jsonData = {
             "apikey": "[redacted]",
             "Password": "[redacted]"
         };

         $.ajax({
             type: 'GET',
             dataType: 'json',
             url: 'https://cstechmkweb.myshopify.com/admin/products.json',
             data: jsonData,
                 headers: {
                     "Access-Control-Allow-Origin: ": "*",
                    
                 },

                 success: function (data) {
                     alert("hello");
                 alert(JSON.stringify(data));
             },
                 error: function () {
                     alert("An error occurred while processing JSON file.");
                 }

         });
      

 

Thanks..

Jason
Shopify Expert
11119 218 2266

I edited your post to remove the secure API key and password details. I know you had been asked for code but never post those details on a public site. I would suggest that you delete that key immediately and make a new one.

As suspected, you're trying to access the Shopify API with JavaScript - likely on a page visible to the public. You should not do this as it exposes the API key and password to anyone viewing that page. I can not stress enough how bad that is from a security standpoint.

Why do you need to use the API to get that data?
What are you trying to do that can't already do on the storefront?

 

★ I jump on these forums in my free time to help and share some insights. Not looking to be hired, and not looking for work. http://freakdesign.com.au ★
Elisha1
New Member
2 0 2

I'm also struggling to authenticate with Shopify.

I'm trying to get this page: 

https://store.myshopify.com/admin/products.json

but what I get is:

=> {"errors"=>"[API] Invalid API key or access token (unrecognized login or wrong password)"}.

I was trying to achieve it through this:

url = 'https://'+@api_key+':'+@password+'@storename.myshopify.com/admin/products.json' 
uri = URI(url)  
response = Net::HTTP.get(uri) 
p = JSON.parse(response)

I suspect that the method I'm using is not longer supported .. maybe I should try another method using headers or something?