Order Metafield

Hi there.

I am trying to create a Metafield for an order:

URI: /admin/api/2022-01/orders/ORDER_ID/metafields.json

data:

 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.

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://

> *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](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods) to update your metafields. According to the [REST API for metafields](https://shopify.dev/api/admin-rest/2022-01/resources/metafield#top):

- 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](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status). 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!