SDK API specs
Last updated
Last updated
PushExpress -- SDK and application instances API reference
Version date: 05 Feb 2024
Clients (app developers) MUST do some initialization in application code (see ).
Usually, they should provide app_id
(which MUST be stored in app local storage) and SDK flow activation flag
(just in-memory flag).
If no valid app_id
found, or SDK flow is not activated by developer, further steps SHALL NOT be done.
ic_token
)Clients need to have some independent globally-unique installation id, even if no internet access available.
This id often used in multiple ad-platforms, and very useful for clients who do not have their own user base with their own ids.
We suggest to use UUIDv4 or UUIDv7 as easily accessible on any modern programming languages.
Of course, clients can generate and store this ID on their own, but it is more convenient to do this at the SDK level.
So, you need:
Generate UUIDv4 (or UUIDv7) to use as ic_token
Store ic_token
in local storage.
Access some variable from app persistent local storage, for example ic_id
(PushExpress App Instance Id).
If non-nil and non-empty variable found, assume it is existing install and go to section 1.3.
Else, do the following steps:
In case of any error (non-200 response or invalid response object), retry infinitely with exponential backoff algorithm, better with random initial value between 1-5s, capped at maximum delay of about 120s
Store aquired ic_id
in local storage. Storage MUST be resistant to app updates and MUST be cleared on app removal. Storage SHOULD not overlap with existing app storages (for use as library). If it is not possible, use a more distinguishable field name (px_ic_id
)
Go to section 2.
As soon as possible after app startup issue first update app info request as described in section 2.
Periodically update app info with received update_interval_sec
interval.
Gather some device and app info params like FCM token, country, language, timezone, app onscreen count and time, etc
In case of any error (non-200 response or invalid response object), retry infinitely with exponential backoff algorithm, better with random initial value between 1-5s, capped at maximum delay of about 120s
Note: it's better to update current app state (on screen/background) and send actual onscreen_count
and onscreen_sec
.
Subscribe for transport channel (for example, Firebase Cloud Messaging).
Notification MUST be displayed with title, body, image and icon, based on standard Firebase notification
fields. Or manually by corresponding px.*
fields in data
.
FCM transport message format:
Below is an example of Kotlin SDK interface:
Request:
Body params:
ic_token
, required. Globally unique, local-generated app instance installation token, as described in section 1.1.
ext_id
, optional. External id (for login/logout functionality).
Response:
200: New app instance created
id
, string. Created app instance id (use as :ic_id
in update info requests)
just_created
, bool. Logged in to existing instance (via ext_id
) or created new device.
Request:
Body params:
transport_type
, required. Push transport type. One of fcm
, onesignal
, huawei
, apns
transport_token
, optional. transport_type
specific token for receiving push
platform_type
, required. Notification rendering platform. One of android
, ios
, browser
platform_name
, optional. Readable platform name and version, like, android_api_33
or chrome_118
country
, recommended. Sim card, locale or some other platform-based country code.
Accepts ISO3166-1, alpha-2 country code.
MUST NOT be determined by current network IP, better send nothing!
Example (don't forget to check exceptions and return empty string on any):
lang
, highly recommended. Platform-based language. Accepts BCP 47 language tag
Example: Locale.getDefault().language
tz_sec
, recommended. Platform timezone east-shift from UTC-0, in seconds, like 3600
, or -7200
. Example: TimeZone.getDefault().rawOffset / 1000
tags
, optional. User-specified string tags, map of strings with string keys. Predefined tag names: ad_id
, offer
, webmaster
onscreen_count
, optional. How many times app was opened and showed on screen (how many times the app was used)
onscreen_sec
, optional. How many seconds app was on screen (how much time the app was used)
agent_name
, recommended. Client agent (or SDK) name and version, like my_sdk_0.0.0
Response:
200: App instance info updated
id
, string. App instance id
update_interval_sec
, int. Interval for sending update info requests in case of success
Request:
Body params:
msg_id
, required. Message id (for FCM transport, get from px.msg_id
data filed)
event
, required. Event name, one of:
delivered
-- if possible, send after the notification has been successfully displayed to the user. Else, after the push message has been received from transport. Or do not send at all on any difficulties
clicked
-- MUST be sent after the user clicks on the notification
Response:
202 Accepted, with no content type and empty body
Request:
Body params:
event
, required. Event name, one of:
onscreen
-- app opened (appeared on the screen)
background
-- app gone to background (disappeared from screen)
closed
-- app closed (if can be detected)
Response:
202 Accepted, with no content type and empty body
All HTTP response codes above 400 MUST be considered as error.
In general, errors do not require attention and do not need to be handled in any way.
There are two types of errors.
Backend errors, will always have content-type: application/json
header and json response body
Example: {"message": "validation error: ..."}
Other errors from proxy servers, load balancers, etc. There may or may not be some explanation in response body.
Example: HTTP 504 Gateway Timeout, with empty response body
Get ic_id
as specified here:
Issue request (only some fields are required, other can be updated later)
Repeat request with received update_interval_sec
interval
Incoming message id MUST be registered by extracting data field px.msg_id
and in clicked
event.
After notification has been displayed, delivered
event . If not possible to detect displaying, send it after FCM message has been received.
Application startups and screen time SHOULD be tracked and saved in local storage, for sending correct onscreen_count
and onscreen_sec
fields in request.
App MAY be sent when app is shown on screen or goes to background.