Define Metafields via Admin-API in PHP (Admin2024_01)

Solved

Define Metafields via Admin-API in PHP (Admin2024_01)

Wowa85
Shopify Partner
1 0 0

Hello,

the API documentation for the PHP programming language is horrible. It's hard to understand anything.

I need to migrate a lot of data from OXID Shop System to Shopify. 🙈

Actually, I am trying to create some metafields for collections. We want to display a text for search engines on the collection page below, under the pagination.

In the first step, I just want to create/define some meta fields and then assign the values for each collection in a for-each loop.

This is the documentation:
https://shopify.dev/docs/api/admin-rest/2024-01/resources/metafield#post-blogs-blog-id-metafields

The title is "Create meta fields".

It's not clear what they mean by "create".

Create an assignment -> assign / set a value to an object
or
Create a definition -> create a new meta field with name and description to assign/set the values later?

Or does this call automatically check if the definition already exists and create it if not.


It is extremely wired. Why do I have the option to specify a description as a parameter that is never used, and why can't I specify a name?

I have uploaded 2 screenshots:
s1.jpg

 

s2.jpg

 



Accepted Solution (1)

Liam
Community Manager
3108 340 871

This is an accepted solution.

Hi - It may actually be easier to use the GraphQL API rather than the REST API for this, with the metafieldDefinitionCreate mutation. There's an example of what this could look like in our developer docs

Liam | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

View solution in original post

Reply 1 (1)

Liam
Community Manager
3108 340 871

This is an accepted solution.

Hi - It may actually be easier to use the GraphQL API rather than the REST API for this, with the metafieldDefinitionCreate mutation. There's an example of what this could look like in our developer docs

Liam | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog