Apps and Users
Applications
Applications allow you to manage multiple groups of users or environments. They can be created and managed on the API dashboard.
Listing Applications
To list applications use the application list call.
The response will include a list of apps with their Application Id
, Application Key
and Name
.
{"count": 2,"next": null,"previous": null,"results": [{"id": "7084efe0-2df3-4a43-a0c4-42e68542915b","key": "8f3e07f0b78dcbee9e905162919e8f4986e7766e","name": "Testing"},{"id": "2e007f59-6d96-4faf-b817-dcd44427a103","key": "c11c85e7884de32226741cecbe029c02e5190d4a","name": "Production"}]}
Users
Users of your application are represented using the User
data model. Most of the API endpoints are accessed on behalf of a user
using a User Token
that's assigned to that user and only expose data that was submitted by that user. The API uses eating patterns
and other contextual information to personalize the suggestions and improve the accuracy of the system for each user.
Creating Users
App users can be created programmatically using two methods, client side using an Application Key or server side using an Admin Token.
Client Side Code
If you'd like to register users directly from a mobile or web application you can use the Application Key to do so. This method is ideal if you don't have a backend server for your application.
To create a user use one of the application keys and provide it as a HTTP Header to the applications_users_create operation.
The response includes the id of the user and the Bearer token which can used for other operations.
{"id": "4d09c6a2-99c5-4038-b287-b61720a5dd95","username": "leeroyjenkins","token": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}
Server Side Code
For secure server side code an admin token can be used to create users.
app = biteai.Application(app_id="[APP ID]",token="[ADMIN TOKEN]")user = app.users.create(username='leeroyjenkins')
Listing Users
To list the users of an application use the application_users_list call.
The response will contain the users with their IDs.
{"count": 1,"next": null,"previous": null,"results": [{"id": "6aeea928-3cd6-4e73-afb3-9452570b1589","username": "test_account","languages": ["en-us"],"meta": {},"time_created": "2018-03-01T19:10:48.510440Z"}]}
Managing User Tokens
Creating a new token
If a token is lost or has become compromised a new token can be created for the user by calling applications_users_tokens_create.
curl -X POST \--url https://api-beta.bite.ai/applications/7084efe0-2df3-4643-a0c4-42e68542915b/users/6feea928-3cd6-4e73-afb3-9452570b1589/tokens/
The response includes the key.
{"key": "9c0709134b5b36372e8a5a292f2d616ac979bdbe","created": "2019-03-07T22:30:48.172184Z"}
Revoking a token
A user token can be revoked by deleting it using the applications_users_tokens_delete endpoint.
curl -X DELETE \--url https://api-beta.bite.ai/applications/7084efe0-2df3-4643-a0c4-42e68542915b/users/6feea928-3cd6-4e73-afb3-9452570b1589/tokens/9c0709134b5b36372e8a5a292f2d616ac979bdbe/ \