Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Zephyr - Need help with Attachment API

Deleted user April 16, 2015

Hi,

I have spent countless hours trying to get the Attachment Resource API(s) to work with no avail. I have referred to the docs here: http://docs.getzephyr.apiary.io/#executionresourceapis

However, the example really doesn't show how to attach the actual file. I am trying to use Postman to test this but ultimately I want to be able to use C# to attach a file to a test execution or test step.
 

Can anyone please provide me with an example of how to use this API in C# or even Postman. I have spent SO MUCH time on this and I cannot begin to explain my frustration smile I have been able to implement all the other Zephyr API's into my automation project, but this one is killing me.

In advance thanks so much for any help, you would be a life saver!!

Jared 

 

6 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Joseph Andrew Jaffey January 29, 2018

Hi..I too spent hours trying to figure this out using C# and RestSharp.  In the end it was a bug with the current version of RestSharp which was causing the issue.  To solve it I downloaded version 15.1 of RestSharp and using the following code was able to get attachments working.

I was attaching to the stepresults.  So I used for the entitiyId - the stepresultId, 

and for the entityType = "TESTSTEPRESULT";

Supposedly by my research only a minor tweak of one class of the current version of restsharp will solve the issue, and hopefully this will be looked at.

 

public static void ProcessGetAttachmentByEntityvi(RestClient client, TestCaseObject t)
{

var path = t.Attachmentloc;
byte[] bb = File.ReadAllBytes(path);
Image img = Image.FromFile(path);

var requestattachment = new RestRequest(Method.POST);
// requestattachment.Resource = "/rest/zapi/latest/attachment?entityId=" + exeid.ToString() + "&entityType=" + entityTypeEx; //execution
requestattachment.Resource = "/rest/zapi/latest/attachment?entityId=" + t.Testresultid + "&entityType=" + entityType;
requestattachment.RequestFormat = DataFormat.Json;
requestattachment.AddHeader("X-Atlassian-Token", "no-check");
requestattachment.AddHeader("Content-Type", "application/json");
requestattachment.AddFile("file", path, "multipart/form-data");

IRestResponse responseattachment = client.Execute(requestattachment);

}

0 votes
sachin shinde May 15, 2017

I am able to call Create Attachment using zephyr for JIRA cloud - http://docs.zfjcloud.apiary.io/#reference/attachment/create-attachment/create-attachment

This is working with Postman rest client.

But i need working C# code, i have tried many ways to call this api using code provided on apiary of zephyr for jira cloud, but it is not working.

Always end up with 500 - internal server error.

please reply..

 

sachin shinde May 16, 2017

Finally resolved with below C# code for attachments:

using (var content = new MultipartFormDataContent())
{
FileInfo fileInfo = new FileInfo(@"D:\Test_Img.png");
var fileContent = new StreamContent(fileInfo.OpenRead());
fileContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data")
{
Name = "\"attachment\"",
FileName = "\"" + fileInfo.Name + "\""
};
fileContent.Headers.ContentType = MediaTypeHeaderValue.Parse(MimeMapping.GetMimeMapping(fileInfo.Name));
content.Add(fileContent);
var result = httpClient.PostAsync(CONTEXT_PATH + RELATIVE_PATH + "?" + QUERY_STRING, content).Result;
Console.WriteLine(" \n" + result.Content.ReadAsStringAsync().Result);
Console.WriteLine(" \n" + result.ReasonPhrase.ToString());
}

 

0 votes
Deleted user May 12, 2015

Hello? 6 months after i first posted in the ZAPI documentation I can still not get any answer from support staff. smh

0 votes
Deleted user April 24, 2015

When i try this curl call i get unsupported media type which is not true because i can attach it though jira.

curl -D- -u user:pass -X POST -H "Content-Type: multipart/form-data" -H "X-Atlassian-Token: nocheck" -F "file=/home/jared/apiautomation/output.html" "https://url/rest/zapi/latest/attachment?entityId=3019&entityType=SCHEDULE&size=292983"

0 votes
Deleted user April 24, 2015

It has been 8 days since I posted this and 3 months since i posted the question in the ZAPI docs. Can anyone provide help?

0 votes
Deleted user April 16, 2015

I have also read https://answers.atlassian.com/questions/268253 this issue. The Curl example is helpful, but I really need a c# example. Please smile

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events