0

I am working on shopify private app . During some task adding some meta fields using shopify api method:

Add a metafield to an existing collection

PUT /admin/custom_collections/#{id}.json
{
  "custom_collection": {
    "id": 841564295,
    "metafields": [
      {
        "key": "new",
        "value": "newvalue",
        "value_type": "string",
        "namespace": "global"
      }
    ]
  }
} 

========================================== next i need to get all collection meta fields but i did't found any solution.

1
  • What are you asking? Are you able to add the metafields but not retrieve them or not add them at all? Commented Aug 24, 2016 at 16:52

1 Answer 1

1

Any resource in Shopify provides a method to get the Metafield resources attached to them. So given that you have a collection ID, think along these lines:

/custom_collections/:id/metafields.json

...to get the Metafields resources using RestAPI. Beware the fact that you might only get 50 of the resources since that is an internal limit. You can get more when you page through the resources and provide a limit. With paging, you can get all the resources, up to 250 Metafields per call.

Note that there are other ways to do this too, using mutations with the GraphQL library for example.

Sign up to request clarification or add additional context in comments.

5 Comments

That doesn't work with the Storefront API though
Ya no kidding. Look at the URL. The OP is not using Storefront API, but the regular admin API. Note the /admin in the URL.
I wasn't kidding, it actually doesn't work with the Storefront API.
That is why I said no kidding. Even if you were kidding. I guess your comment is helpful in the sense that someone, some time might be curious if StorefrontAPI works for that. Quite a few people do screw that up, sure.
Anyways this guy said he's adding the metafields using the admin api but he didn't say which api he wants to use to retrieve them. The good news for everyone is that it'll be possible to retrieve collections metafields with the admin api (currently possible) as well as the storefront api soon: shopify.dev/changelog/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.