nepda/youtrack-client

Create Issue Error

jeroentiem opened this issue · 7 comments

Hi,

Great library.

All the get functions are working, i also can update comments, but i can't create a new issue on a project.
This error is shown:

Fatal error: Uncaught YouTrack\Exception: Error for 'https://....myjetbrains.com/youtrack/rest/issue?priority=Higher&type=Auto-reported+CLI+exception&description=The+full+text+issue+description&project=Sandbox&summary=Create+a+basic+issue+for+example': 400 in ../vendor/nepda/youtrack-client/YouTrack/Connection.php:349 Stack trace: #0 ..vendor/nepda/youtrack-client/YouTrack/Connection.php(513): YouTrack\Connection->request('POST', 'https:...', NULL) #1 ../vendor/nepda/youtrack-client/examples/create-simple-issue.php(18): YouTrack\Connection->createIssue('Sandbox', 'Create a basic ...', Array) #2 {main} thrown in ../vendor/nepda/youtrack-client/YouTrack/Connection.php on line 349

Best regards,

Jeroen

nepda commented

Please try to generate the issue with a try-catch block:

try {
    $issue = $youtrack->createIssue('Sandbox', 'Create a basic issue for example');

    if ($issue) {
        printf('Issue %s created' . PHP_EOL, $issue->getId());
    }
} catch (\YouTrack\NotAuthorizedException $e) {
    echo 'Caught a not authorized exception: ' . $e->getMessage() . PHP_EOL;
    var_dump($e->getYouTrackError());
} catch (\YouTrack\IncorrectLoginException $e) {
    echo 'Caught a incorrect login exception: ' . $e->getMessage() . PHP_EOL;
    var_dump($e->getYouTrackError());
} catch (\YouTrack\NotFoundException $e) {
    echo 'Caught a not found exception: ' . $e->getMessage() . PHP_EOL;
    var_dump($e->getYouTrackError());
} catch (\YouTrack\Exception $e) {
    echo 'Caught a generic YouTrack exception: ' . $e->getMessage() . PHP_EOL;
    var_dump($e->getYouTrackError());
}

And post the output. Inside the $e->getYouTrackError() there should be information about the cause of the error.

Generally the HTTP-status code 400 stands for Bad Request.

400 bad request.

If i change the body in Connections.php it's working:

if (empty($body)) {
//$body = null;
$body = array("test" => "test");
}

nepda commented

I'm not able to reproduce this. I can successfully create a simple issue with $body == null.

Please post your $youtrack->createIssue() line.

Otherwise I would close this issue.

Thanks for you support.

$params = array(
'priority' => 'Higher',
'type' => 'Task',
'description' => "testing",
);
$issue = $youtrack->createIssue('Sandbox', 'Create', $params);

nepda commented

You're welcome.
Unfortunately I'm not able to reproduce. My output for this call is as expected:

Issue Sandbox-4247 created

May be you can post your plain response XML from YouTrack (remove your personal URL, username etc.)

Just var_dump the response in YouTrack/Connection.php:337

        $content = curl_exec($this->http);
        $response = curl_getinfo($this->http);
        curl_close($this->http);
        var_dump($content);

Caught a generic YouTrack exception: Error for 'https://....myjetbrains.com/youtrack/rest/issue?priority=Higher&type=Task&description=testing&project=Sandbox&summary=Create': 400 NULL

If i change the body it works so i can proceed, thanks for your support. Is it possible to domate?

nepda commented

Thanks. It's a free time project. No donation is required/necessary. Just stay tuned and mark this library with a GitHub-Star :).

Consider donating to another great project or organisation ;)