Skip to main content

Creating a User Management Service

A User Management Service is a simple service which exposes CRUD APIs for user management. Bharat SahAIyak platform is able to seamlessly integrate with any User Management Service as long as it follows the following spec and exposes the following APIs.

Registering a User

POST
/register/{deviceId} Register a user given a `deviceId`.

Url Parameters

NameTypeRequiredDescription
deviceIdStringYESThe unique device Id of the user which an adapter uses to send messages.

Request Body

NameTypeRequiredDescription
verificationIdStringYESThe verification Id that the user provides, which can be used to verify the user. For example email, phone number, etc.

Response

Success (201)
Return a 201 response code if the user registration request has been successfully made.
Conflict (409)
Return a 409 response if a user already exists with the same `deviceId` or `verificationId`.
Failure Response (any other code)
Return the corresponding error code with relevant error message.
{
"error": "This went wrong",
}

Fetching Users

GET
/ Fetch all users in segment.

Query Parameters

NameTypeRequiredDescription
pagenumberNOThe page number of the user segment being retrieved in a paginated query. All users are returned by default if page is not provided.
sizenumberNOThe size of the page being retrieved in a paginated query. By default this value if 10.

Response

The service must respond with a 200 status code for a successfull call, or else provide the corresponding error code along with an error message.
Success Response (200)
[
{
"name": "abc",
"deviceId": "xyz",
"verificationId": "aaa",
},
{
"name": "aac",
"deviceId": "yyz",
"verificationId": "abb",
},
...
]
Failure Response (other than 200)
{
"error": "This went wrong",
}

Fetching Single User

GET
/{deviceId} Fetch user based on `deviceId`.

Url Parameters

NameTypeRequiredDescription
deviceIdStringYESThe unique device Id of the user which an adapter uses to send messages.

Response

Success (200)
Return a 200 response code if the user is found.
{
"name": "abc",
"deviceId": "xyz",
"verificationId": "aaa",
}
Not Found (404)
Return a 404 response if a user is not registered to the segment.
Failure Response (any other code)
Return the corresponding error code with relevant error message.
{
"error": "This went wrong",
}

Deleting a registration

DELETE
/{deviceId} Delete a user registration based on `deviceId`.

Url Parameters

NameTypeRequiredDescription
deviceIdStringYESThe unique device Id of the user which an adapter uses to send messages.

Response

Success (200)
Return a 200 response code if the user registration is deleted successfully.
Not Found (404)
Return a 404 response if a user is not registered to the segment.
Failure Response (any other code)
Return the corresponding error code with relevant error message.
{
"error": "This went wrong",
}

Updating deviceId of a given user

PATCH
/{verificationId} Update a user registration based on `verificationId`.

Url Parameters

NameTypeRequiredDescription
verificationIdStringYESThe unique verification Id of the user which was used to verify the user during registration.

Request Body

NameTypeRequiredDescription
deviceIdStringYESThe unique device Id of the user which an adapter uses to send messages.

Response

Success (200)
Return a 200 response code if the user registration was successfully updated.
Not Found (404)
Return a 404 response if a user is not registered to the segment.
Failure Response (any other code)
Return the corresponding error code with relevant error message.
{
"error": "This went wrong",
}

How to use User Management Service

Once the User Management Service is up and running with the given spec, the only thing required to do is to add the BASE_URL of your service to the url property of the UserSegment while creating a UserSegment.