JiraServiceDesk
The JiraServiceDesk class provides an interface to interact with Jira Service Desk customer requests via the Atlassian Service Desk REST API. This class is part of the
EncoreDigitalGroup\Atlassian\Services\Jira namespace and enables creating and retrieving Service Desk customer requests.
The Service Desk API uses different endpoints (/rest/servicedeskapi/*) compared to the standard Jira API (/rest/api/2/*), but authentication follows the same pattern
using basic auth with username/email and API token.
Available Methods
Below are the methods available in the JiraServiceDesk class:
Request Management
createRequest(ServiceDeskRequest $request): ServiceDeskRequestgetRequest(string $issueIdOrKey): ServiceDeskRequest
Customer Management
customers(): ServiceDeskCustomers- Returns a sub-resource for customer operations
The ServiceDeskCustomers sub-resource provides:
create(string $displayName, string $email, bool $strictConflictStatusCode = false): Customerlist(string $serviceDeskId, ?string $query = null, int $start = 0, int $limit = 50): PagedCustomerListadd(string $serviceDeskId, array $accountIds): voidremove(string $serviceDeskId, array $accountIds): voidrevokePortalAccess(string $accountId): void
Method Details
createRequest
Create a new Service Desk customer request in a Jira Service Desk project.
Parameters
ServiceDeskRequest $request: An instance of theServiceDeskRequestclass containing:serviceDeskId(required): The ID of the Service Desk (found in Service Desk settings)requestTypeId(required): The ID of the request type (found in request type configuration)requestFieldValues(required): Field values including at minimum the fields required by the request type (typically 'summary' and 'description')raiseOnBehalfOf(optional): Account ID of the user to create the request for (requires permission)
Return Value
Returns an instance of ServiceDeskRequest containing the created request with all server-populated fields including:
issueId: The numeric ID of the created issueissueKey: The issue key (e.g., 'SD-123')createdDate: The date/time the request was createdreporter: Information about the user who created the requestsla: Array of SLA information for the request
Example Usage
use EncoreDigitalGroup\Atlassian\Services\Jira\JiraServiceDesk;
use EncoreDigitalGroup\Atlassian\Services\Jira\Objects\ServiceDesk\ServiceDeskRequest;
// Create service instance
$service = JiraServiceDesk::make();
// Create a new request object
$request = new ServiceDeskRequest();
$request->serviceDeskId = '10';
$request->requestTypeId = '25';
// Set required field values
$request->requestFieldValues->setField('summary', 'Need help with login');
$request->requestFieldValues->setField('description', 'I cannot access my account');
// Set custom field values if needed
$request->requestFieldValues->setField('customfield_10001', 'High priority');
// Optional: raise request on behalf of another user
$request->raiseOnBehalfOf = '5b10a2844c20165700ede21g';
// Create the request
$created = $service->createRequest($request);
echo "Created request: {$created->issueKey}" . PHP_EOL;
echo "Reporter: {$created->reporter->displayName}" . PHP_EOL;
echo "Created: {$created->createdDate}" . PHP_EOL;
getRequest
Retrieve an existing Service Desk request by issue ID or key.
Parameters
string $issueIdOrKey: The issue ID (numeric, e.g., '10001') or issue key (e.g., 'SD-123')
Return Value
Returns an instance of ServiceDeskRequest containing all request data including field values, reporter information, SLA details, and metadata.
Example Usage
use EncoreDigitalGroup\Atlassian\Services\Jira\JiraServiceDesk;
$service = JiraServiceDesk::make();
// Retrieve by issue key
$request = $service->getRequest('SD-123');
// Retrieve by issue ID
$request = $service->getRequest('10001');
// Access request data
echo "Summary: " . $request->requestFieldValues->getField('summary') . PHP_EOL;
echo "Description: " . $request->requestFieldValues->getField('description') . PHP_EOL;
echo "Reporter: {$request->reporter->displayName}" . PHP_EOL;
echo "Email: {$request->reporter->emailAddress}" . PHP_EOL;
// Access custom fields
$customValue = $request->requestFieldValues->getField('customfield_10001');
echo "Custom field: {$customValue}" . PHP_EOL;
// Check SLA information
foreach ($request->sla as $sla) {
echo "SLA: {$sla->name} - Completed: " . ($sla->completedCycle ? 'Yes' : 'No') . PHP_EOL;
}
Customer Management
The JiraServiceDesk class provides comprehensive customer management capabilities through the customers() sub-resource. This allows you to create customers, list
them, add/remove them from service desks, and manage their access permissions.
customers
Access the customer management sub-resource.
Return Value
Returns an instance of ServiceDeskCustomers that provides all customer-related operations.
Example Usage
use EncoreDigitalGroup\Atlassian\Services\Jira\JiraServiceDesk;
$service = JiraServiceDesk::make();
// Access the customer management sub-resource
$customers = $service->customers();
Creating Customers
Create a new customer globally in your Jira instance.
Method Signature
create(string $displayName, string $email, bool $strictConflictStatusCode = false): Customer
Parameters
string $displayName(required): The display name for the customerstring $email(required): The email address for the customerbool $strictConflictStatusCode(optional): If true, returns 409 status code on conflict instead of 200 (default: false)
Permissions Required
- Jira Administrator global permission
Return Value
Returns a Customer object containing:
accountId: The Atlassian account IDname: The usernamekey: The customer key (deprecated by Atlassian)displayName: The display nameemailAddress: The email addressactive: Whether the account is activetimeZone: The user's timezonelinks: HAL links for the customer
Example Usage
use EncoreDigitalGroup\Atlassian\Services\Jira\JiraServiceDesk;
$service = JiraServiceDesk::make();
// Create a new customer
$customer = $service->customers()->create(
displayName: 'John Doe',
email: 'john.doe@example.com'
);
echo "Created customer: {$customer->displayName}" . PHP_EOL;
echo "Account ID: {$customer->accountId}" . PHP_EOL;
echo "Email: {$customer->emailAddress}" . PHP_EOL;
echo "Active: " . ($customer->active ? 'Yes' : 'No') . PHP_EOL;
// Create with strict conflict status code
$customer = $service->customers()->create(
displayName: 'Jane Smith',
email: 'jane.smith@example.com',
strictConflictStatusCode: true
);
Listing Customers
Retrieve a paginated list of customers for a specific service desk with optional filtering.
Method Signature
list(string $serviceDeskId, ?string $query = null, int $start = 0, int $limit = 50): PagedCustomerList
Parameters
string $serviceDeskId(required): The ID of the service deskstring $query(optional): Filter customers by name or email (default: null)int $start(optional): The starting index for pagination (default: 0)int $limit(optional): The maximum number of results per page (default: 50)
Return Value
Returns a PagedCustomerList object containing:
expands: The expands applied to the customer listsize: The number of items in this pagestart: The starting index of the pagelimit: The maximum number of items per pageisLastPage: Whether this is the last pagelinks: HAL links for pagination (base, context, next, prev)values: Array ofCustomerobjects
Example Usage
use EncoreDigitalGroup\Atlassian\Services\Jira\JiraServiceDesk;
$service = JiraServiceDesk::make();
// List all customers for a service desk
$customers = $service->customers()->list('10');
echo "Found {$customers->size} customers" . PHP_EOL;
echo "Is last page: " . ($customers->isLastPage ? 'Yes' : 'No') . PHP_EOL;
foreach ($customers->values as $customer) {
echo "- {$customer->displayName} ({$customer->emailAddress})" . PHP_EOL;
}
// Filter customers by query
$filtered = $service->customers()->list(
serviceDeskId: '10',
query: 'john'
);
// Paginate through results
$page1 = $service->customers()->list(
serviceDeskId: '10',
start: 0,
limit: 25
);
$page2 = $service->customers()->list(
serviceDeskId: '10',
start: 25,
limit: 25
);
Adding Customers to Service Desk
Add existing customers to a service desk, granting them access to submit requests.
Method Signature
add(string $serviceDeskId, array $accountIds): void
Parameters
string $serviceDeskId(required): The ID of the service deskarray $accountIds(required): Array of customer account IDs to add
Notes
- Duplicate account IDs are automatically removed
- The method returns void; no response is returned on success
- If a customer is already added to the service desk, they are ignored
Example Usage
use EncoreDigitalGroup\Atlassian\Services\Jira\JiraServiceDesk;
$service = JiraServiceDesk::make();
// Add single customer to service desk
$service->customers()->add('10', ['5b10a2844c20165700ede21g']);
// Add multiple customers
$service->customers()->add('10', [
'5b10a2844c20165700ede21g',
'5b10a2844c20165700ede22h',
'5b10a2844c20165700ede23i',
]);
// Duplicates are automatically removed
$service->customers()->add('10', [
'5b10a2844c20165700ede21g',
'5b10a2844c20165700ede21g', // Duplicate, will be ignored
'5b10a2844c20165700ede22h',
]);
Removing Customers from Service Desk
Remove customers from a service desk, revoking their access to submit requests.
Method Signature
remove(string $serviceDeskId, array $accountIds): void
Parameters
string $serviceDeskId(required): The ID of the service deskarray $accountIds(required): Array of customer account IDs to remove
Requirements
- The service desk must have closed access enabled
- You must have appropriate permissions to modify service desk customers
Notes
- Duplicate account IDs are automatically removed
- The method returns void; no response is returned on success
Example Usage
use EncoreDigitalGroup\Atlassian\Services\Jira\JiraServiceDesk;
$service = JiraServiceDesk::make();
// Remove single customer from service desk
$service->customers()->remove('10', ['5b10a2844c20165700ede21g']);
// Remove multiple customers
$service->customers()->remove('10', [
'5b10a2844c20165700ede21g',
'5b10a2844c20165700ede22h',
]);
Revoking Portal Access
Revoke portal-only access permission for a customer account.
Method Signature
revokePortalAccess(string $accountId): void
Parameters
string $accountId(required): The account ID of the customer
Notes
- This removes the portal-only access permission from a customer
- The method returns void; no response is returned on success
Example Usage
use EncoreDigitalGroup\Atlassian\Services\Jira\JiraServiceDesk;
$service = JiraServiceDesk::make();
// Revoke portal access for a customer
$service->customers()->revokePortalAccess('5b10a2844c20165700ede21g');
Complete Customer Management Example
Here's a complete example demonstrating all customer management operations:
use EncoreDigitalGroup\Atlassian\Services\Jira\JiraServiceDesk;
$service = JiraServiceDesk::make();
// 1. Create a new customer
$customer = $service->customers()->create(
displayName: 'John Doe',
email: 'john.doe@example.com'
);
echo "Created customer: {$customer->accountId}" . PHP_EOL;
// 2. Add customer to service desk
$service->customers()->add('10', [$customer->accountId]);
echo "Added customer to service desk" . PHP_EOL;
// 3. List all customers
$customers = $service->customers()->list('10');
echo "Total customers: {$customers->size}" . PHP_EOL;
// 4. Search for specific customers
$filtered = $service->customers()->list(
serviceDeskId: '10',
query: 'john'
);
foreach ($filtered->values as $customer) {
echo "Found: {$customer->displayName}" . PHP_EOL;
}
// 5. Remove customer from service desk
$service->customers()->remove('10', [$customer->accountId]);
echo "Removed customer from service desk" . PHP_EOL;
// 6. Revoke portal access
$service->customers()->revokePortalAccess($customer->accountId);
echo "Revoked portal access" . PHP_EOL;
Working with Field Values
The ServiceDeskRequestFieldValues object provides a flexible way to work with both standard and custom fields.
Setting Field Values (for Request Creation)
When creating a request, field values are sent as a simple object/map:
$request = new ServiceDeskRequest();
// Standard fields
$request->requestFieldValues->setField('summary', 'Request title');
$request->requestFieldValues->setField('description', 'Request description');
// Custom fields
$request->requestFieldValues->setField('customfield_10001', 'Value 1');
$request->requestFieldValues->setField('customfield_10002', 'Value 2');
Getting Field Values (from Response)
When retrieving a request, the API returns field values as an array of objects with fieldId, label, and value properties. The SDK automatically converts this to a
simple key-value format:
$summary = $request->requestFieldValues->getField('summary');
$customValue = $request->requestFieldValues->getField('customfield_10001');
// Returns null if field doesn't exist
$nonExistent = $request->requestFieldValues->getField('nonexistent'); // null
Note: The API response format differs from the request format:
- Request payload:
{"summary": "value", "description": "value"}(object/map) - Response payload:
[{"fieldId": "summary", "label": "...", "value": "..."}, ...](array of objects)
The SDK handles this conversion automatically.
Finding Service Desk and Request Type IDs
To use the createRequest method, you need to find the Service Desk ID and Request Type ID:
Service Desk ID
- Navigate to your Jira Service Desk project
- Go to Project Settings > Service Desk settings
- The Service Desk ID is displayed in the settings or can be found in the URL
Request Type ID
- In your Service Desk project, go to Project Settings > Request types
- Click on a request type to view its details
- The Request Type ID can be found in the URL or request type configuration
Alternatively, you can use the Atlassian API to programmatically retrieve these IDs:
- Service Desks:
GET /rest/servicedeskapi/servicedesk - Request Types:
GET /rest/servicedeskapi/servicedesk/{serviceDeskId}/requesttype
Handling Responses
ServiceDeskRequest Object
The ServiceDeskRequest object returned by both methods contains the following properties:
issueId: The numeric ID of the issueissueKey: The issue key (e.g., 'SD-123')serviceDeskId: The ID of the Service DeskrequestTypeId: The ID of the request typerequestFieldValues: AServiceDeskRequestFieldValuesobject containing all field valuesreporter: AServiceDeskRequestParticipantobject with user informationraiseOnBehalfOf: Account ID if the request was raised on behalf of another usercreatedDate: ISO 8601 formatted date stringsla: Array ofServiceDeskRequestSlaobjects
ServiceDeskRequestParticipant Object
The reporter information includes:
accountId: The Atlassian account IDname: The usernamedisplayName: The display nameemailAddress: The email addressactive: Whether the user is activetimeZone: The user's timezone
ServiceDeskRequestSla Object
SLA information includes:
id: The SLA IDname: The SLA name (e.g., 'Time to resolution')completedCycle: Whether the SLA cycle is completedremainingTime: Array with time information (millis, friendly format)
Configuration
Required Environment Variables
The JiraServiceDesk class requires the following configuration:
ATLASSIAN_HOSTNAME=https://your-domain.atlassian.net
ATLASSIAN_USERNAME=your-email@example.com
ATLASSIAN_TOKEN=your-api-token
Generating an API Token
- Visit https://id.atlassian.com/manage-profile/security/api-tokens
- Click "Create API token"
- Give it a descriptive name
- Copy the token and add it to your
.envfile
Permissions
Required Permissions
To use the Service Desk API, you need:
- Browse project permission for the Service Desk project
- Create issues permission to create requests
- Service Desk Agent role to raise requests on behalf of others
Raising Requests on Behalf of Others
To use the raiseOnBehalfOf parameter:
- You must have the Service Desk Agent role
- The user you're creating the request for must have permission to access the Service Desk
- Provide the Atlassian account ID (not username or email) in the
raiseOnBehalfOffield
Notes
- This class is marked as
@experimentaland@api, indicating that it is part of the public API but should be used with caution as it may be subject to changes. - Authentication is handled via basic auth using a username and API token, which are retrieved using the
AtlassianHelperclass. - Field validation is performed by the Jira Service Desk API. If required fields are missing or invalid values are provided, the API will return an error.
- Custom field IDs (e.g.,
customfield_10001) are specific to your Jira instance and can be found in the Jira field configuration.
API Reference
For more information about the Atlassian Service Desk REST API, see: