Search code examples
python-3.xrestpython-requestsalmhp-alm

HP ALM API : Attaching file to run step through ALM REST API not working


We have fetched Run Steps details using ALM REST API. (for reference ALM API Documentation

Same question is being asked in ALM community, Community Microfocus ALM

https://some.almserver.com/qcbin/rest/domains/DOMAIN/projects/PROJECT/runs/<run-id>/run-steps

and passed Run Step id to below API and tried to attach file using POST and PUT.

https://some.almserver.com/qcbin/rest/domains/DOMAIN/projects/PROJECT/runs/<run-id>/run-steps/<run-step-ID>/attachments

we are getting 404 response. Bad request.

URL =  "https://some.almserver.com/qcbin/rest/domains/DOMAIN/projects/PROJECT/runs/<run-id>/run-steps/<step-id>/attachments"

METHOD = "PUT"

HEADERS = {

    'cache-control': "no-cache",

    "Slug": "some.html",

    'Content-Type': "application/octet-stream"

}

 

def attach_to_run_step():

    f = open("/path/to/some.html", "rb")

    response = requests.put(URL, headers=HEADERS, cookies=cookies, data=f.read())

    print(response.content)

Expected : 200 response Actual : 404 status code


Solution

  • I think you need to use the following URL for your POST request: https://some.almserver.com/qcbin/rest/domains/DOMAIN/projects/PROJECT/run-steps/<run-step-id>/attachments (remove /runs/<run-id>)

    Update:

    Here is an example, generated from Postman:

    import requests
    
    url = "http://xxx.xxx.xxx.xxx:8080/qcbin/rest/domains/DEFAULT/projects/demo/run-steps/1263/attachments"
    
    payload="<file contents here>"
    headers = {
      'Content-Type': 'application/octet-stream',
      'Slug': '1.jpg',
      'Cookie': 'JSESSIONID=<session>; ALM_USER=2e69...; LWSSO_COOKIE_KEY=PTKYM...; QCSession=MTQwM...; XSRF-TOKEN=3dfa4...'
    }
    
    response = requests.request("POST", url, headers=headers, data=payload)
    
    print(response.text)
    

    P.S. We are developing commercial platform for integrating various test frameworks with ALM, which is called Agiletestware Bumblebee, so you might want to have a look at it.