Skip to main content

Client Central Python API.

Project description

clientcentral-api-python

version Commitizen friendly semantic-release

Install

pip install clientcentral --user

Upgrading

pip install --user --upgrade clientcentral

A specific version can also be installed by adding the tag:

pip install --user --upgrade clientcentral==9.2.1

Requirements

This library was built and tested on Python 3.7.4 a minimal Python version of Python 3.6.x is required.

Python 2 is not supported.

Features

  • Object Oriented API
  • Querying
  • Lazy loading (Events)

Config

The token that will be used can either be sent as an environement variable:

CC_TOKEN=<TOKEN> python3 main.py

or parsed to the constructor:

cc = ClientCentral(production=True, token="123")

Example usage

import clientcentral.ticketformatting as tf
from clientcentral.clientcentral import ClientCentral

# Production 'false' will run on qa.cc
cc = ClientCentral(production=True)

# This will create a ticket in the Managed Services workspace.
# In this example custom_fields {"id": 17, "values": 0} refer to "Security related" -> "No"
# Theses values can be found by following the following instructions: https://clientcentral.io/support/cc/kb/articles/1661-tickets-api-creating-tickets
ticket = cc.create_ticket(subject="New awesome subject" ,
                          description="this is an awesome ticket",
                          project_id=8,
                          workspace_id=16,
                          custom_fields_attributes=[{
                              "id": 17,
                              "values": 0
                          }, {
                              "id": 75,
                              "values": 363
                          }])

ticket.comment("<p>" + tf.bold("I am BOLD") + "</p>")

# Get the ticket's creator
print("Ticket creator: " + ticket.owner.name)

# Get the ticket's status
print("Ticket status:" + ticket.status.name)

# Print the ticket's description
print("Ticket description: " + ticket.description)

# Add a user to watchers
ticket.add_user_watcher(14012) # 14012 refers to the user id in this case its "Thomas Scholtz"

# Change the description of the ticket
ticket.description = "New and improved ticket description"

# Finally after making all changes commit them.
ticket.commit()

for comment in ticket.comments:
    if comment.created_by_user:
        print("Comment from: " + comment.created_by_user.name + " says: " + comment.comment)

# Ticket events, change_events and comments are lazy loaded.
for change_event in ticket.change_events:
    if change_event.created_by_user:
        print("Change by: " + str(change_event.created_by_user.name))
    for change in change_event.changes:
        print("Changed: " + str(change.name) + " from: " + str(change.from_value) + " to: " + str(change.to_value))

Example query

from clientcentral.clientcentral import ClientCentral
import clientcentral.query as operators

# Production 'false' will run on qa.cc
cc = ClientCentral(production=True)

# This will return a list of all tickets that are:
# open,
# in workspace with id 87,
# created by the user with the email 'thomas@labs.epiuse.com',
# has not been updated since 2019-02-20,
# subject contains 'New awesome subject'
tickets = cc.query_tickets().filter_by(
            operators.and_( operators.statement("status.open"),
                            operators.comparison("workspace_id", "=", "87"),
                            operators.comparison("created_by_user.email", "=", "'thomas@labs.epiuse.com'"),
                            operators.comparison("updated_at", "<", "'2019-02-20'"),
                            operators.comparison("subject", "CONTAINS", "'New awesome subject'"))
                           ).all()

for ticket in tickets:
    # Get the ticket's creator
    print("Ticket creator: " + ticket.owner.name)

    # Get the ticket's status
    print("Ticket status:" + ticket.status.name)

    # Print the ticket's description
    print("Ticket description: " + ticket.description)

    # Ticket events, change_events and comments are lazy loaded.
    for comment in ticket.comments:
        if comment.created_by_user:
            print("Comment from: " + comment.created_by_user.name +
                  " says: " + comment.comment)
    for change_event in ticket.change_events:
        if change_event.created_by_user:
            print("Change by: " + str(change_event.created_by_user.name))
        for change in change_event.changes:
            print("Changed: " + str(change.name) + " from: " +
                  str(change.from_value) + " to: " + str(change.to_value))

Contributing

For this repository we are enforcing the use of Commitizen. Respective merge requests require to follow the format created from Commitizen. More info can be found at: http://commitizen.github.io/cz-cli/

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

clientcentral-9.2.1.tar.gz (20.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

clientcentral-9.2.1-py2.py3-none-any.whl (37.3 kB view details)

Uploaded Python 2Python 3

File details

Details for the file clientcentral-9.2.1.tar.gz.

File metadata

  • Download URL: clientcentral-9.2.1.tar.gz
  • Upload date:
  • Size: 20.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.2

File hashes

Hashes for clientcentral-9.2.1.tar.gz
Algorithm Hash digest
SHA256 38ff1b58f377c69e49d46d47c0b9b7ae81b87bd14b1f3278b19aa1df4c85da9d
MD5 4a11460cf05f5589b50206cb743e6d4a
BLAKE2b-256 e83a6161c3ee5ba774a6ed917195c26244555eb4cd85a5cd316cc72ba2ac6555

See more details on using hashes here.

File details

Details for the file clientcentral-9.2.1-py2.py3-none-any.whl.

File metadata

  • Download URL: clientcentral-9.2.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 37.3 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.2

File hashes

Hashes for clientcentral-9.2.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 35a8c9dd7be0dd1eaa03499365b0af124f3feb6db64504d41fc29c0770b49138
MD5 bb910d1e0f5e2f5f50f1a28676e5b8df
BLAKE2b-256 6bee0c97bd6ab6143caf64ece2ff13f7b3c62672f872db15db1d66f3d404e990

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page