Help topics

Read and write content with the REST API

Read a model's entries with one request, then create an entry with one authenticated request. Both steps use the REST API address that Morphic shows on the API & integration screen.

Before you start

  • You need a model that anonymous visitors can read. In the model's Access tab, set See entries to Everyone.
  • To create the key for the write step, you need the administrator role.

Steps

The read needs no key, so it comes first. Create a key only for the write.

Read an entry

  1. Go to API & integration.
  2. Select Copy in the REST API row.
  3. Send a GET request to items/{model} under that address, for example items/book?limit=10. The response contains an items list.

Create a key for writes

  1. Go to Settings > API keys.
  2. Select New API key.
  3. In Name, enter a name for the app or site that uses the key.
  4. Turn on Can also create, edit and delete to allow writes.
  5. Optional: Under Models, select the models the key can use. If you select none, the key can use every model.
  6. Select Create key.
  7. Select Copy key. Morphic shows the key only once.

Write an entry

  1. Send a POST request to items/{model} under the same address.
  2. Add the key in the Authorization header as Bearer mk_…, or in the X-Morphic-Key header.
  3. Put the content in a data object, for example {"data": {"title": "The Hobbit"}}.

Result

The read returns HTTP 200 with the items list. The write returns HTTP 201 with the new entry, including its id and rev. Without a key, the same write returns HTTP 403 with the message you may not create book.