--- url: https://docs.youcan.shop/store-admin/metafields/crud.md --- # CRUD Metafield management is available through the admin API. Anyone with access to a resource can list and read its metafields. Writes are limited to apps. ## Who can write * Only a token that belongs to an app can create, update or delete a metafield. Other tokens get HTTP 403 with `only apps can write metafields`. * An app writes only in the namespace equal to its app handle. For an app with the handle `reviews-app`, the namespace is `reviews-app`. * A write in another namespace gets HTTP 403 with `apps can only write metafields in the namespace`. This also applies to an update or a delete by ID of a metafield in another namespace. * An update by ID only changes a metafield of the resource in the URL. Another resource's metafield ID returns `resource not found`. ## List ### Response ```json [ { "id": "2YcBCnAFyyDjLv0wuhZdFnWIqjR", "namespace": "reviews-app", "key": "rating", "value": "4", "type": "number" } ] ``` ## Create ### Parameters > \[!NOTE] > `value_type` supports [these types](./types.md). The input parameter is named `value_type` but the response field is named `type`. Some scenarios to consider when creating a new metafield. * If the namespace and key already exists, and the existing value is not a list, we override the value. * If the namespace and key already exists, the existing value is a list, and the coming value is single, we append the value to the list. * If the namespace and key already exists, the existing value is a list, and the coming value is a list, we override the value. ### Response ```json { "id": "2YcBCnAFyyDjLv0wuhZdFnWIqjR", "namespace": "reviews-app", "key": "rating", "value": "4", "type": "number" } ``` ## Update ### Parameters > \[!NOTE] > `value_type` supports [these types](./types.md) ### Response ```json { "status": 200, "detail": "", "meta": [] } ``` ## Delete ### By ID #### Response ```json { "message": "The resource has been successfully deleted.", "type": "success" } ``` ### By namespace and key #### Response ```json { "message": "The resource has been successfully deleted.", "type": "success" } ``` ## Show ### By ID #### Response ```json { "id": "2YcCVBRMqjpRcqFbeN9fpUAWmQc", "namespace": "reviews-app", "key": "rating", "value": "4", "type": "number" } ``` ### By namespace and key #### Response ```json { "id": "2YcCVBRMqjpRcqFbeN9fpUAWmQc", "namespace": "reviews-app", "key": "rating", "value": "4", "type": "number" } ```