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.

Import News from an External Platform to the Staffbase Platform

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.

Prerequisites

  • 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.

Importing News Content

  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.
1export CHANNEL="5db0221d0a09a219c4ce9218"
2export AUTH="Basic TOKEN"
3
4curl "https://exampleapp.staffbase.com/api/channels/$CHANNEL/posts" \
5 -X POST \
6 -H "Authorization: $AUTH" \
7 -H "Content-Type: application/json; charset=UTF-8" \
8 -d '{
9 "contents": {
10 "en_US": {
11 "title": "Very nice title.",
12 "teaser": "Some clickbait",
13 "content": "Full HTML content."
14 }
15 },
16 "published": "true",
17 "notificationChannels": ["email", "push"]
18}' \
19 --compressed | json_pp

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

Upload News Content Images Without URL from an External Platform to the Staffbase Platform

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.

Prerequisite

  • 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.

Uploading News Content Images

  • 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.

Resend Notification to Post Published After a Specific Date

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.

Prerequisite

  • You have generated an API token with editorial access or higher via the Staffbase Studio.

Resending Notifications to News Post

  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.
1export POST="614ad94d23af1d5f9f8f5301"
2export AUTH="Basic TOKEN"
3
4curl "https://exampleapp.staffbase.com/api/posts/$POST/notifications" \
5 -X POST \
6 -H "Authorization: $AUTH" \
7 -H "Content-Type: application/json; charset=UTF-8" \
8 -d '{
9 "email": false,
10 "push": true,
11 "recipients": "unread",
12 "contents": {
13 "en_US": {
14 "text": "Custom notification text."
15 },
16 "de_DE": {
17 "text": "Angepasster Benachrichtigungstext."
18 }
19 }
20 }' \
21 --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.

Publish News Posts Associated With a Campaign

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

Prerequisite

  • You have generated an API token with editorial access or higher via the Staffbase Studio.

Publishing News Post

  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.