Unknown field error when trying to set Service desk id and request type Id when creating issue Edited

I am trying to use C sharp code to create request in service desk and set the reqeust type value for service desk request using REST API, but getting unknown field error when trying to create a request in JIRA Service desk.

Below is the actual code which has the meta data to set the request type.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace JiraConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            Jira objJira = new Jira();
            objJira.JiraUrl = "https://xxxx.atlassian.net";

        
            objJira.JiraJson = @"{""fields"":{
                ""project"": {""key"": ""xxxx""},
                ""issuetype"": {""name"": ""Incident""},
                ""serviceDeskId"": ""1"",
                ""requestTypeId"": ""1"",
                ""requestFieldValues"": {
                    ""summary"": ""This is an automated ticket for Testing"",
                    ""description"": ""Test - ignore this""
                }
            }}";

            objJira.JiraUserName = "xxxxx";
            objJira.JiraPassword = "jkl;UIOP&*()";
            Console.WriteLine(objJira.addJiraIssue());
            Console.ReadKey();
        }
    }
}

We utilize the output from the above code to be parsed to the main jira.cs file in the below code.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MSXML2;

namespace JiraConsoleApp
{
    class Jira
    {
        public string JiraUserName { get; set; }
        public string JiraPassword { get; set; }
        public string JiraUrl { get; set; }
        public string JiraJson { get; set; }

        private XMLHTTP60 JiraService = new XMLHTTP60();

        public String addJiraIssue()
        {
            JiraService.open("POST", JiraUrl + "/rest/servicedeskapi/request/");
            JiraService.setRequestHeader("Content-Type", "application/json");
            JiraService.setRequestHeader("Accept", "application/json");
            JiraService.setRequestHeader("Authorization", "Basic " + GetEncodedCredentials());
            JiraService.setRequestHeader("X-Atlassian-Token", "no-check");
            JiraService.send(JiraJson);
            String response = JiraService.responseText;
            JiraService.abort();
            return response;
        }

        private string GetEncodedCredentials()
        {
            string mergedCredentials = string.Format("{0}:{1}", JiraUserName, JiraPassword);
            byte[] byteCredentials = UTF8Encoding.UTF8.GetBytes(mergedCredentials);
            return Convert.ToBase64String(byteCredentials);
        }
    }
}

 

Tried the same using REST client using the below JSON data but able to create request and set the request type.

We are using the POST operation as shown below
/rest/servicedeskapi/request

Body of the request.
{
"serviceDeskId": "1",
"requestTypeId": "1",
"requestFieldValues": {
"summary": "Request JSD help via REST1",
"description": "I need a new mouse for my Mac"
}
}

Please let me know whats the mistake in the csharp code in setiing the service desk and reqeust type.

0 answers

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Jun 14, 2018 in Jira Service Desk

How the Telegram Integration for Jira helps Sergey's team take their support efficiency to the bank

...+ reading Fantasy). The same is true for him at the bank he works for: Efficiency is key when time literally equals money. Read on to learn how Sergey makes most of the time he has by...

772 views 5 6
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you