Methods
static getInBulk(client, requests)
This low level function can be used to make multiple API calls simultaneously to the backend. This is typically not meant to be used by developers directly, please consider using Collection and related functions instead
Parameters:
Name | Type | Description |
---|---|---|
client |
Client | |
requests |
Object |
- See:
-
- POST /api/v1/bulk-request API documentation for a list of parameters and fields
static getPublicPreviewStory(client, publicPreviewKey) → {Promise.<(Story|null)>}
This function can be used to fetch a draft story, given the secretKey
generated by the editor.
This function works very similar to Story.getStoryBySlug, except the fact that it accepts a secretKey.
This is the only API which will give you the latest draft / un published version of a story.
See the public preview tutorial (FIXME: Broken Link) for an a tutorial on implementation
Parameters:
Name | Type | Description |
---|---|---|
client |
Client | |
publicPreviewKey |
string |
- See:
-
- GET /api/v1/preview/story/:public-preview-key API documentation for a list of parameters and fields
static getSearch(client, params) → {Object}
This function can be used to search for stories by the given string. The returned object has a stories
property which is an array of Stories,
but also contains other fields like from
, and total
.
Example
const {stories, total} = Story.getSearch(client, {q: "Some String"});
console.log(`Total Number of Results: ${total}`);
JSON.stringify(stories.map(story => story.asJson()));
Parameters:
Name | Type | Description |
---|---|---|
client |
Client | |
params |
Object | Please see the Search API documentation for more details. |
q |
string | The search string |
- See:
-
- GET /api/v1/search API documentation for a list of parameters and fields
Please see Search API documentation for more details.
static getStories(client, storyGroup, params) → {Array.<Story>}
This function can be used to fetch stories from the old sorters API.
Example
const stories = await Story.getStories(client, 'top', {'section-id': 42});
console.log(stories[0].headline)
console.log(JSON.stringify(stories.map(s => s.asJson())))
Parameters:
Name | Type | Description |
---|---|---|
client |
Client | |
storyGroup |
string | |
params |
Object |
- Deprecated:
- Please use Collection and related functions instead
- See:
-
- GET /api/v1/stories API Documentation for a list of parameters accepted and fields returned
static getStoryByExternalId(client, externalId) → {Promise.<(Story|null)>}
This function can be used to fetch a story given an external id. This is typically done on story pages.
This returned promise will resolve to null if the story is not found
Example
const story = await Story.getStoryByExternalId(client, externalId);
if(!story) {
render404();
} else {
renderTheStoryPage(story);
}
Parameters:
Name | Type | Description |
---|---|---|
client |
Client | |
externalId |
string | The external id of the story. |
static getStoryById(client, id) → {Promise.<(Story|null)>}
This function can be used to fetch a story, given the id.
This function works very similar to Story.getStoryBySlug, except the fact that it accepts a id
Parameters:
Name | Type | Description |
---|---|---|
client |
Client | |
id |
string |
- See:
-
- GET /api/v1/preview/stories/:story-id API documentation for a list of parameters and fields
static getStoryBySlug(client, slug, params) → {Promise.<(Story|null)>}
This function can be used to fetch a story given a slug. This is typically done on story pages.
This returned promise will resolve to null if the story is not found
Example
const story = await Story.getStoryBySlug(client, slug);
if(!story) {
render404();
} else {
renderTheStoryPage(story);
}
Parameters:
Name | Type | Description |
---|---|---|
client |
Client | |
slug |
string | The slug of the story. |
params |
Object | Parameters that are passed directly as query paremeters to the API |
- See:
-
- GET /api/v1/stories-by-slug API documentation for a list of parameters and fields
asJson()
Use this to convert to a simple javascript object, suitable for JSON.
getRelatedStories(client) → {Array.<Story>}
This method can be used to fetch stories related to a given story
Example
const story = await Story.getStoryBySlug(client, "some-slug");
const relatedStories = await story.getRelatedStories(client);
Parameters:
Name | Type | Description |
---|---|---|
client |
Client |
- See:
-
- GET /api/v1/stories/:story-id/related-stories API Documentation for a list of fields returned
getStoryAttributes(client) → {Object}
This method can be used to get various metadata for the given story. Apart from story related attributes, this API will also return all collections this story is a part of, along with collection metadata.
Parameters:
Name | Type | Description |
---|---|---|
client |
Client |
- See:
-
- GET /api/v1/stories/:story-id/attributes API Documentation for a list of fields returned
Please see API documentation for more details