1. Organizations
  2. Create & Update Organizations

Organizations

Create & Update Organizations

Create Organization

INFO

You should only create an organization via API key if you are an enterprise customer looking to create a multi-organization setup. Please note there can be significant costs associated with this setup, so please reach out to your account manager if you are interested in this.

POST
`/v1/organizations`

Because you are already part of an organization if you are in possession of an API key, what this API does is create a new organization. This new organization's data will be completely separate from your current organization. However, billing will still be handled by your current organization.

You'll need to provide an email and name for the new user who will be the owner of this organization. This user will be able to sign into the new organization from cloud.packagex.io in the event that you need to access the dashboard. You can use the same email and name as a current user in you organization. Upon signing in, any user part of multiple organizations will be able to select which organization they want to access.

Because the organization's data is separate from your current organization, your current API key will not work for the new organization. A new API key will be generated when the organization is created. This API Key will be fully scoped for all resources but will expire in 15 minutes. You'll either need to update the expires_at property of the API Key to some date in the future or null (never expire) or use the newly generated API Key to create your own key. If the key expires, you'll need to sign into the PackageX dashboard to generate a new one, using the owner user that was added when creating the organization, or any other users you have added after that.

js
        const data = {
  user: {
    email: "jamie@packagex.io",
    name: "Jamie Jones",
  },
  organization: {
    name: "New Org Name",
    address: "500 7th Ave, New York, NY 10018",
  },
};

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

const organization = res.data.organization; //Refer to the organization model
const api_key = res.data.api_key; //Refer to the API Key model. This key will expire in 15 minutes.

      

Update Organization

POST
`/v1/organizations/:organization_id`
POST
`/v1/org`

When updating an organization, you can either user the full organization ID in proper RESTful fashion, or you can use the org shortcut since your API key is scoped to the organization anyway. Besides billing, every other property for the organization can be updated in the same structure as the model.

Any properties that have deeply nested lists with objects inside of them including settings.deliveries.rate_classes, settings.deliveries.private_rates, and settings.fulfillments.predefined_packages, have their own RESTful endpoints to make creating, updating, and deleting them easier.

js
        //Update lead time mins for a delivery and org's DBA name
const data = {
  settings: {
    deliveries: {
      lead_time_mins: 60,
    },
  },
  profile: {
    dba_name: "New DBA Name",
  },
};

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