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 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
Community moderators have prevented the ability to post new answers.
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);
}
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..
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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());
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Community moderators have prevented the ability to post new answers.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.