Read Jira Cloud users from a URL


Get Started

Not the template you're looking for? Browse more.

About the template


This template fetches users from a Jira Cloud instance, performs name based filtering when asked for, converts users into HTML and then sends it back with a HTTP response. This template demonstrates how a basic user interface can be built with ScriptRunner Connect by making use of Generic Event Listeners and by responding with HTML. Get started to learn more.

About ScriptRunner Connect


What is ScriptRunner Connect?

ScriptRunner Connect is an AI assisted code-first (JavaScript/TypeScript) integration platform (iPaaS) for building complex integrations and automations.

Can I try it out for free?

Yes. ScriptRunner Connect comes with a forever free tier.

Can I customize the integration logic?

Absolutely. The main value proposition of ScriptRunner Connect is that you'll get full access to the code that is powering the integration, which means you can make any changes to the the integration logic yourself.

Can I change the integration to communicate with additional apps?

Yes. Since ScriptRunner Connect specializes in enabling complex integrations, you can easily change the integration logic to connect to as many additional apps as you need, no limitations.

What if I don't feel comfortable making changes to the code?

First you can try out our AI assistant which can help you understand what the code does, and also help you make changes to the code. Alternatively you can hire our professionals to make the changes you need or build new integrations from scratch.

Do I have to host it myself?

No. ScriptRunner Connect is a fully managed SaaS (Software-as-a-Service) product.

What about security?

ScriptRunner Connect is ISO 27001 and SOC 2 certified. Learn more about our security.

Template Content


README

Scripts

TypeScriptOnGetUsersFromJiraHttpEvent
Sync HTTP Event

README


๐Ÿ“‹ Overview

This template fetches users from a Jira Cloud instance, performs name based filtering when asked for, converts users into HTML and then sends it back with a HTTP response. This template demonstrates how a basic user interface can be built with ScriptRunner Connect by making use of Generic Event Listeners and by responding with HTML.

๐Ÿ–Š๏ธ Setup

  • Configure Sync HTTP Event listener.

๐Ÿš€ Usage

Grab the URL that you should have received when setting up the Generic HTTP Event Listener, open that URL in your browser, after successful event processing you should see a basic table for listing users in Jira Cloud with an option to perform name based filtering.

API Connections


TypeScriptOnGetUsersFromJiraHttpEvent

import { HttpEventRequest, HttpEventResponse, buildHTMLResponse } from '@sr-connect/generic-app/events/http';
import JiraCloud from "./api/jira/cloud";

/**
 * This function fetches users from Jira Cloud, performs name based filtering when asked for, converts users into HTML and then sends it back with HTTP response.
 *
 * @param event Object that holds Sync HTTP Event event data
 * @param context Object that holds function invocation context data
 */
export default async function(request: HttpEventRequest): Promise<HttpEventResponse> {
    // Get users from Jira (result is paginated which we're not traversing right now)
    const users = await JiraCloud.User.getUsers();

    // Pick out only the fields we're interested in
    let filteredUsers = users.map(({ displayName, emailAddress, accountId, active }) => ({
        displayName,
        emailAddress,
        accountId,
        active
    } as User));

    // Try extracting search term from query params
    const searchTerm = request.queryStringParams.search ?? '';
    
    // If search term is found
    if (searchTerm) {
        // Then log it
        console.log(`Search term: ${searchTerm}`);

        // And perform additional filtering
        filteredUsers = filteredUsers.filter(u => u.displayName.toLowerCase().includes(searchTerm.toLowerCase()));
    }

    // Finally convert users into HTML output and return it
    return buildHTMLResponse(getHtml(filteredUsers, searchTerm));
}

function getHtml(users: User[], searchTerm: string) {
    return `
        <form>
            <label for="search">Search by name:</label>
            <input type="text" id="search" name="search" value="${searchTerm}">
            <input type="Submit" value="Search">
        </form>
        <table>
            <tr>
                <td>Display Name</td>
                <td>Email</td>
                <td>Account ID</td>
                <td>Active</td>
            </tr>
            ${users.map(getUserRow).join('\n')}
        </table>
    `;
}

function getUserRow({displayName, emailAddress, accountId, active}: User) {
    return `
        <tr>
            <td>${displayName}</td>
            <td>${emailAddress ?? ''}</td>
            <td>${accountId}</td>
            <td>${active}</td>
        </tr>
    `;
}

interface User {
    displayName: string;
    emailAddress?: string;
    accountId: string;
    active: boolean;
}
Documentation ยท Support ยท Suggestions & feature requests