Home > OS >  Unable to find a way to upload attachments using URL to ALM via REST API
Unable to find a way to upload attachments using URL to ALM via REST API

Time:12-18

I have a way to attach file as binary to ALM using REST API

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

METHOD = "POST"

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.post(URL, headers=HEADERS, cookies=cookies, data=f.read())

    print(response.content)

I couldn't find any way to upload attachments which are in url format (from X website to ALM directly using REST) But from ALM UI, we have option to upload attachment using URL.

Expecting METHOD, HEADERS, Request payload to upload url to ALM.

CodePudding user response:

You need to authenticate and get the ALM session before trying to do anything else.
Check out the Documentation for details.

Here is a sample code (sorry I'm not a Python guy, but it works):

import requests
session = requests.session()
response = session.post("http://xxx.xxx.xxx.xxx:8080/qcbin/authentication-point/alm-authenticate", headers={
    'Content-Type': 'application/xml'
}, data="<alm-authentication><user>user</user><password>password</password></alm-authentication>")

response = session.post("http://xxx.xxx.xxx.xxx:8080/qcbin/rest/site-session")

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

headers = {
    'Content-Type': 'application/octet-stream',
    'Slug': 'some.html'
}
response = session.post("http://xxx.xxx.xxx.xxx:8080/qcbin/rest/domains/DEFAULT/projects/demo/run-steps/1263/attachments", headers=headers, data=file.read())
print(response.text)

Just replace user, password and run-step ID with your own.

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.

  • Related