@artworker/sdk
Artworker SDK Documentation
Table of Contents
Introduction
The Artworker SDK allows your B2B SaaS to integrate with Artworker services, making it easier to handle artwork. This documentation aims to provide a comprehensive guide for implementing the SDK's features.
Installation
npm install artworker-sdk
Artworker Client
const client = new Client('your-api-key');
Throws
- Throws an error if the
apiKeyis not supplied or invalid.
Methods
picker(options?: PickerOptions): Picker
Initializes a new Picker instance, allowing a user to upload artwork. See below for more details.
Picker
const client = new Client('your-api-key');
const picker = artworker.picker({
uploadMeta: {
customUId: "wedk3w4f", // the Id of the orderItem or orderId in your system (if you have it)
jobName: "300 flyers",
customerEmail: "joe@bloggs.com",
customerName: "Joe Bloggs",
},
onClose: () => {
console.log("user closed picker widget without submitting artwork");
},
onDone: (pickerResponse) => {
console.log("user submitted the following artwork:", pickerResponse);
},
});
// open the picker
picker.open();
PickerOptions
Configure callbacks to handle events from the Artworker picker widget
interface PickerOptions {
uploadMeta: {
customUId: string; // the Id of the orderItem or orderId in your system (if you have it)
jobName: string;
customerEmail: string;
customerName: string;
};
onClose?: () => void;
onOpen?: (handle: PickerInstance) => void;
onDone?: (files: PickerResponse) => void;
}
uploadMeta
Prefills fields in artworker based on input
onClose
Called when the picker is closed by the user, without submitting any artwork
onOpen
Prefills fields in artworker based on input
onDone
Called when the user has submitted artwork. Returns the PickerResponse object
interface PickerResponse {
fileTransfer?: FileTransfer;
}
interface Image {
id: bigint;
url: string;
filename: string;
contentType: string;
}
interface Media {
id: bigint;
url: string;
filename: string;
contentType: string;
thumbnail?: Image;
imagePreview?: Image;
originalFilename: string;
fileSize: string;
}
interface FileTransfer {
id: string;
mediaItems: Media[];
contactName: string;
contactEmail: string;
orderRef: string;
name: string;
notes: string;
}
Methods
open(): void
Opens the Picker UI.
Events
opened: Triggered when the picker is opened.done: Triggered when the picker process is done.closed: Triggered when the picker is closed.
Authentication
If your company operates as a B2B SaaS and some of your customers have Artworker accounts, you'll need to obtain their public API keys to capture artwork on their behalf. You have two options for achieving this:
- Request that your customers manually go to their Artworker account, copy their public API key, and share it with you through a secure channel of your choice.
- Use the Auth method provided in this class to automate the acquisition of their public API key.
The Auth Object
import { Auth } from '@artworker/sdk';
const auth = new Auth({ debugMode: true });
Methods
| Method | Description |
|---|---|
show() |
Displays the authentication widget. |
onAuthenticated(cb: AuthentiationCallback) |
Sets the callback function that will be called upon successful authentication. |
onError(cb: ErrorCallback) |
Sets the callback function that will be called when an error occurs. |
Usage Example
A sample code snippet on how to use the Auth class is provided below:
import { Auth } from '@artworker/sdk';
const auth = new Auth({ debugMode: true });
auth.onAuthenticated((apiKey) => {
console.log('Authenticated, received API Key:', apiKey);
});
auth.onError((err) => {
console.error('Error:', err);
});
auth.show();