Reuse our custom structure across another item

Overview

In the previous guide we created an item with structure. This item used a custom structure which cannot be reused on other items.

In this guide we'll save the custom structure we created in the previous guide as a template. This will allow us to reuse it when we create another item.

Saving the custom structure as a reusable template

We can use the save structure as template endpoint to give us a reusable template.

We'll use the structure_uuid of the custom structure we created in the URL.

curl --request POST \
     --url https://api.gathercontent.com/structures/b5868741-c574-4482-91ee-d10003114954/save_as_template \
     --header 'Accept: application/vnd.gathercontent.v2+json' \
     --header 'Authorization: Basic PDx1c2VyPj46PDxwYXNzPj4=' \
     --header 'Content-Type: application/json'
     --data='{"name": "Course Page"}'

// Response
{
  "data":{
    "id":54321 // ID associated with the template created
    "name":"Course page", 
    "number_of_items_using":1
    "structure_uuid":"b5868741-c574-4482-91ee-d10003114954", // the custom structure UUID is now associated with the template
    "project_id":67890,
    "updated_at":"2021-07-07 20:00:00",
    "updated_by":123
	}
}

Reusing the template on another item

Now that we have saved the custom structure as a template we can reuse it on items we create, they will inherit the template and therefore it's structure, groups and fields.

curl --request POST \
     --url https://api.gathercontent.com/projects/67890/items \
     --header 'Accept: application/vnd.gathercontent.v2+json' \
     --header 'Authorization: Basic PDx1c2VyPj46PDxwYXNzPj4=' \
     --header 'Content-Type: application/json'
      --data '
{
	"name": "Physiotherapy BSc",
  "status_id": 12345,
  "folder_uuid": "b5868741-c574-4482-91ee-d10003114954", 
  "position": 0,
  "template_id": 54321
}

In the next section, we'll add content to our items through the update item content endpoint.