0

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.

1 Answers1

0

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.

Sergi
  • 990
  • 5
  • 16
  • I have implemented authentication logic separately and i didn't add that function here from where I'm setting cookings to each request, but that's not my question. Here you mentioned "/path/to/some.html" is that meaning the url of any file? So using above code **can we upload directly a file from URL to ALM? instead of again downloading file to local and then upload?** – Arunkumar G Dec 16 '22 at 16:49
  • I don't think that you can upload a file from the remote URL directly to ALM because of the nature of HTTP(s) requests - you have to add file content into your request body OR ALM API should be able to parse your request, get the URL and download that file using that URL, but I haven't seen anything in the documentation which makes me think it's possible – Sergi Dec 16 '22 at 19:10