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.

Order Metafield

Solved

Order Metafield

McJagger
Visitor
1 0 0

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.

Accepted Solution (1)

stratify
Shopify Staff (Retired)
20 2 14

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:

  • POST – Creates a new metafield for a resource
  • PUT – Updates a metafield

 

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.

View solution in original post

Reply 1 (1)

stratify
Shopify Staff (Retired)
20 2 14

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:

  • POST – Creates a new metafield for a resource
  • PUT – Updates a metafield

 

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.