Skip to main content

Users

Basic concepts#

The project API provides users resource out of the box.
This includes all CRUD actions on users like a regular API resource and also the endpoint for authentication.

Registering/Creating users#

POST https://{app-id}.essentialz.cloud/users

User registration/creation is very simple. You should just make a POST request to /users with three parameters email, password and provider. Provider is always equal to email. Example request could look like this:

User registration/creation request
const myHeaders = new Headers();
myHeaders.append("Content-Type", "application/json");
const raw = JSON.stringify({
email: "user@demo.com",
password: "strongPassWord",
provider: "email",
});
const requestOptions = {
method: "POST",
headers: myHeaders,
body: raw,
redirect: "follow",
};
fetch("https://your_app_id.essentialz.cloud/users", requestOptions)
.then((response) => response.text())
.then((result) => console.log(result))
.catch((error) => console.log("error", error));

After successful registration/creation you will receive response object that look like this:

User registration/creation response
{
"id": "9f9aad9d-180a-4706-af97-21f539671be8",
"email": "user@demo.com",
"apple_id": null,
"google_id": null,
"facebook_id": null,
"role": "regular",
"active": true,
"details": {},
"created_at": "2021-09-28 10:17:57 UTC",
"updated_at": "2021-09-28 10:17:57 UTC",
"authorization": {
"token": "eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJmMGRiYmNmMi1jZDY4LTQxNDctYjE5Zi0zZjRjZjNlZTNhNjkiLCJpYXQiOjE2MzI4MjQyNzd9.bmhPUQEHY4fxagYJJieQ-nlBmwow2crcWMkesJuuh-k"
}
}

Get all users#

GET https://{app-id}.essentialz.cloud/users

To get all users you should make a GET request to /users. Basic example using fetch:

Get users
const requestOptions = {
method: "GET",
redirect: "follow",
};
fetch("https://your_app_id.essentialz.cloud/users", requestOptions)
.then((response) => response.text())
.then((result) => console.log(result))
.catch((error) => console.log("error", error));

Response is an array of user objects:

[
{
"id": "XXX-XXX-XXXX-XXXX-XXXXXX",
"email": "user@demo.com",
"apple_id": null,
"google_id": null,
"facebook_id": null,
"role": "regular",
"active": true,
"details": {},
"created_at": "2021-08-12 10:17:48 UTC",
"updated_at": "2021-08-12 10:17:48 UTC"
},
{
"id": "XXX-XXX-XXXX-XXXX-XXXXXX",
"email": "user2@demo.com",
"apple_id": null,
...

Get user#

GET https://{app-id}.essentialz.cloud/users/{user-id}

To get user you should make GET request to /users/{user-id} where user-id is a value of user object id property. Using fetch request can look like this (don't forget to add {authorization : Bearer XXXXX} header, where XXXXX is your token):

Get user
const myHeaders = new Headers();
myHeaders.append(
"authorization",
"Bearer eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiI5ZjlhYWQ5ZC0xODBhLTQ3MDYtYWY5Ny0yMWY1Mzk2NzFiZTgiLCJpYXQiOjE2MzI3NjE2ODF9.gUHQf55wMmV7cKFR_M7JCAZ-IkfbWETGLSBbE4VRDhs",
);
myHeaders.append("content-type", "application/json");
const requestOptions = {
method: "GET",
headers: myHeaders,
redirect: "follow",
};
fetch("https://your_app_id.essentialz.cloud/users/9f9aad9d-180a-4706-af97-21f539671be8", requestOptions)
.then((response) => response.text())
.then((result) => console.log(result))
.catch((error) => console.log("error", error));

Response has following fields:

Get user response
{
"id": "9f9aad9d-180a-4706-af97-21f539671be8",
"email": "user@demo.com",
"apple_id": null,
"google_id": null,
"facebook_id": null,
"role": "regular",
"active": true,
"details": {},
"created_at": "2021-08-12 10:17:48 UTC",
"updated_at": "2021-08-12 10:17:48 UTC"
}

Update users#

PUT https://{app-id}.essentialz.cloud/users/{user-id}

To update user you should send a PUT request to /users/{user-id} where user-id is a value of user object id property. Request body should have everything you want to update about user. For example if you want to update user details object with his new address you could write, using fetch:

Update user request
const myHeaders = new Headers();
myHeaders.append("content-type", "application/json");
myHeaders.append(
"Authorization",
" Bearer eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiI5ZjlhYWQ5ZC0xODBhLTQ3MDYtYWY5Ny0yMWY1Mzk2NzFiZTgiLCJpYXQiOjE2MzI3NjE2ODF9.gUHQf55wMmV7cKFR_M7JCAZ-IkfbWETGLSBbE4VRDhs",
);
const raw = JSON.stringify({
details: {
city: "Belgrade",
address: "Neznanog junaka 33",
apartment: 34,
},
});
const requestOptions = {
method: "PUT",
headers: myHeaders,
body: raw,
redirect: "follow",
};
fetch("https://your_app_id.essentialz.cloud/users/9f9aad9d-180a-4706-af97-21f539671be8", requestOptions)
.then((response) => response.text())
.then((result) => console.log(result))
.catch((error) => console.log("error", error));

As a response you will receive user object with updated properties.

Update user response
{
"id": "9f9aad9d-180a-4706-af97-21f539671be8",
"email": "nikola@essentialz.io",
"apple_id": null,
"google_id": null,
"facebook_id": null,
"role": "regular",
"active": true,
"details": {
"city": "Belgrade",
"address": "Neznanog junaka 33",
"apartment": 34
},
"created_at": "2021-08-12 10:17:48 UTC",
"updated_at": "2021-09-28 12:40:01 UTC"
}

Deleting users#

DELETE https://{app-id}.essentialz.cloud/users/{user-id}

If you want to delete a user you should send DELETE request at /users/{user-id} where user-id is a value of user object id property. An example request using fetch:

Delete user request
const myHeaders = new Headers();
myHeaders.append(
"authorization",
"Bearer eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiI5ZjlhYWQ5ZC0xODBhLTQ3MDYtYWY5Ny0yMWY1Mzk2NzFiZTgiLCJpYXQiOjE2MzI3NjE2ODF9.gUHQf55wMmV7cKFR_M7JCAZ-IkfbWETGLSBbE4VRDhs",
);
myHeaders.append("content-type", "application/json");
const requestOptions = {
method: "DELETE",
headers: myHeaders,
redirect: "follow",
};
fetch("https://your_app_id.essentialz.cloud/users/<id>", requestOptions)
.then((response) => response.text())
.then((result) => console.log(result))
.catch((error) => console.log("error", error));
As a response you should receive empty object.
Delete user response
{}