Jira search API response doesn't match documentation

I am new to this API, so this might be user error. I am doing an issue search as per https://developer.atlassian.com/cloud/jira/platform/rest/v2/api-group-issue-search/#api-rest-api-2-search-post, but [tenant_url]/rest/api/2/search returns a 404. I am able to query https://api.atlassian.com/ex/jira/[cloud_id]/rest/api/2/ (found on the forum here) but the data is formatted very differently.

In the documentation, there is a “fields” property with “sub-tasks”, “issuelinks”, “attachment” and “comment” properties (all arrays), but in the response there is no “fields”. Rather, there is “subtasks” at the root (note the different spelling, too) alongside “issuelinks” but no “comment” or “attachment” property.

Any suggestions are appreciated. In particular, what type is this return format and why is the documented URL returning 404?

Welcome to the Atlassian developer community @DylanThorne,

I can’t reproduce your 404 problem on my instance. I am able to POST using an API token. And, even if I use a Bearer token (a la OAuth 2), then I get 403, not 404. I’m not sure why you are getting the 404. What is the auth mechanism you are using?

As for results, maybe you could post an example? I’m not sure I follow how it varies from the docs.

If you want specific fields to appear, you can ask for them in the request. For example, my query will only return summary:

{
	"jql": "parent = NGEW-10",
	"fields": [
		"summary"
	]
}

The result is:

{
	"expand": "schema,names",
	"startAt": 0,
	"maxResults": 50,
	"total": 2,
	"issues": [
		{
			"expand": "operations,versionedRepresentations,editmeta,changelog,renderedFields",
			"id": "10976",
			"self": "https://api.atlassian.com/ex/jira/c68adbe0-2b09-4add-b08e-eb5797b31bc9/rest/api/2/issue/10976",
			"key": "NGEW-12",
			"fields": {
				"summary": "Maggie"
			}
		},
		{
			"expand": "operations,versionedRepresentations,editmeta,changelog,renderedFields",
			"id": "10975",
			"self": "https://api.atlassian.com/ex/jira/c68adbe0-2b09-4add-b08e-eb5797b31bc9/rest/api/2/issue/10975",
			"key": "NGEW-11",
			"fields": {
				"summary": "Bart"
			}
		}
	]
}

Thanks for the advice. I am now using the Forge package to execute the fetch and it seems to match the documentation better. This is how I am performing the API queries:

import api from '@forge/api';

export const jiraClient = {
	queryUsers: async (apiMethod: string, httpMethod = 'GET') => {
		logger.trace('Enter: queryOne');

		const apiUrl = await getApiUrl();
		const url = new URL(apiMethod, apiUrl);

		const token = await getAccessToken();
		if (!token) throw Error('No access token');

		const init = {
			headers: {
				Authorization: `Bearer ${token}`,
				Accept: 'application/json',
				'Content-Type': 'application/json',
			},
			method: httpMethod,
		};

		const response = await api.fetch(url.href, init);
		const result = await response.json();

		logger.info(`Exit: queryApi`);

		return result;
	},
	queryIssues: async (method: string, httpMethod = 'POST') => {
		logger.trace('Enter: queryForge');

		const apiUrl = await getApiUrl();
		const url = new URL(method, apiUrl);

		const token = await getAccessToken();
		if (!token) throw Error('No access token');

		let startAt = 0;
		const init = {
			headers: {
				Authorization: `Bearer ${token}`,
				Accept: 'application/json',
				'Content-Type': 'application/json',
			},
			method: httpMethod,
			body:
				httpMethod === 'POST'
					? JSON.stringify({
							startAt,
							fields: ['*all'],
					  })
					: undefined,
		};
		const results = [];
		let hasMore = false;
		do {
			const response = await api.fetch(url.href, init);
			const result = await response.json();
			results.push(...result.issues);

			startAt += result.issues.length;
			init.body = JSON.stringify({ startAt, fields: ['*all'] });

			logger.info(`${startAt} results (cumulative)`);

			hasMore = hasMoreResults(result);
		} while (hasMore);

		logger.info(`${results.length} results`);
		logger.info(`Exit: queryApi`);

		return results;
	},
};