# Snippets: search

> Oktul Code Studio script snippets for searching work items with JQL, copied from the console and run by its tests.
>
> Documentation for Oktul Code Studio, for Jira Cloud and Confluence Cloud, by Oktul: https://oktul.com/docs/plugins/code-studio/snippets/search/

These are the snippets the console's **Snippets** dialog offers under Search. Each is TypeScript; in a `.js` script the console shows the same code with its types removed. Every one runs unchanged in Code Studio's own tests. How the API they call behaves is in [writing scripts](../../writing-scripts/) and the [script API reference](../../script-api/).

## Search with JQL, every page

Reads every work item a JQL query finds, 100 at a time, following nextPageToken. Ask only for the fields you use: it keeps each page small.

```ts
interface Page {
    issues: { key: string; fields: { summary: string } }[];
    nextPageToken?: string;
}

export default async function () {
    const keys: string[] = [];
    let nextPageToken: string | undefined;
    do {
        const page: Page = await jira.post('/rest/api/3/search/jql', {
            jql: 'project = DEMO AND statusCategory != Done ORDER BY created DESC',
            fields: ['summary'],
            maxResults: 100,
            nextPageToken,
        });
        keys.push(...page.issues.map((issue) => issue.key));
        nextPageToken = page.nextPageToken;
    } while (nextPageToken);
    log.info(`Found ${keys.length} work items`);
    return { count: keys.length };
}
```

## Count what a JQL query finds

Asks Jira for an approximate count without reading a single work item.

```ts
export default async function () {
    const { count } = await jira.post<{ count: number }>('/rest/api/3/search/approximate-count', {
        jql: 'project = DEMO AND created >= -7d',
    });
    return { count };
}
```

## Related

- [Writing scripts](../../writing-scripts/)
- [Requests to other systems](../../requests-to-other-systems/)
- [Script examples](../../script-examples/)

---

A problem or a question? Write to [support@oktul.com](mailto:support@oktul.com) or open a request in the [Help Center](https://oktul.atlassian.net/servicedesk/customer/portals). Both reach the same service desk, so either way the request gets a reference and an SLA measuring the response.
