1. API Keys
  2. Write API Keys

API Keys

Write API Keys

Create API Key

POST
`/v1/api-keys`

When an API Key is created, the full key will be shown only on that first response in a property called api_key.

You can provide a name for your API Key if you would like. When adding scopes, you can either use integers or "read" and "write" strings.

Remember, you can only add scopes to an API Key, if the current API Key you are using also has those scopes.

js
        const data = {
  name: "My First API Key",
  scopes: {
    items: 1 //read scopes
    shipments: 2 //write scopes,
    fulfillments: null //remove scopes
  }
  //Set an expiration date for the API key.
  //This is optional and default to null, which means the API key will never expire.
  //You can pass in ISO 8601 date string, a JS Date object, or a timestamp in epoch seconds or milliseconds.
  expires_at: new Date(Date.now() + 1000 * 60 * 60 * 24 * 30)
};

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

const key = res.data.api_key;

      

Update API Key

POST
`/v1/api-keys/:api-key`

You can update the name and scopes of your API Key.

js
        const data = {
  name: "Updated name",
  scopes: {
    items: "write" //you can use string if you want
    shipments: "read"
    fulfillments: null
  }
};

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