Create HP QC Defect programmatically through Jenkins

Micro Focus Quality Center, formerly known as HP Quality Center is a quality management software. You can go through to find out the benefits provided by ALM QC

I had a requirement to create a QC defect through Jenkins, It was on old HP ALM environment when QC was not taken over by MicroFocus where I faced few issues which I was able to resolve.

I created a Jenkins Job and configured it as shown in below screenshots

I provided the xml input to my curl command which will create QC defect based on provided Jenkins parameters

After configuring the Job. Saved the Job and Triggered the job by ‘Build with Parameters’ option

Provided all the parameters

Build was completed and Verified the Console output

Now, the above can be considered as the happy path which will help you to create the QC defect programatically either by Jenkins or any other tools, but I found few issues when I was writing the code for the same and would like to share as it was quite interesting 🙂

Initially I followed the official guides and tried to authenticate :

curl -c qc_cookies -u admin:********  http://qcserver:8084/qcbin/authentication-point/authenticate

By which i was able to authenticate (tried in both browser and curl). To verify my authentication, I used 

curl --cookie cookies.txt --cookie-jar cookies.txt  http://localhost:8084/qcbin/rest/is-authenticated

It was showing the user name as part of authentication. So i was pretty sure my connection is established an i got the right cookies.

Then i tried to list out the defects – to do that i used :

curl --cookie cookies.txt --cookie-jar cookies.txt  http://qcserver:8084/qcbin/rest/domains/DOM/projects/PROJ/defects

but when you hit the api, the login was not remained authenticated and its asking for new login, which was not working and giving different errors, such as :

401 – with login not given

302 – since it was redirecting to login page

Then i checked the the 12.53 REST apis documentation : I got to know about one more term – Instead of using rest in URL – i tried with api

After reviewing it, I fired :

curl -c qc_cookies -u admin:******  http://qcserver:8084/qcbin/api/authentication-point/authenticate 

It prompted me to try with sign-in URL, then i changed my command

curl -c qc_cookies -u admin:********  http://qcserver:8084/qcbin/api/authentication/sign-in -v

I had then verified with

curl -b qc_cookies http://localhost:8084/qcbin/rest/is-authenticated

I had then lsited out the defetcs:

curl -b qc_cookies -c qc_cookies -H "Content-Type: application/json" -X GET http://qcserver:8084/qcbin/api/domains/DOM/projects/PROJ/defects

It has successfully shown the defetcs

But when i fired this create defect command it was throwing an error :

HTTP/1.1 415 Unsupported Media Type: "Id":"qccore.general-error","Title":"Unsupported Media Type"
curl -b qc_cookies -c qc_cookies -X POST -d @post-defect.json http://qcserver:8084/qcbin/rest/domains/DOM/projects/PROJ/defects/ -v

I found a nice explanation which states, It looks like the issue has to do with the difference between the Content-Type and Accept headers. In HTTP, Content-Type is used in request and response payloads to convey the media type of the current payload. Accept is used in request payloads to say what media types the server may use in the response payload.

So, having a Content-Type in a request without a body (like your GET request) has no meaning. When you do a POST request, you are sending a message body, so the Content-Type does matter.

If a server is not able to process the Content-Type of the request, it will return a 415 HTTP error. (If a server is not able to satisfy any of the media types in the request Accept header, it will return a 406 error.)

In OData v3, the media type “application/json” is interpreted to mean the new JSON format (“JSON light”). If the server does not support reading JSON light, it will throw a 415 error when it sees that the incoming request is JSON light. In your payload, your request body is verbose JSON, not JSON light, so the server should be able to process your request. It just doesn’t because it sees the JSON light content type.

I made few changes and tried with json and xml but it was not helping and even got 500 Error – then i made it in original form and changed the headers to show the odata verbose

curl -b qc_cookies -c qc_cookies -H "Accept: application/xml;odata=verbose" -H "Content-Type: application/xml" -X POST -d @post-defect.xml http://qcserver:8084/qcbin/rest/domains/DOM/projects/PROJ/defects

It was telling me what’s wrong with my provided json or xml and once i fixed it – I was able to create the defect and used correct syntax in my Jenkins job

Hope it helps …. Happy learning !!!

15 thoughts on “Create HP QC Defect programmatically through Jenkins”

    1. Hi Ranadip,
      Sorry for the delay.
      The above mentioned powershell scripts are just to create a input file based on the QC defect parameters and to display the output.
      The main script is the windows batch one :- please find below

      curl -c qc_cookies -u admin:%password% http://qcserver:8084/qcbin/api/authentication/sign-in

      curl -b qc_cookies -c qc_cookies -H “Accept: application/xml;odata=verbose” -H “Content-Type: application/xml” -X POST -d @temp.xml http://qcserver:8084/qcbin/rest/domains/DOM/projects/PROJ/defects -o curl_output

      Hope this helps!!

  1. Hi Ravi,

    Thnx for your reply.
    I understand your point.
    I actually need XML payload to create defect. As this solution already tested and working I don’t want to search and try same over internet :).


    1. Hi Ranadip,
      Thanks again but sorry, I don’t have that xml file with me. It was quite an old post and I had decommissioned that jenkins server long back.
      You may need to refer the screenshot and write it.

  2. Hi Ravi,

    Thnx. No issues.
    One more query – If I need to upload attachments also along with defects how can I do that via curl.


  3. Hi Ravi,
    I am using below curl commands to create defect in ALM for a specific project and release. But I am getting below error –
    Can you please check if I did any mistake –
    “Id”: “qccore.general-error”,
    “Title”: “Unsupported Media Type”,

    Sign In – curl -c qc_cookies -u xxxx:xxx http://xxxx/qcbin/api/authentication/sign-in -v
    Autheticate – curl -b qc_cookies http://xxxx/qcbin/rest/is-authenticated

    Create Defect –
    curl -b qc_cookies -c qc_cookies -H “Accept: application/xml;odata=verbose” -H “Content-Type: application/xml” -X POST -d @createdefect.xml http://xxxx/qcbin/api/domains/DEFAULT/projects/CIA_UAT_2020/defects -v

    Same Error is also coming in POSTMAN when I am testing that

    1. Hi Ranadip,

      I had highlighted this error in this article (in last steps), please check and see if it works for you. Usually its relevant to your json or xml.


      1. Hi Ravi,

        Its working now. But now facing different issue. I am using below payload create defect. But in ALM apart from below fields they have another mandatory fields. I am unable to find out exact Field Name for all of them, so can use those in XML. Do you have any clue for that where can I find out those names.






  4. Hi Ravi,

    I want to attach file with my defect. For that I got some clue in

    Here is the curl command –
    curl -X POST \
    -H “Content-Type: application/octet-stream” \
    -b cookies.txt \
    –data-binary @C:/my_files/my_uploaded_image.jpg \
    “http://:/api/shared_spaces//workspaces//attachments? \
    But what is and ?
    I believe is defect id.

Leave a Comment

Your email address will not be published. Required fields are marked *