Forum Discussion

zeigerr's avatar
zeigerr
Occasional Contributor
3 years ago
Solved

Authentificate using a Token with curl.exe using ZAPI

Hi,

 

after using the JUnit import functionality in Zephyr Squad, I have to attach some log files as evidence to the executions created by the JUnit test result upload.

 

Since I am not a Java developer but more the scripting guy kind, I was looking for examples how to do this in the most direct way.

I found that this is e.g. for uploading an attachment this is to send a POST message to the Jira Server using the ZAPI REST API.

 

On Windows you can use for example curl.exe.

E.g. curl -D- -u MyUserID -X POST -H "X-Atlassian-Token: no-check" -F "file=@test_time.txt" https://jira-server.mycompany.es/rest/api/2/issue/ABC-11/attachments

 

Using a 20 line perl script I am able to for example, to retrieve the ids of the test executions via GET requests and then attach specific attachments as evidence to the executions. I have uploaded this script as "20211018_upload_attachments_wip.pl". The script is work in progress and only demonstrated that information can be retrieved via ZAPI API and attachments can be uploaded - nothing else.

I read that within the admin interface of the Zephyr Squad plugin it should be possible to generate an access key that can be used in scripts and can be assigned fine tunes access rights (similiar to github tokens). How can I generate these tokens? How can I use the token in curl.exe.

Thanks.

 

Best regards,

Raphael

  • We installed a newer version of Jira Squar, i.e. 6.2.4.

    Wit this version PATs are supported. Each user can create one and use ist e.g. via curl:

    curl -X GET -H "Authorization: Bearer <personal_access_token>" -H "Content-Type:multipart/form-data" https://jira-test.intern.hessen.de/rest/zapi/latest/cccccc?ddddd=eeeee


    On windows cammandline you have to escape "&" character via "^&".

     

     

3 Replies

  • zeigerr's avatar
    zeigerr
    Occasional Contributor

    Content of 20211018_upload_attachments_wip_pl.txt:

     

    use strict;
    use warnings;

    use Term::ReadKey;
    use JSON;
    use Data::Dumper;


    my $user = "USERID";

    print "Please supply password and press enter:\n";

    ReadMode('noecho');
    my $password = ReadLine(0);

    chomp $password;

    if ($password eq "") {
    print "No password supplied. Script will exit.\n";
    exit 1;
    }

    my $input_cycle = "1231233";

    my $response;

    $response = `curl -sS -u USERID:$password -X GET -H "X-Atlassian-Token: no-check" https://jira-test.mycompany.es/rest/zapi/latest/cycle?projectId=34234`;


    my $decoded_json;
    $decoded_json = decode_json($response);

    my $hr = $decoded_json->{234234}[0];

    ...


    #$response = `curl -sS -u USERID:$password -X POST -H "X-Atlassian-Token: no-check" -H "Content-Type:multipart/form-data" -F "file=\@C:\\Users\\ABC\\Desktop\\Work\\evidence.png" https://jira-test.mycompany.es/rest/zapi/latest/attachment?entityId=${last}&entityType=SCHEDULE`;

    print $response;

    • zeigerr's avatar
      zeigerr
      Occasional Contributor

      I like to use the the OAuth Athentification using curl. I.e. " curl -H "Authorization: OAuth <ACCESS_TOKEN>" ".

       

      What is the most straight forward way to generate such an Access Token under Win10.

      E.g. download an openssl binary run it with some parameters, Log into Zephyr webpage as admin and upload public key?

       

      Best regards,

      Raphael

      • zeigerr's avatar
        zeigerr
        Occasional Contributor

        We installed a newer version of Jira Squar, i.e. 6.2.4.

        Wit this version PATs are supported. Each user can create one and use ist e.g. via curl:

        curl -X GET -H "Authorization: Bearer <personal_access_token>" -H "Content-Type:multipart/form-data" https://jira-test.intern.hessen.de/rest/zapi/latest/cccccc?ddddd=eeeee


        On windows cammandline you have to escape "&" character via "^&".