Read
The read
method is used to one item from a Ghost Admin API resource, it is the equivalent of the GET /posts/slug/this-is-a-slug
endpoint. You have to give it an identity field to fetch the resource.
Options
Options for the read method depends on the resource you are querying. Each resource have a specific identity field that you can use to fetch it.
For example, the Post
resource will have id
and slug
as identity fields but the Member
resource will only have id
. On the other hand the User
resource will have id
, and email
as identity fields.
Use TypeScript autocomplete to guide you through the available identity fields.
Not recommended:
You can submit both id
and email
, but the fetcher will then chose the id
in priority if present to make the final URL query to the Ghost API.
The order of preference is id
> slug
> email
.
Output modifiers
After calling read
you get a Fetcher instance that you can use to optionnaly alter the output of the result with methods like include
, fields
and formats
. You can also skip that and use the fetch
method directly to get the result.
There is a section dedicated to output modifiers here.
Fetching the data
After using browse query, you will get a ReadFetcher
with an async fetch
method.
That result is a discriminated union with the Boolean success
as a discriminator, so a check on success
will let you know if the query was successful or not. Generally your workflow will look like that:
Result type of .fetch()
The data
property of the result will be an object corresponding to the resource you requested. This output schema will be modified according to the output modifiers you used.
Basic example for Post (without output modifiers you get the full Post object):