When I tried to get the products under a collection, the price is missed

Solved

I am using GET /admin/api/2020-07/collections/{collection_id}/products.json to get the products under a collection. It works however the price field cannot be found. 

The response (only include 1st product for simplicity):

{
  "products": [
    {
      "id": 4494944862285,
      "title": "ADIDAS | CLASSIC BACKPACK | LEGEND INK MULTICOLOUR",
      "body_html": "The adidas BP Classic Cap features a pre-curved brim to keep your face shaded, while a hook-and-loop adjustable closure provides a comfortable fit. With a 3-Stripes design and reflective accents. The perfect piece to top off any outfit.",
      "vendor": "ADIDAS",
      "product_type": "ACCESSORIES",
      "created_at": "2020-02-09T23:41:51-05:00",
      "handle": "adidas-classic-backpack-legend-ink-multicolour",
      "updated_at": "2020-07-30T06:34:27-04:00",
      "published_at": "2020-02-09T23:41:51-05:00",
      "template_suffix": null,
      "published_scope": "web",
      "tags": "adidas, backpack, egnition-sample-data",
      "admin_graphql_api_id": "gid://shopify/Product/4494944862285",
      "options": [
        {
          "id": 5874089328717,
          "product_id": 4494944862285,
          "name": "Size",
          "position": 1
        },
        {
          "id": 5874089361485,
          "product_id": 4494944862285,
          "name": "Color",
          "position": 2
        }
      ],
      "images": [
        {
          "id": 14166500737101,
          "product_id": 4494944862285,
          "position": 1,
          "created_at": "2020-02-09T23:41:51-05:00",
          "updated_at": "2020-07-27T22:31:13-04:00",
          "alt": "ADIDAS | CLASSIC BACKPACK | LEGEND INK MULTICOLOUR - Sillycube Demo Shop",
          "width": 635,
          "height": 560,
          "src": "https://cdn.shopify.com/s/files/1/1498/3202/products/8072c8b5718306d4be25aac21836ce16.jpg?v=1595903473",
          "variant_ids": [
            
          ],
          "admin_graphql_api_id": "gid://shopify/ProductImage/14166500737101"
        },
        {
          "id": 14166500769869,
          "product_id": 4494944862285,
          "position": 2,
          "created_at": "2020-02-09T23:41:51-05:00",
          "updated_at": "2020-07-27T22:31:16-04:00",
          "alt": "ADIDAS | CLASSIC BACKPACK | LEGEND INK MULTICOLOUR - Sillycube Demo Shop",
          "width": 635,
          "height": 560,
          "src": "https://cdn.shopify.com/s/files/1/1498/3202/products/32b3863554f4686d825d9da18a24cfc6.jpg?v=1595903476",
          "variant_ids": [
            
          ],
          "admin_graphql_api_id": "gid://shopify/ProductImage/14166500769869"
        },
        {
          "id": 14166500802637,
          "product_id": 4494944862285,
          "position": 3,
          "created_at": "2020-02-09T23:41:51-05:00",
          "updated_at": "2020-07-27T22:31:20-04:00",
          "alt": "ADIDAS | CLASSIC BACKPACK | LEGEND INK MULTICOLOUR - Sillycube Demo Shop",
          "width": 635,
          "height": 560,
          "src": "https://cdn.shopify.com/s/files/1/1498/3202/products/044f848776141f1024eae6c610a28d12.jpg?v=1595903480",
          "variant_ids": [
            
          ],
          "admin_graphql_api_id": "gid://shopify/ProductImage/14166500802637"
        }
      ],
      "image": {
        "id": 14166500737101,
        "product_id": 4494944862285,
        "position": 1,
        "created_at": "2020-02-09T23:41:51-05:00",
        "updated_at": "2020-07-27T22:31:13-04:00",
        "alt": "ADIDAS | CLASSIC BACKPACK | LEGEND INK MULTICOLOUR - Sillycube Demo Shop",
        "width": 635,
        "height": 560,
        "src": "https://cdn.shopify.com/s/files/1/1498/3202/products/8072c8b5718306d4be25aac21836ce16.jpg?v=1595903473",
        "variant_ids": [
          
        ],
        "admin_graphql_api_id": "gid://shopify/ProductImage/14166500737101"
      }
    },
    ...
  ]
}

 

