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
- Go to API & integration.
- Select Copy in the REST API row.
- Send a GET request to
items/{model}under that address, for exampleitems/book?limit=10. The response contains anitemslist.
Create a key for writes
- Go to Settings > API keys.
- Select New API key.
- In Name, enter a name for the app or site that uses the key.
- Turn on Can also create, edit and delete to allow writes.
- Optional: Under Models, select the models the key can use. If you select none, the key can use every model.
- Select Create key.
- Select Copy key. Morphic shows the key only once.
Write an entry
- Send a POST request to
items/{model}under the same address. - Add the key in the
Authorizationheader asBearer mk_…, or in theX-Morphic-Keyheader. - Put the content in a
dataobject, 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.