News API Use Cases

Explore News API use case scenarios for your organization.

The News API gives you a lot of flexibility in how you create and manage your news content. Be that for integrating news content between the Staffbase platform and external platforms or improving efficiencies. All News API specifications are listed here.

In this article, let’s look at the everyday business use cases for the News API in your organization. The following is not an exhaustive list of use cases for the News API.

With the Staffbase News API, you can import all the news content created in any platform you use to your Staffbase platform. Import the content to a specific news channel in the Staffbase platform and publish it immediately or schedule it to be published later. Importing news content from an external platform to the Staffbase platform can be helpful in many cases.
For example:

  • To migrate all the content created in an external platform to the Staffbase platform
  • To ensure that the content is accessible to your users on both platforms
  • To build sync between the two platforms and provide a seamless flow of content

    For syncing content, you need to create additional middleware between the two platforms.

  • You have generated an API token with editorial access or higher via the Staffbase Studio.
  • Ensure that the video or image content in your news content has a URL. If not, you need to upload the video or image content to the platform via Media API before proceeding with the News API. Learn more about it here.
  1. From the Staffbase Studio, obtain the channel ID for the news channel to which you want to import the news. Learn more about it here.
  2. Make a POST request to endpoint /channels/{channelID}/posts to add a news post to the channel you want.
Terminal window
export CHANNEL="5db0221d0a09a219c4ce9218"
export AUTH="Basic TOKEN"
curl "https://exampleapp.staffbase.com/api/channels/$CHANNEL/posts" \
-X POST \
-H "Authorization: $AUTH" \
-H "Content-Type: application/json; charset=UTF-8" \
-d '{
"contents": {
"en_US": {
"title": "Very nice title.",
"teaser": "Some clickbait",
"content": "Full HTML content."
}
},
"published": "true",
"notificationChannels": ["email", "push"]
}' \
--compressed | json_pp

You can set up an automation to import the news content on a regular basis.

When importing news content from an external platform to the Staffbase platform using the POST request to the News API, you need to provide the URL of the video or image displayed along with the teaser. If the image or video file in the content does not have a URL, you can upload the file first using the Media API.

  • You have generated an API token with editorial access or higher via the Staffbase Studio.
    Reuse the API token you generated for importing news to the Staffbase platform.
  • Make a POST request to the endpoint /media to upload the file. Learn more about it here.

Once you have uploaded the image or video file using the Media API, you will get the URL to the uploaded file in the response sample. Use the URL when importing the news content from an external platform to the Staffbase Platform.

You want to resend the notification to HR-related posts published in the previous month to all the employees who have not read the post.

  • You have generated an API token with editorial access or higher via the Staffbase Studio.
  1. From the Staffbase Studio, obtain the channel ID for the news channel where HR-related posts are published. Learn more about it here.
  2. Make a GET request to the endpoint /posts to list all posts in the channel by providing the channelID. Learn more about it here.
  3. From the response list you got, filter for the posts that fall into the time frame you want.
  4. Get the list of the postIDs for the posts in the time frame.
  5. Make a POST request to the endpoint /posts/{postID}/notifications to resend notifications to all employees who have not read the post. In the request body schema, set the recipients parameter to unread.
Terminal window
export POST="614ad94d23af1d5f9f8f5301"
export AUTH="Basic TOKEN"
curl "https://exampleapp.staffbase.com/api/posts/$POST/notifications" \
-X POST \
-H "Authorization: $AUTH" \
-H "Content-Type: application/json; charset=UTF-8" \
-d '{
"email": false,
"push": true,
"recipients": "unread",
"contents": {
"en_US": {
"text": "Custom notification text."
},
"de_DE": {
"text": "Angepasster Benachrichtigungstext."
}
}
}' \
--compressed | json_pp

To resend the notifications to all users instead of users who have not yet read the post, set the recipients parameter to all.

You can manage your Campaigns with greater ease with the Staffbase APIs. Let’s look at how to assign news posts to a campaign.

  • You have generated an API token with editorial access or higher via the Staffbase Studio.
  1. Make a GET request to the endpoint /campaigns to list all campaigns. Learn more about it here.
  2. Get the campaignID for which you want to assign a post.
  3. Make a PUT request to the endpoint /posts/{postID} and in the request body schema, provide the value for the parameter campaignID. Learn more about it here.