Widget SDK reference
Version 1.0.3. Everything a widget can call, with the inputs, results and errors of each call. New to widgets? Start with Build a widget.
How it works
Your widget runs in a frame inside Docktix. When it calls the SDK, Docktix checks the permission, performs the action as the signed-in user's firm, and returns the result. Your widget never receives a password, session or access token, and you never send one.
A widget only works when it is opened from Docktix. Opening its page directly in a browser tab makes init fail.
Load the SDK
Add this script tag to your widget's entry page:
<script src="https://sdk.docktix.com/sdk/v1/docktix-widget-sdk.js"></script>It creates a global object called Docktix. There is nothing to install and there are no other dependencies. It works in current versions of the major browsers.
| URL | Use it when |
|---|---|
https://sdk.docktix.com/sdk/v1/docktix-widget-sdk.js | You want the latest compatible version 1 release (recommended). |
https://sdk.docktix.com/sdk/1.0.3/docktix-widget-sdk.js | You want to stay on exactly version 1.0.3. |
https://sdk.docktix.com/sdk/1.0.3/docktix-widget-sdk.d.ts | TypeScript type definitions. |
Quick start
<!doctype html>
<html>
<body>
<pre id="out">Loading...</pre>
<script src="https://sdk.docktix.com/sdk/v1/docktix-widget-sdk.js"></script>
<script>
const out = document.getElementById('out');
async function load(context) {
// A record button has a recordId. A left-menu tab does not.
const data = context.recordId
? await Docktix.records.details({ Record_Id: context.recordId })
: await Docktix.modules.list();
out.textContent = JSON.stringify(data, null, 2);
}
const show = (error) => { out.textContent = error.code + ': ' + error.message; };
Docktix.init()
.then((context) => {
Docktix.on('context.changed', (next) => load(next).catch(show));
Docktix.on('auth.revoked', () => { out.textContent = 'This widget was disabled.'; });
return load(context);
})
.catch(show);
</script>
</body>
</html>This example needs the Read records and Read modules permissions.
init
const context = await Docktix.init(options);Connects your widget to Docktix. Call it once, and wait for it before any other call.
| Input | Type | Required | Description |
|---|---|---|---|
options.timeoutMs | number | No | How long to wait for Docktix to answer. Default 10000 (10 seconds). |
Result: the context object.
Calling init again returns the same result. If it fails, you may call it again to retry.
| Error code | Why |
|---|---|
init_failed | The page was not opened from Docktix, or its address is incomplete. |
timeout | Docktix did not answer in time. |
destroyed | Docktix.destroy() was called while connecting. |
The context object
init resolves with the context. The latest copy is always available as Docktix.context (null before init finishes).
{
"placement": "button",
"openMode": "popup",
"module": { "api": "contacts" },
"recordId": "A1B2C3D4E5F6A7B8C9D0",
"recordIds": ["A1B2C3D4E5F6A7B8C9D0"],
"user": { "name": "Jane Doe", "email": "jane@example.com" },
"firm": { "name": "Doe & Co" },
"scopes": ["DocktixCRM.modules.READ", "DocktixCRM.records.READ"],
"theme": "light",
"locale": "en"
}| Field | Type | Description |
|---|---|---|
placement | "button" or "web_tab" | Where the widget was opened from. |
openMode | "popup" or "new_tab" | How a button opened it. May be absent. |
module.api | string | API name of the current module. Absent when there is no record context. |
recordId | string | The current record. Absent in a left-menu tab. |
recordIds | string[] | The current record ids, when provided. |
user.name, user.email | string | The signed-in user. |
firm.name | string | The user's firm. |
scopes | string[] | The permissions this widget has for this user. Check it before you show an action. |
theme | "light" or "dark" | The Docktix theme. |
locale | string | The user's language, for example "en". |
Treat ids as opaque text: do not rely on their length or format.
Events
const stop = Docktix.on('context.changed', (context) => { /* ... */ });
stop(); // remove this handler
Docktix.off('context.changed', handler); // or remove it by reference| Event | When | Your handler receives |
|---|---|---|
context.changed | The user moved to something else while your widget stayed open. | The complete new context. If module, recordId or recordIds are missing, there is no longer a current record: stop using the old one. |
auth.revoked | The widget lost access, for example because an administrator disabled or removed it. | Nothing. |
Permissions
Each data call needs a permission. An administrator approves permissions when installing the widget and chooses which profiles may use it. A user may therefore have fewer permissions than the widget asked for.
| Permission | Shown to the administrator as | Calls |
|---|---|---|
DocktixCRM.modules.READ | Read modules | modules.list, modules.details, modules.fields |
DocktixCRM.records.READ | Read records | records.list, records.details |
DocktixCRM.records.CREATE | Create records | records.create |
DocktixCRM.records.UPDATE | Update records | records.update |
DocktixCRM.records.DELETE | Delete records | records.delete |
Parameters. Data calls take one plain object. Names are case-sensitive. Do not send Firm_Id, Email, Confirm or any token: Docktix sets them, and replaces anything you send for Firm_Id and Email.
Modules
A module is a type of record (for example contacts). You can name it by Module_Api (its API name) or Module_Id. Send one of the two; if you send both they must refer to the same module.
Docktix.modules.list()
Lists the firm's modules. Permission: DocktixCRM.modules.READ.
Inputs: none.
Result: an array of modules.
| Field | Description |
|---|---|
module_id | Module id. |
module_name, module_label | Name and display label. |
module_api_name | Value to pass as Module_Api. |
module_status | Module status. |
module_icon, module_image_url | Icon. |
module_sort_order | Position in the menu. |
module_created_on, module_modified_on | Dates. |
created_by, modified_by | { id, name, alias, email, image }. |
Errors: the common errors.
Docktix.modules.details(params)
Details of one module. Permission: DocktixCRM.modules.READ.
| Input | Type | Required |
|---|---|---|
Module_Api | string | One of the two |
Module_Id | string | One of the two |
Result: the module, including module_id, module_name, module_label, module_api_name, module_status, module_modified_on, module_icon, module_image_url.
Errors:bad_request (no module named, or the two do not match), not_found (no such module in this firm), plus the common errors.
const contacts = await Docktix.modules.details({ Module_Api: 'contacts' });Docktix.modules.fields(params)
The fields of a module. Use it to find the field names for Data. Permission: DocktixCRM.modules.READ.
| Input | Type | Required |
|---|---|---|
Module_Api | string | One of the two |
Module_Id | string | One of the two |
Result: an array of fields.
| Field | Description |
|---|---|
field_id | Field id. |
field_label | Display label. |
field_api_name | The key to use in Data, Fields and Sort_Key. |
field_required | true if the field is required. |
field_type | Field type. Lookup fields are reported as associated. |
Errors:bad_request, not_found, plus the common errors.
Records
Docktix.records.list(params)
One page of a module's records. Permission: DocktixCRM.records.READ.
| Input | Type | Required | Description |
|---|---|---|---|
Module_Api / Module_Id | string | One of the two | The module. |
Page | number | No | Page number, starting at 1 (default). |
Per_Page | number | No | Records per page. Default 25, maximum 100 (larger values are reduced to 100). |
Sort_Key | string | No | modifiedOn (default), createdOn, or a field API name. |
Sort_Type | string | No | ASC or DESC (default). |
Record_Criteria | string | No | Search text. Returns records whose name contains it, ignoring case. |
Fields | string[] | No | Return only these fields. The entries_... properties are always included. |
Result: an array of records. Each record has its field values as properties, plus:
| Property | Description |
|---|---|
entries_id | Record id (use it as Record_Id). |
entries_created_on, entries_modified_on | Dates. |
entries_created_by, entries_modified_by | { id, name, email, image, alias }. |
entries_image_url | Record image, if any. |
entries_converted | Conversion flag. |
entries_tags | Tags on the record (tag_id, tag_label, tag_color, ...). |
Paging: the result does not include a total count. Request the next page until a page returns fewer records than Per_Page.
Errors:bad_request (no module, negative Page or Per_Page), not_found (no such module), plus the common errors.
const page1 = await Docktix.records.list({
Module_Api: 'contacts', Page: 1, Per_Page: 50,
Sort_Key: 'createdOn', Sort_Type: 'DESC', Record_Criteria: 'smith'
});Docktix.records.details(params)
One record. Permission: DocktixCRM.records.READ.
| Input | Type | Required |
|---|---|---|
Record_Id | string | Yes |
Result: the record. Field values are properties of the object, together with entries_id, entries_created_on, entries_modified_on, entries_created_by, entries_modified_by, entries_image_url, entries_active_status, entries_visibility_status, entries_tags, entrie_resources (linked resources) and entries_relations (an object keyed by module API name, each holding the related records).
Errors:bad_request (no Record_Id), not_found (no such record in this firm), forbidden (the record is waiting for approval), plus the common errors.
Docktix.records.create(params)
Creates a record. Permission: DocktixCRM.records.CREATE.
| Input | Type | Required | Description |
|---|---|---|---|
Module_Api / Module_Id | string | One of the two | The module. |
Data | object | Yes, not empty | Field values, keyed by field API name. |
Result: the new record's id (a string).
If the firm requires approval for new records, the call still succeeds and returns the id, but the record stays hidden until it is approved. Reading it before then fails with forbidden or not_found.
File and image fields cannot be uploaded from a widget.
Errors:bad_request (missing module or Data, or the values were refused), not_found (no such module), plus the common errors.
const id = await Docktix.records.create({
Module_Api: 'contacts',
Data: { first_name: 'Jane' }
});Docktix.records.update(params)
Changes a record. Only the fields you send are changed. Permission: DocktixCRM.records.UPDATE.
| Input | Type | Required |
|---|---|---|
Record_Id | string | Yes |
Data | object | Yes, not empty |
Result: the promise resolves when the change is saved. Do not rely on the value it returns; read the record again if you need it.
Errors:bad_request, not_found, plus the common errors.
await Docktix.records.update({ Record_Id: id, Data: { first_name: 'Janet' } });Docktix.records.delete(params, options)
Deletes one record. Permission: DocktixCRM.records.DELETE. Docktix always asks the user to confirm.
| Input | Type | Required |
|---|---|---|
Record_Id | string | Yes |
Result: the promise resolves when the record is deleted. Do not rely on the value it returns.
The time the user takes to answer the confirmation counts toward the call timeout. Give this call a longer one, so your widget does not report a failure while the user is still deciding:
try {
await Docktix.records.delete({ Record_Id: id }, { timeoutMs: 120000 });
} catch (error) {
if (error.code !== 'confirmation_declined') throw error;
}If the call times out, check whether the record still exists before you try again.
Errors:confirmation_declined (the user chose not to delete), bad_request, not_found, plus the common errors.
UI
These calls control the Docktix screen around your widget. They need no permission. Each resolves when Docktix has handled it; do not rely on the value it returns.
| Call | Inputs | What happens |
|---|---|---|
Docktix.ui.notify(message, type) | message: text. type: info (default), success, warning or error. | Docktix shows a notification. The message is shown as plain text. |
Docktix.ui.resize({ height }) | height: pixels. | Asks to change the height of a popup. Docktix keeps it within its own limits and may ignore it in a full-page tab. |
Docktix.ui.openRecord(module, recordId) | Module API name and record id, both required. | Docktix opens that record. |
Docktix.ui.close() | none | Closes the popup or the tab Docktix opened for the widget. |
Errors:bad_request (invalid input), plus the common errors.
await Docktix.ui.notify('Saved', 'success');
await Docktix.ui.resize({ height: document.body.scrollHeight });Access and sign-out (auth)
There is no sign-in call: the user is already signed in to Docktix, and the SDK never gives your widget a token. Access is renewed for you while the widget is open.
Access can end at any time, for example when an administrator disables or removes the widget. A change to its permissions or a new version can also end the open session. Then:
- your
auth.revokedhandler runs; - calls that are still waiting fail with
auth_revoked; - every later call fails with
auth_revokedimmediately.
Show a short message and stop calling. The user can open the widget again from Docktix.
Docktix.on('auth.revoked', () => {
document.body.textContent = 'This widget is no longer available. Close it and open it again.';
});Errors
A failed call rejects with an error whose name is DocktixError.
| Property | Description |
|---|---|
code | One of the codes below. Use it in your logic. |
message | A readable explanation. Do not parse it. |
status | A number similar to an HTTP status, when available. |
requiredScope | The missing permission, for scope_not_granted. |
try {
await Docktix.records.details({ Record_Id: id });
} catch (error) {
if (error.code === 'scope_not_granted') showHelp('Ask your administrator for: ' + error.requiredScope);
else if (error.code === 'not_found') showHelp('This record no longer exists.');
else showHelp(error.message);
}| Code | Meaning | What to do |
|---|---|---|
init_failed | The widget could not connect: it was not opened from Docktix. | Open it from Docktix. |
not_initialized | A call was made before init finished. | Wait for init. |
timeout | No answer in time. | Check the result before repeating a change, then retry. |
destroyed | Docktix.destroy() was called. | Call init again if needed. |
unknown_method | The method name does not exist. | Fix the call. |
bad_request | The input was refused. It is also used when Docktix is temporarily unavailable (status is 0 or 500 and above). | Fix the input; for an outage, retry later. |
scope_not_granted | The widget does not have the permission for this user. | Do not retry. Ask an administrator. |
confirmation_declined | The user did not confirm. | Nothing: respect the choice. |
not_found | The item does not exist in this firm. | Check the id. |
forbidden | Not allowed, for example a record waiting for approval. | Do not retry. |
not_a_member | The user no longer belongs to the firm. | Stop. |
rate_limited | Too many calls. | Wait, then retry. |
auth_revoked | Access to the widget ended. | Stop. See auth. |
Errors any call can return
not_initialized, timeout, destroyed, rate_limited, auth_revoked, bad_request. Data calls can also return scope_not_granted, forbidden and not_a_member.
Call limit and timeouts
- Call limit: each open widget may make up to 10 calls per second, with up to 60 calls waiting for an answer at the same time. Calls over the limit fail with
rate_limited. This applies to data and UI calls. - Do not retry in a tight loop. Wait a moment and increase the wait if it happens again.
- Read records in pages (
Per_Pageup to 100) instead of one call per record where you can. - Timeout: each call waits up to 30 seconds. Change it for one call with a second argument:
{ timeoutMs: 60000 }.
Other methods
| Method | Description |
|---|---|
Docktix.context | The latest context, or null. |
Docktix.version | The SDK version, for example "1.0.3". |
Docktix.call(method, params, options) | Calls a method by name, for example Docktix.call('records.list', { Module_Api: 'contacts' }). Docktix.call('context.get') returns the current context from Docktix. |
Docktix.destroy() | Disconnects: removes your event handlers, cancels waiting calls with destroyed. A later init starts again. |