After that, I tried to use GET admin/api/2020-07/products/{productid}.json to check the product, I can find the price. Here is the response:

  "product": {
    "id": 4494944862285,
    "title": "ADIDAS | CLASSIC BACKPACK | LEGEND INK MULTICOLOUR",
    "body_html": "The adidas BP Classic Cap features a pre-curved brim to keep your face shaded, while a hook-and-loop adjustable closure provides a comfortable fit. With a 3-Stripes design and reflective accents. The perfect piece to top off any outfit.",
    "vendor": "ADIDAS",
    "product_type": "ACCESSORIES",
    "created_at": "2020-02-09T23:41:51-05:00",
    "handle": "adidas-classic-backpack-legend-ink-multicolour",
    "updated_at": "2020-07-30T06:34:27-04:00",
    "published_at": "2020-02-09T23:41:51-05:00",
    "template_suffix": null,
    "published_scope": "web",
    "tags": "adidas, backpack, egnition-sample-data",
    "admin_graphql_api_id": "gid://shopify/Product/4494944862285",
    "variants": [
      {
        "id": 31944543666253,
        "product_id": 4494944862285,
        "title": "OS / blue",
        "price": "50.00",
        "sku": "AD-04\r\n-blue-OS",
        "position": 1,
        "inventory_policy": "deny",
        "compare_at_price": "0.00",
        "fulfillment_service": "manual",
        "inventory_management": "shopify",
        "option1": "OS",
        "option2": "blue",
        "option3": null,
        "created_at": "2020-02-09T23:41:51-05:00",
        "updated_at": "2020-02-09T23:41:51-05:00",
        "taxable": true,
        "barcode": null,
        "grams": 0,
        "image_id": null,
        "weight": 0.0,
        "weight_unit": "kg",
        "inventory_item_id": 33761050001485,
        "inventory_quantity": 30,
        "old_inventory_quantity": 30,
        "requires_shipping": true,
        "admin_graphql_api_id": "gid://shopify/ProductVariant/31944543666253"
      }
    ],
    "options": [
      {
        "id": 5874089328717,
        "product_id": 4494944862285,
        "name": "Size",
        "position": 1,
        "values": [
          "OS"
        ]
      },
      {
        "id": 5874089361485,
        "product_id": 4494944862285,
        "name": "Color",
        "position": 2,
        "values": [
          "blue"
        ]
      }
    ],
    "images": [
      {
        "id": 14166500737101,
        "product_id": 4494944862285,
        "position": 1,
        "created_at": "2020-02-09T23:41:51-05:00",
        "updated_at": "2020-07-27T22:31:13-04:00",
        "alt": "ADIDAS | CLASSIC BACKPACK | LEGEND INK MULTICOLOUR - Sillycube Demo Shop",
        "width": 635,
        "height": 560,
        "src": "https://cdn.shopify.com/s/files/1/1498/3202/products/8072c8b5718306d4be25aac21836ce16.jpg?v=1595903473",
        "variant_ids": [
          
        ],
        "admin_graphql_api_id": "gid://shopify/ProductImage/14166500737101"
      },
      {
        "id": 14166500769869,
        "product_id": 4494944862285,
        "position": 2,
        "created_at": "2020-02-09T23:41:51-05:00",
        "updated_at": "2020-07-27T22:31:16-04:00",
        "alt": "ADIDAS | CLASSIC BACKPACK | LEGEND INK MULTICOLOUR - Sillycube Demo Shop",
        "width": 635,
        "height": 560,
        "src": "https://cdn.shopify.com/s/files/1/1498/3202/products/32b3863554f4686d825d9da18a24cfc6.jpg?v=1595903476",
        "variant_ids": [
          
        ],
        "admin_graphql_api_id": "gid://shopify/ProductImage/14166500769869"
      },
      {
        "id": 14166500802637,
        "product_id": 4494944862285,
        "position": 3,
        "created_at": "2020-02-09T23:41:51-05:00",
        "updated_at": "2020-07-27T22:31:20-04:00",
        "alt": "ADIDAS | CLASSIC BACKPACK | LEGEND INK MULTICOLOUR - Sillycube Demo Shop",
        "width": 635,
        "height": 560,
        "src": "https://cdn.shopify.com/s/files/1/1498/3202/products/044f848776141f1024eae6c610a28d12.jpg?v=1595903480",
        "variant_ids": [
          
        ],
        "admin_graphql_api_id": "gid://shopify/ProductImage/14166500802637"
      }
    ],
    "image": {
      "id": 14166500737101,
      "product_id": 4494944862285,
      "position": 1,
      "created_at": "2020-02-09T23:41:51-05:00",
      "updated_at": "2020-07-27T22:31:13-04:00",
      "alt": "ADIDAS | CLASSIC BACKPACK | LEGEND INK MULTICOLOUR - Sillycube Demo Shop",
      "width": 635,
      "height": 560,
      "src": "https://cdn.shopify.com/s/files/1/1498/3202/products/8072c8b5718306d4be25aac21836ce16.jpg?v=1595903473",
      "variant_ids": [
        
      ],
      "admin_graphql_api_id": "gid://shopify/ProductImage/14166500737101"
    }
  }
}

 

Why the price is missed, how can I get it?

SPO - SEO App to research keywords & edit social link preview
0 Likes
Greg_Kujawa
Shopify Partner
965 80 204

This is an accepted solution.

I believe that price goes down to the variant level, whereas the product is one level up. 

Below is a GraphQL API query that works. In the example, I provide a specific collection name, pull the first 10 products in that collection, and then drill down to pull the first 10 variants for each product.

Hope this helps!

query {
  collectionByHandle(handle: "Jewelry") {
    products(first: 10) {
      edges {
        node {
          id
          title
          description
          tags
          variants(first: 10) {
            edges {
              node {
                id
                title
                sku
                price
              }
            }
          }
        }
      }
    }
  }
}
0 Likes

This is an accepted solution.

After further researching, I find the correct endpoint should be GET /admin/api/2020-07/products.json?collection_id={collection_id}

source: https://shopify.dev/docs/admin-api/rest/reference/products/product?api[version]=2020-07#index-2020-0...

section: Retrieve all products that belong to a certain collection

SPO - SEO App to research keywords & edit social link preview
0 Likes