<rss version="2.0" xmlns:a10="http://www.w3.org/2005/Atom"><channel><title>Inflectra Customer Forums: Problem with manual test run creation using REST (Thread)</title><description> I am trying to create a test run using the rest api. After reading the documentation I have made a little code but I dont know what Im doing wrong because when I do the PUT, it doesnt work. I think it may be related to the dictionary that is sent in the request but Im not sure. The code is the following:   import requests
from datetime import datetime

# Set up the API endpoint URLs
api_url = "https://xyz.spiraservice.net/Services/v6_0/RestService.svc"
project_id = 9  # Replace with your project ID
release_id = 807

# Credentials and login
username = "xyz"
api_key = "{xyz-xyz-xyz-xyz-xyz}"
auth = (username, api_key)

# Petition header
headers = {
    "Content-Type": "application/json"
}

# Create a new test run shell dictionary
new_test_run = [2361]

# Construct the test run shell
test_run_create_endpoint = f"{api_url}/projects/{project_id}/test-runs/create?release_id={release_id}"

# Make a POST request to create the test run shell
response_post = requests.post(test_run_create_endpoint, headers=headers, auth=auth, json=new_test_run)

# Check if the request was successful
if response_post.status_code == 200:  # HTTP 201 Created
    test_run = response_post.json()
    print(test_run)
    # if "TestRunId" in test_run:
    #     test_run_id = test_run["TestRunId"]
    #     print(f"Test run created successfully with ID: {test_run_id}")
    # else:
    #     print("Error: Test run ID not found in the response")
else:
    print(f"Error creating test run: {response_post.status_code} - {response_post.text}")

# Update the test run 0001-01-01T00:00:00
test_run_data = [
    {"TestRunId": 0,},
    {"ExecutionStatusId" : 1},
    {"EndDate" : datetime.now().strftime("%Y-%m-%dT%H:%M:%S.000")}
]

endpoint = f"{api_url}/projects/{project_id}/test-runs?end_date={test_run_data[1]['EndDate']}"
response = requests.put(endpoint, headers=headers, auth=auth, json=test_run_data)

# Check if the request was successful
if response.status_code == 200:  # HTTP 201 Created
    test_run = response.json()
    print(test_run)
    # if "TestRunId" in test_run:
    #     test_run_id = test_run["TestRunId"]
    #     print(f"Test run created successfully with ID: {test_run_id}")
    # else:
    #     print("Error: Test run ID not found in the response")
else:
    print(f"Error creating test run: {response.status_code} - {response.text}")
   Im quite new in this so the code must be improved a lot. I just want to make the test run first.     Thanks in advance,      Javier. </description><language>en-US</language><copyright>(C) Copyright 2006-2026 Inflectra Corporation.</copyright><managingEditor>support@inflectra.com</managingEditor><category domain="http://www.dmoz.org">/Computers/Software/Project_Management/</category><category domain="http://www.dmoz.org">/Computers/Software/Quality_Assurance/</category><generator>KronoDesk</generator><a10:contributor><a10:email>support@inflectra.com</a10:email></a10:contributor><a10:id>http://www.inflectra.com/kronodesk/forums/threads</a10:id><ttl>120</ttl><link>/Support/Forum/spirateam/issues-questions/2837.aspx</link><item><guid isPermaLink="false">threadId=2837</guid><author>Javier Quesada (javier.quesadagalban@gmail.com)</author><title>Problem with manual test run creation using REST</title><description> I am trying to create a test run using the rest api. After reading the documentation I have made a little code but I dont know what Im doing wrong because when I do the PUT, it doesnt work. I think it may be related to the dictionary that is sent in the request but Im not sure. The code is the following:   import requests
from datetime import datetime

# Set up the API endpoint URLs
api_url = "https://xyz.spiraservice.net/Services/v6_0/RestService.svc"
project_id = 9  # Replace with your project ID
release_id = 807

# Credentials and login
username = "xyz"
api_key = "{xyz-xyz-xyz-xyz-xyz}"
auth = (username, api_key)

# Petition header
headers = {
    "Content-Type": "application/json"
}

# Create a new test run shell dictionary
new_test_run = [2361]

# Construct the test run shell
test_run_create_endpoint = f"{api_url}/projects/{project_id}/test-runs/create?release_id={release_id}"

# Make a POST request to create the test run shell
response_post = requests.post(test_run_create_endpoint, headers=headers, auth=auth, json=new_test_run)

# Check if the request was successful
if response_post.status_code == 200:  # HTTP 201 Created
    test_run = response_post.json()
    print(test_run)
    # if "TestRunId" in test_run:
    #     test_run_id = test_run["TestRunId"]
    #     print(f"Test run created successfully with ID: {test_run_id}")
    # else:
    #     print("Error: Test run ID not found in the response")
else:
    print(f"Error creating test run: {response_post.status_code} - {response_post.text}")

# Update the test run 0001-01-01T00:00:00
test_run_data = [
    {"TestRunId": 0,},
    {"ExecutionStatusId" : 1},
    {"EndDate" : datetime.now().strftime("%Y-%m-%dT%H:%M:%S.000")}
]

endpoint = f"{api_url}/projects/{project_id}/test-runs?end_date={test_run_data[1]['EndDate']}"
response = requests.put(endpoint, headers=headers, auth=auth, json=test_run_data)

# Check if the request was successful
if response.status_code == 200:  # HTTP 201 Created
    test_run = response.json()
    print(test_run)
    # if "TestRunId" in test_run:
    #     test_run_id = test_run["TestRunId"]
    #     print(f"Test run created successfully with ID: {test_run_id}")
    # else:
    #     print("Error: Test run ID not found in the response")
else:
    print(f"Error creating test run: {response.status_code} - {response.text}")
   Im quite new in this so the code must be improved a lot. I just want to make the test run first.     Thanks in advance,      Javier. </description><pubDate>Wed, 09 Aug 2023 09:14:43 -0400</pubDate><a10:updated>2023-08-09T12:55:40-04:00</a10:updated><link>/Support/Forum/spirateam/issues-questions/2837.aspx</link></item><item><guid isPermaLink="false">messageId=6170</guid><author>David J (adam.sandman+support@inflectra.com)</author><title> Could you please log a help desk ticket with this?  In general for a PUT you need to first do  a GE</title><description> Could you please log a help desk ticket with this?  In general for a PUT you need to first do  a GET of the whole object, make any changes and then send the entire object back. You cannot just send back a partial fragment with a PUT.  Thanks  David </description><pubDate>Wed, 09 Aug 2023 12:55:40 -0400</pubDate><a10:updated>2023-08-09T12:55:40-04:00</a10:updated><link>/Support/Forum/spirateam/issues-questions/2837.aspx#reply6170</link></item></channel></rss>