A space to discuss GraphQL queries, mutations, troubleshooting, throttling, and best practices.
Hi there.
I am trying to create a Metafield for an order:
URI: /admin/api/2022-01/orders/ORDER_ID/metafields.json
data:
<?
$metaFieldData = array
(
[metafield] => array
(
[namespace] => my_fields
[type] => single_line_text_field
[key] => nalogProdajeId
[value] => 281-2891
)
);
?>
and I get response: 1
Any ideas?
I can manipulate an existing field, but not create an entirely new one.
Solved! Go to the solution
This is an accepted solution.
Hi @McJagger – big fan of your music! Let's see if I can help...
Before I get started, I wanted to suggest using metafield definitions via the GraphQL API. You can apply a metafield definition to all of your orders (under a given namespace and key) which can help validate your metafield data moving forward!
To create a metafield on an order using the REST API, you'll need to POST your data to:
https://<YOUR_STORE>.myshopify.com/admin/api/2022-01/orders/<ORDER_ID>/metafields.json
I can manipulate an existing field, but not create an entirely new one.
That suggests to me that you might be using the wrong HTTP method to update your metafields. According to the REST API for metafields:
Always be sure to use the right method and URI.
Finally, I also wanted to mention that response code 1 is not a standard response. Sometimes you can get a response code of -1 when you're having network or connection issues, so there might be an issue with your network. Hope that's helpful!
To learn more visit the Shopify Help Center or the Community Blog.
This is an accepted solution.
Hi @McJagger – big fan of your music! Let's see if I can help...
Before I get started, I wanted to suggest using metafield definitions via the GraphQL API. You can apply a metafield definition to all of your orders (under a given namespace and key) which can help validate your metafield data moving forward!
To create a metafield on an order using the REST API, you'll need to POST your data to:
https://<YOUR_STORE>.myshopify.com/admin/api/2022-01/orders/<ORDER_ID>/metafields.json
I can manipulate an existing field, but not create an entirely new one.
That suggests to me that you might be using the wrong HTTP method to update your metafields. According to the REST API for metafields:
Always be sure to use the right method and URI.
Finally, I also wanted to mention that response code 1 is not a standard response. Sometimes you can get a response code of -1 when you're having network or connection issues, so there might be an issue with your network. Hope that's helpful!
To learn more visit the Shopify Help Center or the Community Blog.