Created
November 14, 2025 15:27
-
-
Save WoLfulus/2b8738b4fddb88190a41f48985aaa29c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import * as https from 'https'; | |
| interface Config { | |
| domain: string; | |
| email: string; | |
| apiToken: string; | |
| } | |
| interface ServiceDesk { | |
| id: string; | |
| projectId: string; | |
| projectName: string; | |
| projectKey: string; | |
| } | |
| interface RequestType { | |
| id: string; | |
| name: string; | |
| description: string; | |
| helpText: string; | |
| } | |
| interface Field { | |
| fieldId: string; | |
| name: string; | |
| description: string; | |
| required: boolean; | |
| validValues?: Array<{ value: string; label: string }>; | |
| jiraSchema?: { | |
| type: string; | |
| system?: string; | |
| }; | |
| } | |
| class JiraServiceDeskClient { | |
| private domain: string; | |
| private authHeader: string; | |
| constructor(config: Config) { | |
| this.domain = config.domain; | |
| const credentials = Buffer.from(`${config.email}:${config.apiToken}`).toString('base64'); | |
| this.authHeader = `Basic ${credentials}`; | |
| } | |
| private async request<T>(path: string): Promise<T> { | |
| return new Promise((resolve, reject) => { | |
| const options = { | |
| hostname: this.domain, | |
| path: path, | |
| method: 'GET', | |
| headers: { | |
| 'Authorization': this.authHeader, | |
| 'Content-Type': 'application/json', | |
| 'Accept': 'application/json' | |
| } | |
| }; | |
| const req = https.request(options, (res) => { | |
| let data = ''; | |
| res.on('data', (chunk) => { | |
| data += chunk; | |
| }); | |
| res.on('end', () => { | |
| if (res.statusCode && res.statusCode >= 200 && res.statusCode < 300) { | |
| try { | |
| resolve(JSON.parse(data)); | |
| } catch (e) { | |
| reject(new Error(`Failed to parse JSON: ${e}`)); | |
| } | |
| } else { | |
| reject(new Error(`HTTP ${res.statusCode}: ${data}`)); | |
| } | |
| }); | |
| }); | |
| req.on('error', (e) => { | |
| reject(e); | |
| }); | |
| req.end(); | |
| }); | |
| } | |
| async listServiceDesks(): Promise<ServiceDesk[]> { | |
| const response = await this.request<{ values: ServiceDesk[] }>( | |
| '/rest/servicedeskapi/servicedesk' | |
| ); | |
| return response.values; | |
| } | |
| async listRequestTypes(serviceDeskId: string): Promise<RequestType[]> { | |
| const response = await this.request<{ values: RequestType[] }>( | |
| `/rest/servicedeskapi/servicedesk/${serviceDeskId}/requesttype` | |
| ); | |
| return response.values; | |
| } | |
| async getRequestTypeFields(serviceDeskId: string, requestTypeId: string): Promise<Field[]> { | |
| const response = await this.request<{ requestTypeFields: Field[] }>( | |
| `/rest/servicedeskapi/servicedesk/${serviceDeskId}/requesttype/${requestTypeId}/field` | |
| ); | |
| return response.requestTypeFields; | |
| } | |
| } | |
| async function main() { | |
| const config: Config = { | |
| domain: 'yourcompany.atlassian.net', | |
| email: '[email protected]', | |
| apiToken: 'your-api-token-here' | |
| }; | |
| console.log(' Jira Service Desk Inspector\n'); | |
| console.log(`Domain: ${config.domain}\n`); | |
| const client = new JiraServiceDeskClient(config); | |
| try { | |
| // List all Service Desks | |
| console.log(' Fetching Service Desks...\n'); | |
| const serviceDesks = await client.listServiceDesks(); | |
| if (serviceDesks.length === 0) { | |
| console.log('No service desks found.'); | |
| return; | |
| } | |
| for (const sd of serviceDesks) { | |
| console.log('═══════════════════════════════════════════════════════════'); | |
| console.log(` Service Desk: ${sd.projectName} (${sd.projectKey})`); | |
| console.log(` ID: ${sd.id}`); | |
| console.log(` Project ID: ${sd.projectId}`); | |
| console.log('───────────────────────────────────────────────────────────'); | |
| // List Request Types for this Service Desk | |
| const requestTypes = await client.listRequestTypes(sd.id); | |
| if (requestTypes.length === 0) { | |
| console.log(' No request types found.\n'); | |
| continue; | |
| } | |
| for (const rt of requestTypes) { | |
| console.log(`\n 📝 Request Type: ${rt.name}`); | |
| console.log(` ID: ${rt.id}`); | |
| if (rt.description) { | |
| console.log(` Description: ${rt.description}`); | |
| } | |
| // Get Fields for this Request Type | |
| try { | |
| const fields = await client.getRequestTypeFields(sd.id, rt.id); | |
| if (fields.length > 0) { | |
| console.log(`\n Fields:`); | |
| for (const field of fields) { | |
| console.log(` - ${field.name} (${field.fieldId})`); | |
| console.log(` Required: ${field.required ? '✓' : '✗'}`); | |
| if (field.jiraSchema) { | |
| console.log(` Type: ${field.jiraSchema.type}`); | |
| } | |
| if (field.description) { | |
| console.log(` Description: ${field.description}`); | |
| } | |
| if (field.validValues && field.validValues.length > 0) { | |
| console.log(` Valid Values: ${field.validValues.map(v => v.label).join(', ')}`); | |
| } | |
| } | |
| } | |
| } catch (error) { | |
| console.log(` Could not fetch fields: ${error}`); | |
| } | |
| } | |
| console.log('\n'); | |
| } | |
| console.log('Inspection complete!\n'); | |
| } catch (error) { | |
| console.error('Error:', error); | |
| process.exit(1); | |
| } | |
| } | |
| // Run the script | |
| main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment