Expose whitelisted metafields

Solved
Excursionist
33 4 1

Hello again,

 

I've created a few whitelisted metafields and now I'd like to retrieve the whitelist to know what was added. 

- admin/api/2019-10/graphql.json returns "Not Found"

- admin/api/2019-10/metafields.json only shows the metafields365 app information

- admin/products/#{id}/metafields.json only shows the applied metafields

My goal is to have a set of metafields, `app-settings`, that will assign some default values to the app functionality so I need to create the metafields, query for them, and utilize the result within the app.

 

Any guidance is much appreciated!

You are phoenix
0 Likes
Highlighted

Success.

Shopify Staff
Shopify Staff
382 52 60

Hey @jenn11 ,

 
There may be some confusion in regards to which Shopify API you are trying to use. Specifically, whether you trying to use the Shopify Admin API, or the Shopify Storefront API.
 
Whitelisting metafields is only a requirement if you are using the Shopify Storefront API. You first need to create the desired metafields on the Product or Product Variant (Storefront API currently can only read metafields on Products and Product Variants) and then use the GraphQL mutation  `metafieldStorefrontVisibilityCreate` with the Admin API to whitelist that metafield's namespace and key. You can now query these metafields through the Storefront API when querying for Products or Product Variants. To get the full list of all of the Metafields that you have whitelisted you can use the GraphQL query `metafieldStorefrontVisibilities` with the Admin API to get the IDs, namespaces, keys, and owners of all of the whitelisted metafields. You can read more about this process here
 
However if you are not using the Storefront API at all and just using the Admin API only, there is no need to whitelist metafields at all in the first place. You can just simply create the metafields on the desired resource (i.e. Customers, Collections, Products, Variants, Shop, etc.) and then query for them righaway. Here is some documentation on how to work with Metafields using the GraphQL Admin API and the REST Admin API
 

Hassain | Developer Support Specialist @ Shopify
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Click Accept as Solution 

1 Like
Highlighted
Excursionist
33 4 1

Thank you for the clarification, @hassain!

 

Following the API instructions you sent for creating a metafield on the Shop resource I'm encountering a new issue (does this require a new post? If so I'll amend) where I sent a POST request to /admin/metafields.json with the params:

namespace=testMetafield&key=testKey&value=testValue&value_type=json_string //also tried value_type=string

and receive the following error: 

"metafield": "Required parameter missing or invalid"

I'm using Postman and have verified authorization and removed all cookies on each request per @Jason in another thread regarding POSTs to the API.

You are phoenix
0 Likes
Highlighted

Success.

Shopify Staff
Shopify Staff
382 52 60

Hey @jenn11 ,

 

When sending a POST request to create a new resource, you do not pass in the values of the required fields through Query String Parameters but instead you pass them in as a JSON object in the "body" of the request.

 

So if you are using Postman to make this request, you do not need to add any params. Instead all you need is to include the appropriate Shopify Access Token credential and Content-Type in your header like so, and then add the JSON object with all the required fields in the body like this

 

Hope that helps. 

 

Hassain | Developer Support Specialist @ Shopify
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Click Accept as Solution 

1 Like
Highlighted
Excursionist
33 4 1

...I am le dumb and don't know how to use Postman. Thank you once again, @hassain!

You are phoenix
0 Likes