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

How can I send solicitus Post in Jira, it always returns 400 error

Juan Francisco June 9, 2019

I try to send data with POST method to JIRA, but I get Error 400 in the UploadString () method.

The token is correct and the Json and tested in POSTMAN is OK, which is the problem?

I've been with this for several days and I can not solve it, could someone be kind enough to help me? Thank you

string json = @"{
                     'fields': {
                            'project': {
                                'key': 'EXAMPLE',
                                'projectTypeKey': 'service_exam'
                            },
                            'customfield_11283': {
                                'self': 'https://example.atlassian.net/rest/api/2/customFieldOption/14538',
                                'value': 'HELLO',
                                'id': '14538'
                            },
                            'issuetype': {
                                'self': 'https://example.atlassian.net/rest/api/2/issuetype/11835',
                                'id': '11835',
                                'description': '',
                                'name': 'EXTac',
                                'subtask': false
                            },
                            'summary': '-',
                            'customfield_10300': {
                                                'requestType': {
                                                    '_expands': [
                                                        'field'
                                                    ],
                                                    'id': '119',
                                                    '_links': {
                                                        'self': 'https://example.atlassian.net/rest/serviceexmapi/serviceexm/11/requesttype/119'
                                                    },
                                                    'name': 'ExmTick 40517',
                                                    'description': 'Register Peter Parker',
                                                    'helpText': '
                                                    'issueTypeId':'10835', 

                                                    'groupIds': [ '24' ]
                                                 }
                                            } 
                                }
                        }";

And mi code with the credentials in ATLASSIAN JIRA and the request is:

string jsonResponse = string.Empty;
    var userid = "user@example.com";
    var password = "QLodasdTCdt7Exampledsfsdf"; //no is real is example
    var endpoint = "https://example.atlassian.net/rest/api/2/issue?"; //no is real is example
    using (var client = new WebClient())
    {
        try
        {            client.Encoding = Encoding.UTF8;            client.Headers.Set("Authorization", "Basic " + GetEncodedCredentials(userid, password));            client.Headers.Add("Content-Type: application/json");            client.Headers.Add("Accept", "application/json");
            var uri = new Uri(endpoint);
            var response = client.UploadString(uri, "POST", json);            jsonResponse = response;
        }
        catch (WebException ex)
        {
            if (ex.Status == WebExceptionStatus.ProtocolError)
            {
                HttpWebResponse wrsp = (HttpWebResponse)ex.Response;
                var statusCode = (int)wrsp.StatusCode;
                var msg = wrsp.StatusDescription;
                throw new HttpException(statusCode, msg);
            }
            else
            {
                throw new HttpException(500, ex.Message);
            }
        }
    }
    return jsonResponse;
}

And the method for convert in UTF8 is:

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

 

1 answer

0 votes
Juan Francisco June 10, 2019

sorry, some administrator can move it to JIRA

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events