If you prefer a typed experience over calling http endpoints directly, you can use our sdk @mobilizehub/api.

npm install @mobilizehub/api

The SDK uses the same authentication and authorization as the API, so you can use it in the same way as you would use the API. The same HTTP RPC-style methods are available as the API, so you can use the SDK to create, update, delete and list resources.

MobilizeHub API Key

When creating, revoking or updating resources, you will need your api key — you can create a new one in the settings of your organization under API Keys. Afterwards you need to provide it to the client:

import { MobilizeHub } from "@mobilizehub/api";

const mobilizehub = new MobilizeHub({ apiKey: "<MOBILIZEHUB_API_KEY>" });

Always keep your api key safe and reset it if you suspect it has been compromised.

Response format

Every method returns either an error or a result field, never both and never none. Errors are explicitly returned to be handled is typesafe.

{
  result: T // the result depends on what method you called
}

Checking for errors

To check for errors you use the error property, our errors are easy to read and provide a link to our documentation for more information.

import { MobilizeHub } from "@mobilizehub/api";

const mobilizehub = new MobilizeHub({ apiKey: "<MOBILIZEHUB_API_KEY>" });

const { result, error } = await mobilizehub.contact.create({
    email: "ryan@mobilizehub.com",
    orgId: "org_1234567890",
});

if (error) {
  // handle potential network or bad request error
  // a link to our docs will be in the `error.docs` field
  console.error(error.message);
  return;
}

// process request
console.log(result);

Retries

By default the client will retry on network errors, you can customize this behavior:

const mobilizehub = new MobilizeHub({
  // ...
  retry: {
    attempts: 3,
    backoff: (retryCount) => retryCount * 1000
  }
})