Admin API metafields.json GET request is not returning all metafields for one specific store

Solved
Zona
New Member
2 0 0

Hi,

We stored some metafield data (ID: 20549960138948) for one of the merchants https://ruglove-co-uk.myshopify.com. Through Postman, we can get the metafield data through the GET request https://ruglove-co-uk.myshopify.com/admin/api/2021-07/metafields/20549960138948.json but when we change the request to https://ruglove-co-uk.myshopify.com/admin/api/2021-07/metafields.json, the stored data is not returned from the body. Do you know what might be going on here? We're able to get our metafield data for other test stores using the above requests.

Accepted Solution (1)

Accepted Solutions
Jason
Shopify Expert
10463 169 2081

This is an accepted solution.

My guess: you have lots of metafields on the product and you are either

  • not setting a limit for how many to get back (eg, you are getting 50 back by default but your metafield is actually at index 51),
  • not paginating to get them all in the cases of truly massive metafield counts
I jump on these forums to help and share some insights. Not looking to be hired, and not looking for work.
Don't hand out staff invites or give admin password to forum members unless absolutely needed. In most cases the help you need can be handled without that.
★ http://freakdesign.com.au ★

View solution in original post

Replies 5 (5)
Jason
Shopify Expert
10463 169 2081

This is an accepted solution.

My guess: you have lots of metafields on the product and you are either

  • not setting a limit for how many to get back (eg, you are getting 50 back by default but your metafield is actually at index 51),
  • not paginating to get them all in the cases of truly massive metafield counts
I jump on these forums to help and share some insights. Not looking to be hired, and not looking for work.
Don't hand out staff invites or give admin password to forum members unless absolutely needed. In most cases the help you need can be handled without that.
★ http://freakdesign.com.au ★

View solution in original post

Zona
New Member
2 0 0

Is the metafield pagination documented anywhere? I can't find it in the REST API doc

stratify
Shopify Staff
15 1 7

Hey @Zona thanks for posting a question on the forums! As @Jason mentioned above, you can paginate your requests to the REST API using the response headers on your request.

Specifically, you want to iterate over the pages of your request. There, you'll see some URL parameters that you can use like "limit" and "page_info" – I wouldn't suggest increasing the limit because you'll risk timing out your requests. Instead, use the page_info parameter to go to the next page of metafields until you've found the right one.

You can also filter the metafields that you request using the following URL parameters:

  • "namespace" 
  • "key"
  • "type"
  • "created_at_min" (by providing a date)
  • "created_at_max"
  • "updated_at_min"
  • "updated_at_max"

For example, you can get shop metafields with the namespace "Shopify" that were created on or after January 1st, 2021, with the following URL:

`/admin/api/2021-07/metafields.json?limit=50&namespace=Shopify&created_at_min=2021-01-01`

ken001
New Member
3 0 0

@stratify Hello Stratify, I'd like to ask a question.

 

You can also filter the metafields that you request using the following URL parameters:

For example, you can get shop metafields with the namespace "Shopify" that were created on or after January 1st, 2021, with the following URL:

`/admin/api/2021-07/metafields.json?limit=50&namespace=Shopify&created_at_min=2021-01-01`

Is it able to filter "Shop" type by using namespace and key?

I couldn't filter the metafields by URL parameters.

Also, I'm using "/admin/api/2021-07".

 

This is my code.

import Shopify from '@shopify/shopify-api';
const client = new Shopify.Clients.Rest('your-development-store.myshopify.com', accessToken);
const res = await client.get({
    path: 'metafields',
    query: {"metafield%5Bnamespace%5D":"grobal","metafield%5Bkey%5D":"test"},
  });
console.log("getSettingsFromApi res: ");
console.dir(res, { depth: null });

Reference

https://shopify.dev/api/admin-rest/2021-10/resources/metafield#[get]/admin/api/2021-10/metafields.js...

stratify
Shopify Staff
15 1 7

Hi @ken001 – can I suggest posting a new question if you're still having issues? It helps everyone in the Community when we have one question per thread.

 

For future reference, we can filter Shop-level metafields via the API. That's actually how Product Image metafields are accessed:

/admin/metafields.json?metafield[owner_id]=#{id}&metafield[owner_resource]=product_image


Be sure to double check that you're querying the right details, including shop URL, access token, and URL parameters. For example, your code is querying for the namespace "grobal" when you probably want "global" – hope that helps! If not, feel free to tag me on a new question.