This is the typescript/node SDK for Plain.com's Core GraphQL API. It makes it easy to make common API calls in just a few lines of code.
If you run into any issues please open an issue or get in touch with us at help@plain.com.
import { PlainSDKClient } from "@team-plain/typescript-sdk"
const client = new PlainSDKClient({
apiKey: 'plainApiKey__tmRD_xF5qiMH0657LkbLCC1maN4hLsBIbyOgjqEP4w'
})
const result = await client.getCustomerById({ customerId: 'c_01GHC4A88A9D49Q30AAWR3BN7P' });
if (result.error) {
console.log(result.error);
} else {
console.log(result.data.fullName);
}
You can find out how to make an API key in our documentation: https://docs.plain.com/core-api/authentication
Every method in the SDK corresponds to a graphql query or mutation.
You can find the generated documentation here:
If you would like to add a query or mutation please open an issue and we can add it for you.
Every SDK method will return an object with either data or an error.
You wil either receive an error or data, never both.
Here is an example:
function doThing() {
const result = await client.getCustomerById({ customerId: 'c_01GHC4A88A9D49Q30AAWR3BN7P' });
if (result.error) {
console.log(result.error);
} else {
console.log(result.data.fullName);
}
}
An error can be one of
(view source)
If you only handle one error when using the SDK, handle this one. This is an error returned by a mutation within Plain's API and contains lots of information of what went wrong. It is called 'MutationError' since it every mutation
error has a errorDetails field which contains the full error details.
Here is an example error:
VALIDATION, FORBIDDEN, INTERNAL. See MutationErrorType for a description of each value.VALIDATION, REQUIRED, NOT_FOUND. See MutationFieldErrorType for a description of each value.(view source) Equivalent to a 400 response. If you are using typescript it's unlikely you will run into this since types will prevent this but if you are using javascript this likely means you are providing a wrong input/argument to a query or mutation.
(view source) Equivalent to a 401 response. Normally means your API key is wrong or has insufficient permissions
(view source) Equivalent to a 500 response. If this happens something unexpected within Plain happened.
Generated using TypeDoc