skip to Main Content

GET /admin/products.json?collection_id=841564295

$.getJSON("/admin/products.json?collection_id=841564295", function(productData) {
console.log(productData);
});

using this code i’m getting all the products in a collection by collection id….
only if i’m logged in as admin..

if i’m not loggedin there is no response but “Status Code:303 See Other” error..

3

Answers


  1. Chosen as BEST ANSWER
    $.getJSON("/collections/#collection-handle/products.json", function(productList) {
    console.log(productList);
    });
    

    Got all the products by collection....


  2. The 303 is a redirect (to the login page).

    Use the /products endpoint instead:

    $.getJSON("/products.json?collection_id=841564295", function(productData) {
    console.log(productData);
    });

    Login or Signup to reply.
  3. You can do like this:
    I am getting namespace of product using this api, you can get whatever you want in products.

    var backvalues2=[]; 
    var product_url='admin/products/2142613700675/metafields.json';   
      $.getJSON(product_url).then
       (function (data) {
    
          $(data.metafields).each(function (i, list) {
    
         backvalues2.push(list.namespace);
         });
    
       }).fail(function () {
          alert("Please Check Internet Connection")
         }).always(function () { });
        console.log(backvalues2);
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search