When creating, revoking or updating resources, you will need your api key — you can create a new one in the settings of your project.
Afterwards you need to provide it to the client:
Copy
import { Unprice } from "@unprice/api";const unprice = new Unprice({ token: "<API_KEY>" });
Always keep your api key safe and reset it if you suspect it has been compromised.
Because forgetting to handle thrown errors properly in javascript is often forgotten, we have decided to explicitly return errors to be handled. Fortunately typescript helps us here and everything is typesafe.Every method returns either an error or a result field, never both and never none.
Copy
{ result: T // the result depends on what method you called}
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.
Copy
import { Unprice } from "@unprice/api";const unprice = new Unprice({ token: env.UNPRICE_API_KEY, baseUrl: env.UNPRICE_API_URL})const { result, error } = await unprice.customers.getPaymentMethods({ customerId: "cus_123", provider: "stripe"});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;}// return the payment methodsreturn result
By default, Unprice collects anonymous telemetry data to help us understand which versions of our SDK is being used, and in which environment.If you wish to disable this, you can do so by passing a boolean flag to the constructor:
Copy
const unprice = new Unprice({ disableTelemetry: true})