Using the CloudBees CD REST API via python

Article ID:360033188811
2 minute readKnowledge base

The easiest way to start using Rest API through Python is to use a "Requests" module.

import requests

The requests module provides all required methods for Rest API calls. Official documentation for requests can be found here.

Before sending any request authentication and SSL certificate ignoring are required:

Authentication and login

Missing authentication will cause error in response

'{"error":{"where":"","message":"No credentials/session found in this request","details":"","code":"NoCredentials"}}'

There are at least two ways to authenticate:

1. Provide password and login information in each request

Firstly auth module from requests should be imported - from requests.auth import HTTPBasicAuth

So request will look like this:

requests.put('https://EFlowServer/rest/v1.0/properties/PythonProperty?projectName=Default&value=newvalue', auth=HTTPBasicAuth('user', 'secretpasswd'))

2. Login and save session id in headers

Logging in can be done by sending the next request:'https://EFlowServer/rest/v1.0/sessions?password=changeme&userName=admin', verify=False)

A server will send a response something like this:

"sessionId": "4VOZBL8M9X5BJYI9",
"userName": "user"

"sessionId" should be stored in some property for use afterward in headers. Also, the content type can be set in headers(it should be set to 'application/json'):

// NOTE: "myHeaders" will be used in below examples of requests.
myHeaders = {'Accept': 'application/json', "sessionId": "4VOZBL8M9X5BJYI9"}

So a request with added session details in the headers should look like this -

requests.get('https://EFlowServer/rest/v1.0/properties/PythonProperty?projectName=Default', verify=False, headers=myHeaders)

Ignoring SSL certificate

To ignore SSL certificates, the option "verify" in the request should be set to "False".


This will avoid the error of SSL: CERTIFICATE_VERIFY_FAILED.

Sending requests

After preparation was done all types of requests(GET, POST, PUT, DELETE) can be sent:

Get property


requests.get('https://EFlowServer/rest/v1.0/properties/PythonProperty?projectName=Default', verify=False, headers=myHeaders)


{ "property": { "propertyId": "d527401a-d390-11e7-832b-005056330fc3", "propertyName": "PythonProperty", "counter": "0", "createTime": "2017-11-27T16:34:26.271Z", "description": "", "expandable": "1", "lastModifiedBy": "user", "modifyTime": "2017-11-27T16:34:26.271Z", "owner": "user", "tracked": "1", "value": "PythonRestApi" } }

Set property


requests.put('https://EFlowServer/rest/v1.0/properties/PythonProperty?projectName=Default&value=UpdatedPython', auth=HTTPBasicAuth('user', 'superpasswd'))


{ "property": { "propertyId": "d527401a-d390-11e7-832b-005056330fc3", "propertyName": "PythonProperty", "counter": "0", "createTime": "2017-11-27T16:34:26.271Z", "description": "", "expandable": "1", "lastModifiedBy": "user", "modifyTime": "2017-11-27T16:34:26.271Z", "owner": "user", "tracked": "1", "value": "PythonUpdate" } }

Publish artifact version

Request'https://EFlowServer/rest/v1.0/artifacts?artifactKey=2&groupId=2', verify=False, auth=HTTPBasicAuth('admin', 'rootpasswd'))



All requests are using the same pattern of URI:


For more information please see Rest API details available on your installed system: