Hello,
I have a php Project, this creates Jira Tickets over the API.
The authentification works with publickey and the atlassian OAuthWrapper class (https://bitbucket.org/atlassian_tutorial/atlassian-oauth-examples/src/default/php/src/Atlassian/OAuthWrapper.php).
The ticket creation works perfect on a Jira Development Instance but not on a productive cloud instance. On the productive instance, I get a 400 Bad Request answer.
The Source Code for the Request (shorted):
require_once __DIR__ . "libs/jira/vendor/autoload.php";
$oauth->setPrivateKey($pathToPrivateKey);
$oauth->setConsumerKey($jiraConsumerKey);
$oauth->setConsumerSecret($jiraConsumerSecret);
$oauth->setCallbackUrl(urlencode($appServerName . $appPath . "connect/callback/"));
$oauth->setRequestTokenUrl("plugins/servlet/oauth/request-token");
$oauth->setAuthorizationUrl("plugins/servlet/oauth/authorize?oauth_token=%s");
$oauth->setAccessTokenUrl("plugins/servlet/oauth/access-token");
$obj_request = $oauth->getClient($oauth_token, $auth_token_secret)
->post("rest/servicedeskapi/request", [
"Content-Type" => "application/json"
], json_encode([
serviceDeskId" => 16,
"requestTypeId" => 500,
"requestFieldValues" => [
"summary" => "SomeText",
"description" => "Ticket Discription"
]
]))->send()->json();
As written above, the 400 Bad Request happens only in productive not in the dev instance.
I hope somebody can help me with this problem.
Best regards
Oliver Hart
I have found the solution of my problem.
I have send
summary
description
but the Request Type has only the summary field and not the description field.
I have finally found the missing JSON Response. With Postman not with PowerShell.
I have saved the output and if you save the response it doesn't show up in the program.
I have to thanks @Alexey Matveev and @Payne for your ideas.
You're specifying project ID 16 and request type ID 500; are they the same in your 2 instances?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
No, the Development Instance has only 1 Project, only 3 Custom RequestTypes and some RequestTypes from Jira (ca. 19 Request Types at all)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
That may well be your problem; you're trying to create an issue in a non-existent project for a non-existent request type.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Unfortunately not. I get the IDs from the API.
API Call for all Servicedesks:
API Call for the Custom RequestTypes:
https://x.jira.com/rest/servicedeskapi/servicedesk/{servicedeskID}/requesttype
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello,
A json must be returned with the 400 error, in which you can see the exact error. Could you have a look what is inside this json?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello,
thanks for the quick answer.
I have exportet the Code in an own file and wrapped it in a try and catch statment (If I doesn't make the Try and Catch, I get a 500 Error because of the 400 Error) and made a Test run.
I also var_dump() the Exeption and got this:
string(129) "Client error response [status code] 400 [reason phrase] Bad Request [url] https://x.jira.com/rest/servicedeskapi/request"
I don't know if this helps, but I don't have something else.
Best regards
Oliver Hart
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I am not familiar with php. But there must be a more meaningful string in response.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello,
I have checked my Request with Postman and also with PowerShell "Invoke-WebRequest" Here are the specs
PowerShell:
$url = "https://x.jira.com/rest/servicedeskapi/request"
$header = @{"Authorization" = "Basic -base64string-";"X-Atlassian-Token" = "nocheck"}
$body = @"
{
"serviceDeskId":"16",
"requestTypeId":"500",
"requestFieldValues":{
"summary":"Summary Text",
"description":"Deesscription Text"
}
}
"@
$res = Invoke-WebRequest -Uri $url -Method Post -Body $body -Headers $header -ContentType "application/json"
Write-Output $res.StatusCode
PowerShell Output:
Invoke-WebRequest : The remote server returned an error: (400) Bad Request.
In line:16 Character:8
+ $res = Invoke-WebRequest -Uri $url -Method Post -Body $body -Headers ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequ
est], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequest
Command
Postman:
Authentification:
Headers:
Request-Body:
Response: (The Body is empty therefore I have the headers screenshotted)
--------------------------------------
This is all I get from the API
Best regards
Oliver Hart
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Try to install Rest Api Browser to your production instance and execute your rest call from there. It is a free add-on.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
There is only one Problem, the production instance is a jira-cloud instance and not a server instance. So this won't work.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Did you catch the news at Team ‘25? With Loom, Confluence, Atlassian Intelligence, & even Jira 👀, you won’t have to worry about taking meeting notes again… unless you want to. Join us to explore the beta & discover a new way to boost meeting productivity.
Register today!Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.