List collections
Our first method, listCollections
, is used to fetch and return the list of collections for an authorized site using the list collections endpoint. It expects a siteId
as a URL parameter, which our frontend should send in the request. If successful, it will respond with a JSON object containing the list of collections.
Get collection details
Get collection details will get the details of a single collection using the get collection endpoint. It expects a collectionId
as a URL parameter, which our frontend should send in the request. If successful, it will respond with a JSON object with additional details about the collection, most importantly the fields
array which contains the schema, or the fields that belong to the collection.
Create fields
This is a helper function that creates multiple fields for a given collection using the create fields endpoint. In our frontend we've created a list of preset collections in CollectionPresets.js
. Each preset has a collection
object that contains the collection details, as well as a list of fields that each have their own name
, type
, and other properties.
This helper function expects a collectionId
and a list of fields, and will create each field for the given collection. So we must first create the collection, and then use the collectionId
to create the fields.
Create a collection with fields
This is the main function that creates a collection and the corresponding fields. It expects a siteId
, as well as a collection
object that contains the collection details and a list of fields from a selected preset from CollectionPresets.js
.
It will first create the collection using the create collection endpoint, then use the helper function createFields
to create multiple fields. Finally, it will respond with the results of each successful field creation.
Delete a collection
This function deletes a collection using the delete collection endpoint. It expects a collectionId
as a URL parameter, which our frontend should send in the request. The delete endpoint does not return any data, so we will just respond with a status of 200.
List collections
Our first method, listCollections
, is used to fetch and return the list of collections for an authorized site using the list collections endpoint. It expects a siteId
as a URL parameter, which our frontend should send in the request. If successful, it will respond with a JSON object containing the list of collections.
Get collection details
Get collection details will get the details of a single collection using the get collection endpoint. It expects a collectionId
as a URL parameter, which our frontend should send in the request. If successful, it will respond with a JSON object with additional details about the collection, most importantly the fields
array which contains the schema, or the fields that belong to the collection.
Create fields
This is a helper function that creates multiple fields for a given collection using the create fields endpoint. In our frontend we've created a list of preset collections in CollectionPresets.js
. Each preset has a collection
object that contains the collection details, as well as a list of fields that each have their own name
, type
, and other properties.
This helper function expects a collectionId
and a list of fields, and will create each field for the given collection. So we must first create the collection, and then use the collectionId
to create the fields.
Create a collection with fields
This is the main function that creates a collection and the corresponding fields. It expects a siteId
, as well as a collection
object that contains the collection details and a list of fields from a selected preset from CollectionPresets.js
.
It will first create the collection using the create collection endpoint, then use the helper function createFields
to create multiple fields. Finally, it will respond with the results of each successful field creation.
Delete a collection
This function deletes a collection using the delete collection endpoint. It expects a collectionId
as a URL parameter, which our frontend should send in the request. The delete endpoint does not return any data, so we will just respond with a status of 200.