How to install Beamer using our API?

When embedding our default script is not an option for your app, whether because it’s not a web app or because you prefer not to use third-party addons, you can still use our API to enable you to use Beamer.

In this guide, we’ll explain a simple implementation of Beamer in your native app using our API, by retrieving the number of unread posts and the URL of your Beamer feed to show to your users. This is probably the simplest implementation, but you can design your own and customize it all the way – just check out our API docs!

API request

To implement the case described above, you only need to make a single request to our API. For this, we are going to use the /unread/count endpoint.

Doing a GET request to /unread/count will retrieve the number of posts (matching the optional query parameters sent in the request) that your user would see when opening your Beamer feed normally. The response to this request will also include the URL of your feed, so you can send your users to it, or show it right into your app with a webview.

An example request would look something like this:

GET https://api.getbeamer.com/v0/unread/count?filter=paid-user&dateFrom=2019-01-01T00:00:00Z&userId=1234&userFirstName=John&userLastName=Doe&userEmail=john@getbeamer.com

 

In this example request, we are passing in a segment filter (‘paid-user’) through the filter parameter, in order to retrieve any posts that have the same filter -if any-, in addition to posts that don’t have any filters. This works just like the filter parameter for the embed script.

Also, we are sending in dateFrom, which will make sure only posts published from that date (2019-01-01T00:00:00Z) onwards are counted.

Keep in mind that the /unread endpoint will only count posts that are visible in your feed (draft, archived, deleted, scheduled and expired posts will not be counted here), so there’s no need to explicitly query posts by their published or archived status for example, as you would when calling the regular /posts endpoint.

Here’s what the response to that request would look like:

{

 “count”: 10,

 “url”: “https://app.getbeamer.com/news?app_id=mZXqptmd65&language=en&filterByUrl=true&role=paid-user&custom_user_id=1234&email=john%40getbeamer.com&firstname=John&lastname=Doe”

}

 

The JSON response includes two properties: count, which is the total count of unread posts matching the query, and url, which is the URL of your feed to show to your user.

An example case of using this in a native mobile app, for example, would be showing the count number over a certain button in your site (just as our embed script does), and then opening the feed URL in a webview when clicking on that button.

Android webview showing Beamer’s feed

 

Taking advantage of userId

If you are on the Pro plan and have multi-device synchronization enabled, you can skip the dateFrom parameter and just keep the userId parameter instead. This userId should be a unique identifier for your user (your own app’s user id).

When doing this, we will store the last time your user visited your Beamer’s feed, so the unread posts will only be counted from that date on – no need to explicitly send a date in the request. This is helpful if you don’t want to keep record of this date in your side, or if your users regularly enter your app from different devices.

Keeping your requests secure

If you will be doing requests from the front-end side of your app, we recommend creating and using a separate API key that has read-only permission, for obvious security reasons.

You can easily create and edit your API keys in your dashboard, right from Settings > API.