1. Users
  2. Write Users

Users

Write Users

Create User

POST
`/v1/users`

Required Properties

  1. name
  2. email

Additionally, you can include the following optional properties:

  1. role or role_id: The role to assign to the user. If not provided, the user will be assigned the default role specified in the organization's settings.
  2. developer_mode: A boolean value indicating whether the user has developer mode enabled.
  3. dark_mode: A boolean value indicating whether the user has dark mode enabled on PackageX Dashboard.
  4. show_dock: A boolean value indicating whether the user has the dock visible in the PackageX Dashboard.
  5. phone: The user's phone number. If provided, it will be parsed into a standardized format.
  6. onboarded_apps: An array of app IDs that the user has access to on the PackageX Dashboard.
  7. fcm_token: An array of Firebase Cloud Messaging tokens for the user's push notifications on PackageX Apps.

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

Example Request

js
        const data = {
  email: "jamie@packagex.io",
  name: "Jamie Jones",
  role: "admin",
  phone: "+1-555-123-4567",
};

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),
})
  .then(response => response.json());

      

Update User

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

POST
`/v1/users/:user`

Request Body

The request body should be a JSON object containing the properties you want to update. The following properties can be updated:

  1. name: The user's full name.
  2. email: The user's email address.
  3. role or role_id: The role to assign to the user. If not provided, the user will be assigned the default role specified in the organization's settings.
  4. developer_mode: A boolean value indicating whether the user has developer mode enabled.
  5. dark_mode: A boolean value indicating whether the user has dark mode enabled on PackageX Dashboard.
  6. show_dock: A boolean value indicating whether the user has the dock visible in the PackageX Dashboard.
  7. phone: The user's phone number. If provided, it will be parsed into a standardized format.
  8. onboarded_apps: An array of app IDs that the user has access to on the PackageX Dashboard.
  9. fcm_token: An array of Firebase Cloud Messaging tokens for the user's push notifications on PackageX Apps.
  10. metadata: Additional metadata to associate with the user's profile.
  11. notification_events: An array of notification events the user wants to update.

Example Request

js
        const data = {
  name: 'John Doe',
  email: 'john@example.com',
  role: 'developer',
  developer_mode: true,
  phone: '+1-555-123-4567',
  onboarded_apps: 'app_789',
  metadata: {
    custom_field: 'value'
  },
  notification_events: ['user.created', 'order.shipped']
};

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),
})
  .then(response => response.json());

      

Update User Locations

To update the locations associated with a user, send a POST request with the ID of the user you want to update. Include the location IDs to add or remove in the request body.

POST
`/v1/users/:user/locations`

Request Body

The request body should be a JSON object containing the following properties:

  1. add (string or array of strings): The location ID(s) to add to the user. You can provide a single location ID as a string or multiple location IDs as an array of strings.
  2. remove (string or array of strings): The location ID(s) to remove from the user. You can provide a single location ID as a string or multiple location IDs as an array of strings.

Example Request

js
        const data = {
  add: ['loc_456', 'loc_789'],
  remove: ['loc_012']
};

fetch(`https://api.packagex.io/v1/users/${userId}/locations`, {
  method: 'POST',
  headers: {
    'PX-API-KEY': process.env.PX_API_KEY,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify(data),
})
  .then(response => response.json());