Using Personal Access Token to access issue in Jira Cloud (from CLI util)

Yes, that worked! I really appreciate your help @IbraheemOsama !

Here’s a working JavaScript (NodeJS) snippet to help other devs if they went astray like myself:

    console.log('Fetching issue with Scoped PAT (Personal Access Token) ');
    // Jira Cloud ID can be found by authenticated user at https://company.atlassian.net/_edge/tenant_info

    // From that point the URL should be constructed according to https://developer.atlassian.com/cloud/confluence/oauth-2-3lo-apps/#implementing-oauth-2-0--3lo-

    // According to doc https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issues/#api-rest-api-3-issue-issueidorkey-get permissions to read this resource:
    // either Classic (RECOMMENDED) read:jira-work
    // or Granular read:issue-meta:jira, read:issue-security-level:jira, read:issue.vote:jira, read:issue.changelog:jira, read:avatar:jira, read:issue:jira, read:status:jira, read:user:jira, read:field-configuration:jira
    const apiUrl = `https://api.atlassian.com/ex/jira/${cloudId}/rest/api/3/issue/${jiraKey}`;

    // Encode credentials for Basic Authentication header
    const credentials = `${username}:${token}`;
    const encodedCredentials = Buffer.from(credentials).toString('base64');
    const authHeader = `Basic ${encodedCredentials}`;

    // Define request headers
    const headers = {
        'Authorization': authHeader,
        'Accept': 'application/json; charset=utf-8',
        'Accept-Language': 'en-US,en;q=0.9' // without this I was getting errors in Chinese
    };

    console.log(`Loading Jira issue: ${jiraKey} from ${apiUrl}`);

    try {
        const response = await fetch(apiUrl, {
            method: 'GET',
            headers: headers,
        });

        if (response.ok) {
            // Assuming successful responses are JSON
            console.log(await response.json());
        } else {
            try {
                // Read the body as text first. This is robust for any content type.
                console.error(await response.json());
            } catch (e) {
                console.error("Response was unsuccessful, failed to parse error response.", e);
            }
        }
    } catch (e) {
        console.error("Failed to perform fetch.", e);
    }