chobie / jira-api-restclient

php JIRA REST API
MIT License
218 stars 123 forks source link

Create Project? #156

Closed benjivm closed 7 years ago

benjivm commented 7 years ago

Is it possible to create a new project using this package? I can't seem to find a method to do so anywhere.

aik099 commented 7 years ago

There is no shortcut method for that, but you can easily make necessary call yourself like so:

use chobie\Jira\Api;

$api = new ...Api(...);

$result = $api->api(
    Api:: REQUEST_POST,
    '/rest/api/2/project',
    array(...)
);
benjivm commented 7 years ago

@aik099 Thanks, I believe I did something similar using Guzzle, I was not aware that invoking the $api>api() method would allow me to interact directly with all available JIRA REST API functionality, that's cool.

Here's what I did with Guzzle, though I am going to refactor to your solution:

$client = new GuzzleHttp\Client([
    'base_uri' => config('app.jira_url'),
    'auth' => [
        'username',
        'password',
    ],
]);

$properties = json_encode([
    'key' => $project_key,
    'name' => $name,
    'projectTypeKey' => 'software',
    'description' => $description,
    'lead' => 'daves',
    'assigneeType' => 'UNASSIGNED',
]);

return $client->request('POST', '/rest/project-templates/1.0/createshared/10331', [
    'headers' => ['Content-Type' => 'application/json', 'Accept' => 'application/json'],
    'body' => $properties,
]);
aik099 commented 7 years ago

If you'd like you can submit a PR with new createProject method and tests for it.