Hey everyone,
I’m having trouble making a new ticket using the JIRA API. I’m trying to send a POST request with curl, but it’s not working right. Here’s what I’m doing:
curl -D- -u myuser:mypass -X POST --data myfile.json -H "Content-Type: application/json" https://myjira.example.com/rest/api/2/issue/
My JSON file (myfile.json) looks like this:
{
"fields": {
"project": {
"key": "MYPROJ"
},
"summary": "API Test Ticket",
"description": "Testing ticket creation via API",
"issuetype": {
"name": "Task"
}
}
}
But I’m getting a 400 Bad Request error. The response mentions something about an unrecognized token and expecting ‘null’, ‘true’, ‘false’ or NaN.
I’m pretty confused about what’s going wrong here. Has anyone run into this before or know what might be causing it? Any help would be awesome! Thanks!
hey mate, sounds like a real pain. have you tried using doublequotes instead of singlequotes for the curl command? sometimes that can mess things up. also, make sure there’s no extra spaces or weird characters in ur json file. those can trip up the api. good luck!
I’ve dealt with similar JIRA API issues before. One thing that often gets overlooked is proper encoding of the JSON data. Try using the --data-binary option instead of --data in your curl command. This ensures the JSON is sent exactly as-is without any processing.
Also, double-check your authentication. Make sure your user has the necessary permissions to create issues in that project. Sometimes, API access is restricted even if you can create tickets through the web interface.
Lastly, consider using the jq tool to validate and format your JSON before sending it. It can help catch syntax errors that might not be immediately obvious. If all else fails, JIRA’s server logs often contain more detailed error messages that can point you in the right direction.
From my experience, these issues can sometimes be traced back to formatting problems. I encountered a similar issue where hidden characters or formatting errors in the JSON file caused unexpected errors. It might be helpful to validate your file with an online tool to ensure there are no hidden characters or mistakes. Also, double-check that the JIRA instance URL, project key, and issue type are exactly what your instance expects. I found that simplifying the JSON to only the required fields and using tools like Postman to test the request can be very effective. I hope this helps narrow down the problem.