Every Wix API has a service object with predefined fields, which can’t be removed or changed. Sometimes, you might want to add additional fields to an object. For example, if your app uses the Booking object to help outdoor adventure companies book their services, you may want to add a field to include equipment rental as part of the booking.
Schema plugins allow you to extend an object with additional fields. A schema plugin adds fields in an object’s extendedFields
property.
Once added, you can read and write schema plugin fields using the object's regular endpoints, just like any other field in the object. Schema plugin fields your app can read or write to depend on the field permissions defined in the schema plugin.
Inside extendedFields
is a nested object called namespaces
. The namespaces
object contains the namespaces of any apps that extend the same API object. The schema plugin fields defined by your app are found in your app's namespace object.
For example, you could create a schema plugin for the Booking object with the namespace myApp
. This namespace will be listed in the namespaces
object. Inside the namespace are the fields you defined in your schema plugin.
A site that installs your app could install another app that also extended the Booking object. In this case, your app needs to know which fields belong to it. This is where namespaces come in. The object separates your plugin data from the other app's. It contains two separate objects in namespaces
and places your respective schema plugins in the appropriate object.
The extendedFields
object looks something like this:
When your app reads or writes to a field defined by your schema plugin, it must include your namespace in the call to access the correct field.
Note:
If a site owner has defined a schema plugin, that plugin is defined in a default namespace called user_defined
. This namespace may appear in API calls.
Here are a few possible use cases for schema plugins:
You’re not restricted to these examples. You can add a schema plugin to any object that supports it and use them in any way that you need.
Note: Only use a schema plugin when an object doesn’t have a field to support your data. Be aware that many objects contain nested fields that may already meet your app’s needs. Before creating a schema plugin, check the object to make sure you don’t add fields that already exist.
You can add a schema plugin to any object that has an extendedFields
property.