Installation:
composer require bluetea/jira-rest-api-bundle dev-master
Add to AppKernel.php:
new Bluetea\JiraRestApiBundle\BlueteaJiraRestApiBundle(),
Configure:
Add to config.yml:
bluetea_jira_rest_api:
api_client: guzzle # or 'http' (default)
api:
jira: "https://your-domain.atlassian.net/rest/api/2/"
authentication:
jira:
type: basic
username: "%env(JIRA_USERNAME)%"
password: "%env(JIRA_API_TOKEN)%"
First Use Case:
Inject the jira_rest_api.jira.endpoint.project service in a controller or service:
use Symfony\Component\HttpFoundation\JsonResponse;
public function listProjects()
{
$projects = $this->get('jira_rest_api.jira.endpoint.project')->findAll();
return new JsonResponse($projects);
}
services.yml for tagged endpoints (e.g., jira_rest_api.jira.endpoint.*).Dependency Injection:
Use tagged services for endpoints (e.g., project, issue, user). Example:
$issueEndpoint = $this->get('jira_rest_api.jira.endpoint.issue');
$issues = $issueEndpoint->findAll(['jql' => 'project = TEST']);
Configuration-Driven:
Extend config.yml for multiple JIRA instances:
bluetea_jira_rest_api:
api:
jira_prod: "https://prod.atlassian.net/rest/api/2/"
jira_staging: "https://staging.atlassian.net/rest/api/2/"
authentication:
jira_prod: { type: basic, username: "%env(JIRA_PROD_USER)%", password: "%env(JIRA_PROD_TOKEN)%" }
jira_staging: { type: basic, username: "%env(JIRA_STAGING_USER)%", password: "%env(JIRA_STAGING_TOKEN)%" }
Access via:
$this->get('jira_rest_api.jira_prod.endpoint.project')->findAll();
Custom Endpoints: Extend the bundle to add missing endpoints (see underlying library for examples).
Error Handling: Wrap API calls in try-catch blocks:
try {
$issue = $issueEndpoint->get($issueId);
} catch (\Bluetea\JiraRestApiBundle\Exception\JiraRestApiException $e) {
$this->addFlash('error', $e->getMessage());
}
jira.api.response).$cache = $this->get('cache.app');
$key = 'jira_projects_' . md5($jql);
if (!$projects = $cache->get($key)) {
$projects = $projectEndpoint->findAll(['jql' => $jql]);
$cache->set($key, $projects, 3600);
}
Deprecated Bundle:
atlassian-php-sdk or php-jira.Authentication Quirks:
basic for most operations.Rate Limiting:
use Symfony\Component\HttpKernel\Exception\TooManyRequestsHttpException;
try {
$response = $endpoint->get($id);
} catch (TooManyRequestsHttpException $e) {
sleep(2 ** $retryCount); // Exponential backoff
$retryCount++;
retry();
}
Endpoint Limitations:
$client = $this->get('jira_rest_api.jira.client');
$response = $client->get('/rest/api/2/serverInfo');
Enable Debug Mode:
Set debug: true in config.yml to log API requests/responses:
bluetea_jira_rest_api:
debug: true
Guzzle Debugging: If using Guzzle, enable middleware for debugging:
$client = $this->get('jira_rest_api.jira.client');
$client->getEmitter()->attach(
new \GuzzleHttp\Middleware::tap(function ($request) {
error_log($request->getUri());
})
);
Common Errors:
/rest/api/2/ vs /rest/api/3/).Custom Services: Create a custom service to extend functionality:
# services.yml
services:
app.jira_custom_service:
class: App\Service\JiraCustomService
arguments:
- '@jira_rest_api.jira.client'
tags: ['jira.custom']
Override Configuration:
Use parameters.yml to override default values:
parameters:
bluetea_jira_rest_api.api.jira: "https://custom-jira.atlassian.net/rest/api/2/"
Add New Endpoints: Extend the bundle by creating a custom endpoint service:
// src/AppBundle/Service/JiraCustomEndpoint.php
class JiraCustomEndpoint {
private $client;
public function __construct($client) {
$this->client = $client;
}
public function customMethod() {
return $this->client->get('/rest/custom/endpoint');
}
}
Register in services.yml:
services:
app.jira.custom_endpoint:
class: App\Service\JiraCustomEndpoint
arguments: ['@jira_rest_api.jira.client']
How can I help you explore Laravel packages today?