1. Users
  2. Write Users

Users

Write Users

Create User

POST
`/v1/users`

To create a user, you'll need to provider a name and email property. If you don't add a role, the user will be assigned the user role.

If a user is given the role of user or admin, they will also need to be given access to locations. This can be done using the locations API.

js
        const data = {
  name: "Jamie Jones",
  email: "jamie@packagex.io",
  role: "admin",
};

fetch(`https://api.packagex.io/v1/users`, {
  method: "POST",
  headers: {
    "PX-API-KEY": process.env.PX_API_KEY,
    "Content-Type": "application/json",
  },
  body: JSON.stringify(data),
});

      

Update User

POST
`/v1/users/:user`

To update a user, you'll need to pass the user's ID along with any properties that you want to manage.

js
        const data = {
  role: "developer",
};

fetch(`https://api.packagex.io/v1/users/${user.id}`, {
  method: "POST",
  headers: {
    "PX-API-KEY": process.env.PX_API_KEY,
    "Content-Type": "application/json",
  },
  body: JSON.stringify(data),
});