Core Resources
Metafields
Metafields allow users to add additional information to other resources. They can be used for adding custom fields to objects, and are useful for storing specialized information.
2 additions in V2, marked New
Everything marked New also works when you send X-Recharge-Version: 2021-11.
#The metafield object
Metafields feature allows to add additional information to other resources. They can be used for adding custom fields to objects, and are useful for storing specialized information.
You can extend the responses of some of these objects by appending the
cf. Extending responses for more info.
include?=metafields as part of your GET request.cf. Extending responses for more info.
Attributes
- idintegerUnique numeric identifier for the metafield.
- created_atdatetimeThe date and time when the metafield was created.
- descriptionstringDescription of the metafield.
- keystringThe name of the metafield.
- namespacestringA category or container that differentiates your metadata from other metafields.
- owner_idintegerUnique numeric identifier of the
owner_resource. - owner_resourcestringObjects which support
MetafieldsPossible valuesaddressstorecustomersubscriptionordercharge - updated_atdatetimeThe date and time when the metafield was last updated.
- valuestringThe content of the metafield.
- value_typestringThe type of the value parameter.Possible values
stringintegerjson_string
{
"metafield": {
"id": 33,
"created_at": "2018-11-07T14:00:10",
"description": "customer_phone_number",
"key": "phone_number",
"namespace": "personal_info",
"owner_id": 18301938,
"owner_resource": "customer",
"updated_at": "2018-11-07T14:00:10",
"value": "3103103101",
"value_type": "integer"
}
}#Create a metafield
POST/metafields
Creates a metafield for a specific object.
Scopes
write_customerswrite_subscriptionswrite_orderswrite_storesThere is a limit of 50 metafields per
You need to have
Returns
owner_id.You need to have
WRITE rights to the resource you want to create a Metafield for.Returns
201. The required scope depends on owner_resource: write_customers for address and customer, write_subscriptions for subscription, write_orders for charge and order, and write_stores for store. namespace and key are limited to 50 characters, value to 1000 characters, and an owner can have at most 50 metafields.Body parameters
- descriptionstringDescription of the metafield.
- The name of the metafield.
- A category or container that differentiates your metadata from other metafields.
- Unique numeric identifier of the owner resource.
- The owner of the resource.Possible values
addressstorecustomersubscriptionordercharge - The content of the metafield.
- The type of the value parameter.Possible values
stringintegerjson_string
curl -X POST 'https://api.rechargeapps.com/metafields' \
-H 'Content-Type: application/json' \
-H 'X-Recharge-Version: v2' \
-H 'X-Recharge-Access-Token: your_api_token' \
-d '{
"metafield": {
"description": "customer_phone_number",
"key": "phone_number",
"namespace": "personal_info",
"owner_resource": "customer",
"owner_id": 18301938,
"value_type": "integer",
"value": "3103103101"
}
}'{
"metafield": {
"id": 33,
"created_at": "2018-11-07T14:00:10",
"description": "customer_phone_number",
"key": "phone_number",
"namespace": "personal_info",
"owner_id": 18301938,
"owner_resource": "customer",
"updated_at": "2018-11-07T14:00:10",
"value": "3103103101",
"value_type": "integer"
}
}#Retrieve a metafield
GET/metafields/{id}
Retrieves a single metafield based on a specified id.
In addition to that, you can retrieve them by
HTTP request examples
GET /metafields/<metafield_id> In addition to that, you can retrieve them by
subscription_id by using: GET /metafields?owner_resource=subscription&owner_id=<subscription_id>Scopes
read_customersread_subscriptionsread_ordersstore_infoThe required scope depends on the
owner_resource of the metafield: read_customers for address and customer, read_subscriptions for subscription, read_orders for charge and order, and store_info for store.curl 'https://api.rechargeapps.com/metafields/33' \
-H 'X-Recharge-Access-Token: your_api_token' \
-H 'X-Recharge-Version: v2'{
"metafield": {
"id": 33,
"created_at": "2018-11-07T14:00:10",
"description": "customer_phone_number",
"key": "phone_number",
"namespace": "personal_info",
"owner_id": 18301938,
"owner_resource": "customer",
"updated_at": "2018-11-07T14:00:10",
"value": "3103103101",
"value_type": "integer"
}
}#Update a metafield
PUT/metafields/{id}
Updates a metafield based on a specified
owner_resource.Scopes
write_customerswrite_subscriptionswrite_orderswrite_storesReturns
200. The required scope depends on the owner_resource of the metafield; changing owner_resource requires the write scope of both the current and the new owner resource. The namespace and key of an existing metafield cannot be changed.Body parameters
- descriptionstringDescription of the metafield.
- owner_idintegerUnique numeric identifier of the resource.
- owner_resourcestringThe owner of the resource can be one of the following values:
address,store,customer,subscription,order,charge. There may be more objects added in the future.Possible valuesaddressstorecustomersubscriptionordercharge - valuestringThe content of the metafield.
- value_typestringThe type of the value parameter.Possible values
stringintegerjson_string
curl -X PUT 'https://api.rechargeapps.com/metafields/33' \
-H 'Content-Type: application/json' \
-H 'X-Recharge-Access-Token: your_api_token' \
-H 'X-Recharge-Version: v2' \
-d '{
"metafield": {
"description": "phone_number_of_customer",
"owner_id": 18293088,
"owner_resource": "customer",
"value": "0333103133",
"value_type": "integer"
}
}'{
"metafield": {
"id": 33,
"created_at": "2018-11-07T14:00:10",
"description": "customer_phone_number",
"key": "phone_number",
"namespace": "personal_info",
"owner_id": 18301938,
"owner_resource": "customer",
"updated_at": "2018-11-07T14:00:10",
"value": "3103103101",
"value_type": "integer"
}
}#Delete a metafield
DELETE/metafields/{id}
Delete a metafield based on a specified id.
Scopes
write_customerswrite_subscriptionswrite_orderswrite_storesThe required scope depends on the
owner_resource of the metafield: write_customers for address and customer, write_subscriptions for subscription, write_orders for charge and order, and write_stores for store.curl -X DELETE 'https://api.rechargeapps.com/metafields/6' \
-H 'X-Recharge-Access-Token: your_api_token' \
-H 'X-Recharge-Version: v2'{}#List metafields
GET/metafields
Retrieves a list of metafields.
When getting metafields, you must specify owner_resource in the URL. It can be
You can list metafields that are created for all subscription objects using:
HTTP request examples
GET /metafields?owner_resource=<owner_resource> GET /metafields?owner_resource=subscription&owner_id=<subscription_id> GET /metafields?owner_resource=customer&owner_id=<customer_id> GET /metafields?owner_resource=store&owner_id=<store_id> When getting metafields, you must specify owner_resource in the URL. It can be
address, store, customer, subscription, order, charge You can list metafields that are created for all subscription objects using:
GET /metafields?owner_resource=subscription - owner_id in the response will be the ID of the subscription.Scopes
read_customersread_subscriptionsread_ordersstore_infoowner_resource is required unless cursor is passed. The required scope depends on owner_resource: read_customers for address and customer, read_subscriptions for subscription, read_orders for charge and order, and store_info for store.Query parameters
- Return either the next or previous page of metafields using the
next_cursororprevious_cursorvalue from a previous response. Onlylimitcan be passed together withcursor. - limitstringAmount of results.
(default:50) (maximum: 250). - namespacestringA category or container that differentiates your metadata from other metafields.
- owner_idintegerUnique numeric identifier of the owner resource.
- owner_resourcestringThe owner of the resource can be one of the following values:
address,store,customer,subscription,order,charge. There may be more objects added in the future.Possible valuesaddressstorecustomersubscriptionordercharge - Page to show.Page-based pagination has been deprecated but still available to use for pages up to a 100. If you need data past this point, use cursor pagination.
- Sort listed
Metafieldsin a specific order. Available sort options:id-asc,id-desc,updated_at-asc,updated_at-desc. Defaults toupdated_at-desc.Possible valuesid-ascid-descupdated_at-ascupdated_at-desc
curl 'https://api.rechargeapps.com/metafields?owner_resource=address&limit=3' \
-H 'X-Recharge-Access-Token: your_api_token' \
-H 'X-Recharge-Version: v2'{
"next_cursor": "next_cursor",
"previous_cursor": "previous_cursor",
"metafields": [
{
"id": 33,
"created_at": "2018-11-07T14:00:10",
"description": "customer_phone_number",
"key": "phone_number",
"namespace": "personal_info",
"owner_id": 18301938,
"owner_resource": "customer",
"updated_at": "2018-11-07T14:00:10",
"value": "3103103101",
"value_type": "integer"
},
{
"id": 15,
"created_at": "2018-11-05T12:59:30",
"description": "desc lorem ipsum",
"key": "marjan",
"namespace": "nmsp2c",
"owner_id": 17868054,
"owner_resource": "customer",
"updated_at": "2018-11-05T15:48:42",
"value": "5",
"value_type": "integer"
},
{
"id": 9,
"created_at": "2018-11-05T12:47:27",
"description": "desc lorem ipsum",
"key": "marjan",
"namespace": "nmspc",
"owner_id": 17868054,
"owner_resource": "customer",
"updated_at": "2018-11-05T12:47:27",
"value": "5",
"value_type": "integer"
}
]
}