This topic will show how to set up and define a GET, PUT, POST and DELETE request to the JAMS REST API using Python. The four examples below will utilize an Agent to demonstrate the functionality of the API requests.
![]() |
Note: To call another controller in the API, such as Job, Batch Queue, etc., are defined in the same way, however you will need different parameters other than Agent and include a different URL. The documentation and Swagger links becomes available from the JAMS Server once the REST API is installed. |
![]() |
Note: This documentation only covers JAMS and does not include setting up the Python development or Eclipse environment. For more information on Python configuration using Eclipse go to: http://www.vogella.com/tutorials/Python/article.html |
You must first authenticate with JAMS in order to define other requests to the JAMS REST API. To get started with the authentication POST request, follow the description below.
Copy the following code and paste into your .py and make sure to enter your JAMS username and password.
#import requests library for making REST calls import requests import json #specify url url = 'http://left/JAMS/api/authentication/login' #Create payload that will be passed to API for authentication payload = { "username": "#Your JAMS Username", "password": "#Your JAMS Password" } #Fill in headers headers = {'content-type': 'application/json'} #Call REST API response = requests.post(url, data=json.dumps(payload), headers=headers) #Print Response print(response.text)
If your username and password is authenticated, a token will appear in the Console as shown in the screenshot below (highlighted in blue).
![]() |
Important: Make sure to copy this token because it will be needed for every request to the API going forward. However, do not copy the “expires in” variable located at the end of the token. If this portion is included it will invalidate the token when pasted into another request. |
![]() |
Note: If you receive a “401” console error it indicates that the token has expired and you must repeat the login and authentication process as describe above. |
Once you have been authenticated and received a token you can issue other requests. In this example, let’s begin with a GET request that will display a list of all JAMS Agents located on a server called “LEFT”.
#import requests library for making REST calls import requests #specify url url = 'http://left/JAMS/api/agent' #Store authorization token in a local variable token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ0aW1mQG12cHNpLmNvbSIsInJvbGUiOiJ1c2VyIiwiSkFNU1RlbmVudElkIjoiNDIiLCJXaW5kb3dzSWRlbnRpdHkiOiJ0aW1mQG12cHNpLmNvbSIsImlzcyI6Ik1WUFNJIiwiYXVkIjoiSkFNU0FEQ2xpZW50SWQiLCJleHAiOjE0NDQ4ODY0NjQsIm5iZiI6MTQ0NDg0MzI2NH0.NRP6o3dMy9WJxXe8zYEznxZN9by6zrrGqo7_yOnyVhA" #Fill in request headers headers = {'Authorization': 'Bearer ' + token} #Call REST API and pass in URL, and headers response = requests.get(url, headers=headers) #Print Response print (response.text)
Using the token you can also issue a PUT request. In this example let’s demonstrate how to change the description of an Agent called “Agent 11”.
![]() |
Note: Agent 11’s currently uses a generic description (“A Description”) as shown below. To change the description, follow the steps below. |
#import requests library for making REST calls import requests import json #specify url url = 'http://left/JAMS/api/agent' #Store auth token in local variable that passes to the header token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ0aW1mQG12cHNpLmNvbSIsInJvbGUiOiJ1c2VyIiwiSkFNU1RlbmVudElkIjoiNDIiLCJXaW5kb3dzSWRlbnRpdHkiOiJ0aW1mQG12cHNpLmNvbSIsImlzcyI6Ik1WUFNJIiwiYXVkIjoiSkFNU0FEQ2xpZW50SWQiLCJleHAiOjE0NDQ4ODY0NjQsIm5iZiI6MTQ0NDg0MzI2NH0.NRP6o3dMy9WJxXe8zYEznxZN9by6zrrGqo7_yOnyVhA" #Specify Agent payload = { "agentName": "Agent 11", "description": "Changed the Description", "platform": "Windows" } #Pass in headers token and content-type headers = {'Authorization': 'Bearer ' + token, "Content-Type": "application/json"} #Call REST API response = requests.put(url, data=json.dumps(payload), headers=headers) #Print Status Code print(response.status_code)
![]() |
Note: You can use the same format with any other controller on the API, such as job or batch queue. However, you may need to pass additional values to the payload for different controllers. In addition, you will need to change the url to represent which controller you are modifying, for example, a job would be …/api/job. |
For this example let’s post a new Agent called “NEW AGENT”.
#import requests library for making REST calls import requests import json #specify url url = 'http://left/JAMS/api/agent' token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ0aW1mQG12cHNpLmNvbSIsInJvbGUiOiJ1c2VyIiwiSkFNU1RlbmVudElkIjoiNDIiLCJXaW5kb3dzSWRlbnRpdHkiOiJ0aW1mQG12cHNpLmNvbSIsImlzcyI6Ik1WUFNJIiwiYXVkIjoiSkFNU0FEQ2xpZW50SWQiLCJleHAiOjE0NDQ4ODY0NjQsIm5iZiI6MTQ0NDg0MzI2NH0.NRP6o3dMy9WJxXe8zYEznxZN9by6zrrGqo7_yOnyVhA" #Create payload that will be passed to API for authentication payload = { "agentName": "NEW AGENT", "description": "Testing Python POST", "agentType": "1", "platform": "Windows", "jobLimit": "777", "userName": "#Your Username" } #Fill in headers headers = {'Authorization': 'Bearer ' + token, "Content-Type": "application/json"} #Call REST API and pass in URL, data and headers response = requests.post(url, data=json.dumps(payload), headers=headers) #Print Response print(response.text) print(response.status_code, response.headers)
![]() |
Note: You can use the same format with any other controller on the API, such as job or batch queue. However, you may need to pass additional values to the payload for different controllers. In addition, you will need to change the url to represent which controller you are modifying, for example, a job would be …/api/job. |
For this final example we’ll show how to delete an Agent using a DELETE Request on the sample agent (“Agent 11”).
#import requests import requests #import json library import json # Set the request parameters url = 'http://left/JAMS/api/agent/Agent11' #Store auth token in local variable that passes to the header token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ0aW1mQG12cHNpLmNvbSIsInJvbGUiOiJ1c2VyIiwiSkFNU1RlbmVudElkIjoiNDIiLCJXaW5kb3dzSWRlbnRpdHkiOiJ0aW1mQG12cHNpLmNvbSIsImlzcyI6Ik1WUFNJIiwiYXVkIjoiSkFNU0FEQ2xpZW50SWQiLCJleHAiOjE0NDQ4ODY0NjQsIm5iZiI6MTQ0NDg0MzI2NH0.NRP6o3dMy9WJxXe8zYEznxZN9by6zrrGqo7_yOnyVhA" #Specify Agent payload = { "agentName": "Agent11" } #Pass in headers token and content-type headers = {'Authorization': 'Bearer ' + token, "Content-Type": "application/json"} #Call REST API response = requests.delete(url, data=json.dumps(payload), headers=headers) #Print Status Code print(response.status_code)