Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

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

Solved

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

Zona
Visitor
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)

Jason
Shopify Partner
11206 226 2314

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 in my free time to help and share some insights. Not looking to be hired, and not looking for work. http://freakdesign.com.au ★

View solution in original post

Replies 8 (8)

Jason
Shopify Partner
11206 226 2314

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 in my free time to help and share some insights. Not looking to be hired, and not looking for work. http://freakdesign.com.au ★
Zona
Visitor
2 0 0

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

stratify
Shopify Staff (Retired)
20 2 13

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`

To learn more visit the Shopify Help Center or the Community Blog.

ken001
Shopify Partner
6 0 8

@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 (Retired)
20 2 13

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.

To learn more visit the Shopify Help Center or the Community Blog.

ken001
Shopify Partner
6 0 8

can I suggest posting a new question if you're still having issues?

No, I don't have any issue.

Thank you for your suggestion.

 

Zeeshan007
Tourist
6 0 1

hello everyone i just need in admin api for metafields i am using as documented but got an error

stratify
Shopify Staff (Retired)
20 2 13

Hi @Zeesh the original issue has been resolved. Please create a new issue on the Community Forums.

 

You're more likely to get an answer if you provide more context on your question. Be sure to provide text examples instead of screenshots, and feel free to tag me in the new post and I'll do my best to help 🙂

To learn more visit the Shopify Help Center or the Community Blog.