Skip to main content
Docktix

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:

html
<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.

URLUse it when
https://sdk.docktix.com/sdk/v1/docktix-widget-sdk.jsYou want the latest compatible version 1 release (recommended).
https://sdk.docktix.com/sdk/1.0.3/docktix-widget-sdk.jsYou want to stay on exactly version 1.0.3.
https://sdk.docktix.com/sdk/1.0.3/docktix-widget-sdk.d.tsTypeScript type definitions.

Quick start

html
<!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

js
const context = await Docktix.init(options);

Connects your widget to Docktix. Call it once, and wait for it before any other call.

InputTypeRequiredDescription
options.timeoutMsnumberNoHow 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 codeWhy
init_failedThe page was not opened from Docktix, or its address is incomplete.
timeoutDocktix did not answer in time.
destroyedDocktix.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).

json
{
  "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"
}
FieldTypeDescription
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.apistringAPI name of the current module. Absent when there is no record context.
recordIdstringThe current record. Absent in a left-menu tab.
recordIdsstring[]The current record ids, when provided.
user.name, user.emailstringThe signed-in user.
firm.namestringThe user's firm.
scopesstring[]The permissions this widget has for this user. Check it before you show an action.
theme"light" or "dark"The Docktix theme.
localestringThe user's language, for example "en".

Treat ids as opaque text: do not rely on their length or format.

Events

js
const stop = Docktix.on('context.changed', (context) => { /* ... */ });
stop();                                   // remove this handler
Docktix.off('context.changed', handler);  // or remove it by reference
EventWhenYour handler receives
context.changedThe 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.revokedThe 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.

PermissionShown to the administrator asCalls
DocktixCRM.modules.READRead modulesmodules.list, modules.details, modules.fields
DocktixCRM.records.READRead recordsrecords.list, records.details
DocktixCRM.records.CREATECreate recordsrecords.create
DocktixCRM.records.UPDATEUpdate recordsrecords.update
DocktixCRM.records.DELETEDelete recordsrecords.delete
Important: permissions apply to the whole firm. A user who may use a widget with Read records can read, through that widget, records of the firm that they might not see elsewhere in Docktix. Ask only for what your widget needs.

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.

FieldDescription
module_idModule id.
module_name, module_labelName and display label.
module_api_nameValue to pass as Module_Api.
module_statusModule status.
module_icon, module_image_urlIcon.
module_sort_orderPosition in the menu.
module_created_on, module_modified_onDates.
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.

InputTypeRequired
Module_ApistringOne of the two
Module_IdstringOne 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.

js
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.

InputTypeRequired
Module_ApistringOne of the two
Module_IdstringOne of the two

Result: an array of fields.

FieldDescription
field_idField id.
field_labelDisplay label.
field_api_nameThe key to use in Data, Fields and Sort_Key.
field_requiredtrue if the field is required.
field_typeField 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.

InputTypeRequiredDescription
Module_Api / Module_IdstringOne of the twoThe module.
PagenumberNoPage number, starting at 1 (default).
Per_PagenumberNoRecords per page. Default 25, maximum 100 (larger values are reduced to 100).
Sort_KeystringNomodifiedOn (default), createdOn, or a field API name.
Sort_TypestringNoASC or DESC (default).
Record_CriteriastringNoSearch text. Returns records whose name contains it, ignoring case.
Fieldsstring[]NoReturn only these fields. The entries_... properties are always included.

Result: an array of records. Each record has its field values as properties, plus:

PropertyDescription
entries_idRecord id (use it as Record_Id).
entries_created_on, entries_modified_onDates.
entries_created_by, entries_modified_by{ id, name, email, image, alias }.
entries_image_urlRecord image, if any.
entries_convertedConversion flag.
entries_tagsTags 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.

js
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.

InputTypeRequired
Record_IdstringYes

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.

InputTypeRequiredDescription
Module_Api / Module_IdstringOne of the twoThe module.
DataobjectYes, not emptyField 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.

js
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.

InputTypeRequired
Record_IdstringYes
DataobjectYes, 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.

js
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.

InputTypeRequired
Record_IdstringYes

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:

js
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.

CallInputsWhat 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()noneCloses the popup or the tab Docktix opened for the widget.

Errors:bad_request (invalid input), plus the common errors.

js
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:

  1. your auth.revoked handler runs;
  2. calls that are still waiting fail with auth_revoked;
  3. every later call fails with auth_revoked immediately.

Show a short message and stop calling. The user can open the widget again from Docktix.

js
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.

PropertyDescription
codeOne of the codes below. Use it in your logic.
messageA readable explanation. Do not parse it.
statusA number similar to an HTTP status, when available.
requiredScopeThe missing permission, for scope_not_granted.
js
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);
}
CodeMeaningWhat to do
init_failedThe widget could not connect: it was not opened from Docktix.Open it from Docktix.
not_initializedA call was made before init finished.Wait for init.
timeoutNo answer in time.Check the result before repeating a change, then retry.
destroyedDocktix.destroy() was called.Call init again if needed.
unknown_methodThe method name does not exist.Fix the call.
bad_requestThe 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_grantedThe widget does not have the permission for this user.Do not retry. Ask an administrator.
confirmation_declinedThe user did not confirm.Nothing: respect the choice.
not_foundThe item does not exist in this firm.Check the id.
forbiddenNot allowed, for example a record waiting for approval.Do not retry.
not_a_memberThe user no longer belongs to the firm.Stop.
rate_limitedToo many calls.Wait, then retry.
auth_revokedAccess 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_Page up 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

MethodDescription
Docktix.contextThe latest context, or null.
Docktix.versionThe 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.