Extra attributes (Metafields)

Thinking that Ordering API is more malleable and can be extended more easily, apart from plugins there is a way to add extra attributes to certain models.

This is achieved through endpoints called "Metafields" and the models that can use them are listed below:

  • User
  • Business
  • Category
  • Product
  • Extra
  • ExtraOption
  • ExtraOptionSuboption
  • Menu
  • Offer
  • Address
  • Drivergroup
  • Order

Metafields Model

The users model has the following attributes:

AttributeTypeRequiredDescription
keystringno, required to createThe name of the new attributte
valuestringno, required to createThe value of the metafield
value_typestringno, required to createThe type of value of the metafield

Values type

Values type specifies the type of value this attribute will have

  • integer
  • decimal
  • boolean
  • text
  • json

Obtaining Metafields

There are two ways to obtain the metafiels using params which are, first "metadata" that bring the metafiels as a normal attribute of the model and second "metafields" which brings the "metafiels" attribute with all the metafields in an array.

Example of Metadata

{
  "error": false,
  "result": [
    {
      "id": 1292,
      "name": "Bird's Nest",
      "price": 3,
      "description": "",
      "images": "https://res.cloudinary.com/ordering/image/upload/v1534195638/sp1iv1xmacqfnwyhbvkr.jpg",
      "sku": null,
      "category_id": 248,
      "inventoried": false,
      "quantity": 0,
      "featured": false,
      "enabled": true,
      "category": null,
      "extras": [],
      "gallery": [],
      "extra_atributte1": "value1",
      "extra_atributte2": "value2"
    },
    ...
  ]
}

Example of Metafields

{
  "error": false,
  "result": [
    {
      "id": 1292,
      "name": "Bird's Nest",
      "price": 3,
      "description": "",
      "images": "https://res.cloudinary.com/ordering/image/upload/v1534195638/sp1iv1xmacqfnwyhbvkr.jpg",
      "sku": null,
      "category_id": 248,
      "inventoried": false,
      "quantity": 0,
      "featured": false,
      "enabled": true,
      "category": null,
      "extras": [],
      "gallery": [],
      "metafields": [
        0:{
          "id":1,
          "object_id":1292,
          "model":"Product",
          "key":"number",
          "value":"text",
          "value_type":"text",
          "created_at":"2019-07-25 16:03:23",
          "updated_at":"2019-07-25 16:03:23",
        }
        ...
      ]
    },
    ...
  ]
}

📘

If the request is not filtered with the parameters, bring the metafields in both ways.