JIRA cloud rest API failing with error code 400

Hello Everyone,

I am new to JIRA cloud and I am trying to fetch the details from JIRA using rest API with C#. For authentication I am using basic authentication with API tokens.
But whatever I tried it always returns the 400 Bad request error. Can someone tell me what I am doing wrong in the following code?

        var url = new Uri("https://myJIRA.net/rest/");

        var httpClient = new HttpClient(new HttpClientHandler() { })
        {
            BaseAddress = url,
            Timeout = new TimeSpan(0, 2, 0)
        };

        var base64Credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes("myEmail@abc.com:API Token"));

        httpClient.DefaultRequestHeaders.Add("ContentType", "application/json");
        httpClient.DefaultRequestHeaders.Add("Authorization", "Basic " + base64Credentials);

        var result = await httpClient.GetAsync(”api/3/search?jql=project=TEST”);

        if (result.IsSuccessStatusCode)
        {
            var response = await result.Content.ReadAsStringAsync();
        }

Thank you,
Suhas

Hi @SuhasShirsat,

The /rest/api/3/search endpoint supports both GET and POST. With the caveat that I’m not familiar with C#, it looks like you’re trying to make a GET request, but maybe you’e actually making a POST request. What happens if you remove the ContentType header?

Regards,
Dugald

Hi @dmorrow ,

Yes its a get request and I am getting same 400 error if I remove the “ContentType” header.

Thank you,
Suhas

Hi @SuhasShirsat,

I’m guessing a little because I’m not familiar with C#, but maybe try URI encoding the JQL parameter.

Regards,
Dugald

Hi @SuhasShirsat,

Do you have any other API calls working or is it just this one that doesn’t work for you?

Regards,
Dugald

Hello @dmorrow,

None of them are working.

Thank you,
Suhas

Hi @SuhasShirsat,

Ah right, then you probably want to get some code working for simpler API calls and build up from there. Maybe see if you can call an API that doesn’t require any auth such as making a GET request to https://icanhazdadjoke.com/ to fetch a random dad joke. See https://icanhazdadjoke.com/api.

Regards,
Dugald

Hi @dmorrow,

You are right. The problem is not with the code or JIRA , Its due to some organizations security protocols that restricting my access when I am working remotely, otherwise it works fine.

Thank you for your time.

Regards,
Suhas