πŸŽ‰ 1Flow is proudly backed by Y Combinator.
logo

Introduction

Our APIs allow you to track events happening on the server-side. Please only use server-side APIs for tracking events that happen outside of your client application.
πŸ’‘
Events tracked using our API cannot trigger surveys. They are used only to record these events and can be used to define target audience for surveys. Whenever possible, please track events on the frontend instead of using this API system.

Overview

To track events on the server-side, there are two steps:
  • Create user session
  • Track event
Both steps are necessary in order to track events.

Step 1: Create or Get User

To track new events, you first need to create or get user using the below API call. This API will return the user’s identifier and session id info necessary to make a log Event call.
  • If the user with the given user_id does not already exist, the API takes care of creating a new user and then returning the user info.
  • If the user already exists, no new user will be created, only the required info will be returned.
API URL:
plain text
https://us-west-2.aws.webhooks.mongodb-realm.com/api/client/v2.0/app/1flow-wslxs/service/HTTP-SDK-REQUEST/incoming_webhook/project-user
API METHOD: POST
Header: Pass in your project API key in the one_flow_key field.
Body:
Field
Type
Description
user_id
STRING
User id is the user unique identifier. A userId is required.
anonymous
BOOLEAN
Anonymous will define your user will be a real user or an anonymous user. An anonymous is required.
custom_parameters
OBJECT
Custom parameter is the user-related parameter that you want to along with the user. This field is optional.
Example Request:
plain text
curl --location --request POST 'https://us-west-2.aws.webhooks.mongodb-realm.com/api/client/v2.0/app/1flow-wslxs/service/HTTP-SDK-REQUEST/incoming_webhook/create-project-user' \ --header 'one_flow_key: oneflow_prod_9YUUTdWrIN7ErCQ/70hTLVeQxnOcAynSBR/sCu9qvgRIFM9yagPM3AAjBNOwudNIFNm3oOr9epnWBIZ8tWiyHA==' \ --data-raw '{ "user_id":"http_request_2", "anonymous":true, "custom_parameters":{ "email":"new@gmailcom" } }'
Example Response:
json
{ "success": 200, "message": "User founds", "result": { "user_id": "62501678fc4d94fdd9203b08", "session_id": "62501680884d278ce64556f6" } }
Now after getting the user_id and session_id, you are ready to track events.
πŸ’‘
Once you get the user_id and session_id for a user, you can optionally save it in your database so next time an event happens for the same user, you won’t need to call Get User API again. (Every time you make a call to Get User, it creates a new session_id)

Step 2: Track Event

API URL:
plain text
https://us-west-2.aws.webhooks.mongodb-realm.com/api/client/v2.0/app/1flow-wslxs/service/HTTP-SDK-REQUEST/incoming_webhook/add-event
API METHOD: POST
Header: Pass in your project API key in the one_flow_key field.
Body:
Field
Type
Description
user_id
STRING
user_id identifies the user with which this event should be associated. An user_id is required
session_id
STRING
Session id is the current analytic_user_id session . A session is required
event
OBJECT
The event object contains current event details. An event is required. Event object contains two fields: name and parameters
name
STRING
Event name, required.
parameters
OBJECT
Parameter contains the event parameters which you want to pass along with the event. A parameters is optional.
Example Request
plain text
curl --location --request POST 'https://us-west-2.aws.webhooks.mongodb-realm.com/api/client/v2.0/app/1flow-wslxs/service/HTTP-SDK-REQUEST/incoming_webhook/add-event' \ --header 'one_flow_key: oneflow_prod_9YUUTdWrIN7ErCQ/70hTLVeQxnOcAynSBR/sCu9qvgRIFM9yagPM3AAjBNOwudNIFNm3oOr9epnWBIZ8tWiyHA==' \ --data-raw '{ "user_id":"62501678fc4d94fdd9203b08", "session_id":"62501680884d278ce64556f6", "event":{ "name":"payment_done", "parameters":{ "payment_id":"pub_12332", "product_id":"pb_jscdjkdosj23" } } }'
Example Response
plain text
{ "success": 200, "message": "Event added", "result": { "insertedEvent": { "insertedId": "6251416d3860de9df1224407" } } }

Helpful?