Skip to main content

dcTrackClient GitHub Workflow Status PyPI PyPI - Downloads npm npm

Sunbird dcTrack API clients in Python and JavaScript

Installation

dcTrackClient can be installed from the package manager of your choice.

Python

pip install dcTrackClient==1.5.2

JavaScript

npm i dctrackclient@1.5.2

Initialize a connection to the dcTrack API

Authentication is by using a base URL (the same URL to access the GUI) and a username and password, or a base URL and an API token.

Python

from dcTrackClient import Client
## Using a username and password ##
api = Client('https://dctrack.example.com/', username='user', password='pass')
## Using an API token ##
api = Client('https://dctrack.example.com/', apiToken='token')

JavaScript

import { Client } from 'dctrackclient';
// Using a username and password // 
const api = new Client('https://dctrack.example.com/', { username: 'user', password: 'pass' });
// Using an API token //
const api = new Client('https://dctrack.example.com/', { apiToken: 'token' });

Advanced: Initialize a connection with a proxy

Proxies can be used for either authentication method (username/password or API token) for both libraries. For the Python library, specify an HTTP or HTTPS proxy, or both. These can also be SOCKS proxies. For the JavaScript library, only 1 proxy is required and https proxies can either be HTTP or HTTPS. HTTPS will automatically upgraded to TLS.

Python

api = Client('https://dctrack.example.com/', username='user', password='pass', httpProxy='http://proxy:port', httpsProxy='https://proxy:port')

JavaScript

const api = new Client('https://dctrack.example.com/', { username: 'user', password: 'pass' }, { https: 'http://proxy:port', socks: 'socks://proxy:port' });

In Python, you can use the sslVerify=True/False argument to toggle whether SSL/TLS certificates are verified on the server. For JavaScript, toggle off this environment variable export NODE_TLS_REJECT_UNAUTHORIZED=0 before executing the script.

Obtain an API Token

Obtain an API token using the Client.generateToken() function provided. Re-authentication is not necessary, as the API token will automatically be used in subsequent API calls. The function returns the token's value in case the user wants to store the token for the next initialization of the API.

Python

token = api.generateToken()

JavaScript

Notice the await keyword before the function call. This is because the JavaScript library is asynchronous and returns a Promise to the return value. All the API calls in this library require that keyword.

const token = await api.generateToken();

Usage Example

This section demonstrates item manipulation with the API client.

Create an item

This example shows the minimum attributes required to create an item using the createItem function. View the comprehensive list of item attributes in the official documentation. Make sure to capture the return value of this function to see the created item details, such as the unique numeric item ID, or to determine if an error occurred while creating an item.

Python

# Set `returnDetails = True` to return the complete item field list.
response = api.createItem(False, {
    'cmbLocation': 'item location',
    'tiName': 'item name',
    'cmbMake': 'item make',
    'cmbModel': 'item model'
})
print(response)

JavaScript

See the JavaScript section on obtaining an API token why the await keyword is required.

// Set `returnDetails = true` to return the complete item field list.
let response = await api.createItem(false, {
    'cmbLocation': 'item location',
    'tiName': 'item name',
    'cmbMake': 'item make',
    'cmbModel': 'item model'
});
console.log(response);

On Success

This function returns the JSON object for the newly created item. This is an example response if returnDetails was set to false.

{ "item": { "id": 1234, "tiName": "item name" } }

On Failure

This function returns a JSON object containing the error message.

Retrieve item details

This example shows the usage of the getItem function. This function requires the unique item's ID, shown in the create item example. It returns the full list of item attributes.

Python

response = api.getItem(1234)

JavaScript

let response = await api.getItem(1234);

Returns

{
    "item": {
        "cmbLocation": "item location",
        "tiName": "item name",
        ...
    }
}

Modify an existing item

This example shows the usage of the updateItem function. Any number of attributes can be included in the payload to be modified. The returnDetails parameter behaves in the same way as in the create item example.

Python

response = api.updateItem(1234, False, {'tiSerialNumber': 12345})

JavaScript

let response = await api.updateItem(1234, false, { 'tiSerialNumber': 12345 });

Search for an item

This example demonstrates usage of the searchItems function. Follow this guide for details on creating the request payload. In this example, the API searches for an item based on the tiName field.

Python

response = api.searchItems(0, 0, {
    'columns': [
        {'name': 'tiName', 'filter': {'eq': 'item name'}}
    ],
    'selectedColumns': [
        {'name': 'id'},
        {'name': 'tiName'},
    ]
})

JavaScript

let response = await api.searchItems(0, 0, {
    'columns': [
        { 'name': 'tiName', 'filter': { 'eq': 'item name' } }
    ],
    'selectedColumns': [
        { 'name': 'id' },
        { 'name': 'tiName' },
    ]
});

Returns

{
    "selectedColumns": [],
    "totalRows": 1,
    "pageNumber": 0,
    "pageSize": 0,
    "searchResults": {
        "items": [
            {"id": "1234", "tiName": "item name"}
        ]
    }
}

Delete an item

This example demonstrates usage of the deleteItem function.

Python

api.deleteItem(1234)

JavaScript

await api.deleteItem(1234);

Returns

{ "itemId": 1234 }

Official DcTrack Documentation

Visit this link for the official documentation on request bodies and attrribute names.

https://www.sunbirddcim.com/help/dcTrack/v930/API/en/Default.htm

Package Documentation

The section below shows all the functions contained within this client along with basic usage.

Release files for dcTrackClient 1.5.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dcTrackClient 1.5.2
File Size Uploaded
dctrackclient-1.5.2.tar.gz 10.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for dcTrackClient 1.5.2
File Interpreter ABI Platform
dctrackclient-1.5.2-py3-none-any.whl Python 3 none any Details

Total release size: 22.1 kB

Release files / dctrackclient-1.5.2.tar.gz

Download URL dctrackclient-1.5.2.tar.gz
Size 10.8 kB
Tags Source
SHA-256 checksum
How to use checksums
5efb27102f9aa703c9072ae84f3ef3d613798dd99d61b43f98ef2f57ad6781d3
BLAKE2b-256 checksum
How to use checksums
f7d1cb2a55fa3c83db6b218a40cd1e023d15681a0d59e0b753ae7ebb317510ab
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.15

Release files / dctrackclient-1.5.2-py3-none-any.whl

Download URL dctrackclient-1.5.2-py3-none-any.whl
Size 11.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
de6813f6a7047bda42f049491008f225acd11ccc9b0b2fe5569e1ab16e370920
BLAKE2b-256 checksum
How to use checksums
840b9e4ecd651c3f2a75822ca913962bf64ff8275a093970c5ac074aa1c1e2e6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.15

Release history Release notifications | RSS feed

1.5.3

2 release files

This release

1.5.2 This release

2 release files

1.5.1

2 release files

1.5.0

2 release files

1.4.8

2 release files

1.4.7

2 release files

1.4.6

2 release files

1.4.5

2 release files

1.4.4

2 release files

1.4.3

2 release files

1.4.2

2 release files

1.4.1

2 release files

1.4.0

2 release files

1.3.2

2 release files

1.3.1

2 release files

1.3.0

2 release files

1.2.2

2 release files

1.2.1

2 release files

1.2.0

2 release files

1.1.4

2 release files

1.1.3

2 release files

1.1.2

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.9.1

2 release files

0.9.0

2 release files

0.8.1

2 release files

0.8.0

2 release files

0.7.2

2 release files

0.7.1

2 release files

0.7.0

2 release files

0.6.2

2 release files

0.6.1

2 release files

0.6.0

2 release files

0.5.2

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.4

2 release files

0.4.3

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.4

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

0.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page