Hello there:
I’m trying to create a request using REST API for ServiceDesk, using Basic Auth (because I’m using a customer account). I was able to read issues, send comments, and even upload attachments, but when I try to send a new request, a “Bad Request” http error is sent back.
I’m using C#, and I’m using this model to send data:
public class NewRequestModel
{
public string serviceDeskId { get; set; }
public string requestTypeId { get; set; }
public Dictionary<string, object> requestFieldValues { get; set; }
}
Inside Dictionary, I’m adding a “summary” field, a “description” field and “customfield_11319” (I’ll explain later.
Then, I send the info using this code:
public async Task<RequestModel> SendIssueAsync(string serviceDeskToken, NewRequestModel requetsModel)
{
HttpResponseMessage response = null;
HttpClient client = new HttpClient
{
BaseAddress = new Uri("https://mycompany.atlassian.net")
};
HttpContent content;
string urlParams = "";
RequestModel modelo = null;
string tempString;
try
{
//Setting header as JSON
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
//Añadiendo Token a la cabecera
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", serviceDeskToken);
urlParams = serviceDeskRequestsUrl;
//Añadiendo datos al contenido
string jason = JsonConvert.SerializeObject(requetsModel, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });
content = new StringContent(jason, System.Text.Encoding.UTF8, "application/json");
//Envío del mensaje
response = await client.PostAsync(urlParams, content);
if (response.StatusCode == System.Net.HttpStatusCode.Created)
{
tempString = await response.Content.ReadAsStringAsync();
modelo = JsonConvert.DeserializeObject<RequestModel>(tempString);
}
}
catch (Exception)
{
throw;
}
return modelo;
}
Where “serviceDeskRequestUrl” is “/rest/servicedeskapi/request”.
I followed the guide in https://developer.atlassian.com/cloud/jira/service-desk/rest/api-group-request/#api-rest-servicedeskapi-request-post
Also, I was not sure that I sent all required data, so I made a request to “get request type fields”
https://developer.atlassian.com/cloud/jira/service-desk/rest/api-group-servicedesk/#api-rest-servicedeskapi-servicedesk-servicedeskid-requesttype-requesttypeid-field-get
“canRaiseOnBehalfOf” returns false, and “canAddRequestParticipants” returns false too. As for “requestTypeFields”, it tolds me that “summary” is required, and “customfield_11319” too (that’s why I added to the dictionary).
I tried any combination I can think of. I put all dictionary values as strings, and “customfield_11319” as an int, but always a BadRequest error.
Also, I tried to put Authorization header from basic to “Bearer”, as said in API, but sent me a “Unauthorized” http error (I expected that, because I’m using Basic Auth, not OAuth).
So, can someone figure it out what am I doing wrong?
Thank you!