Set app property

Sets the value of an app's property. Use this resource to store custom data for your app. The value of the request body must be a [valid](http://tools.ietf.org/html/rfc4627), non-empty JSON blob. The maximum length is 32768 characters. **[Permissions](#permissions) required:** Only a Connect app whose key matches `addonKey` can make this request. Additionally, Forge apps can access Connect app properties (stored against the same `app.connect.key`).

Script jira Verified

by hugo697 ยท 11/2/2023

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 396 days ago
1
type Jira = {
2
  username: string;
3
  password: string;
4
  domain: string;
5
};
6
/**
7
 * Set app property
8
 * Sets the value of an app's property. Use this resource to store custom data for your app.
9

10
The value of the request body must be a [valid](http://tools.ietf.org/html/rfc4627), non-empty JSON blob. The maximum length is 32768 characters.
11

12
**[Permissions](#permissions) required:** Only a Connect app whose key matches `addonKey` can make this request.
13
Additionally, Forge apps can access Connect app properties (stored against the same `app.connect.key`).
14
 */
15
export async function main(
16
  auth: Jira,
17
  addonKey: string,
18
  propertyKey: string,
19
  body: { [k: string]: unknown }
20
) {
21
  const url = new URL(
22
    `https://${auth.domain}.atlassian.net/rest/atlassian-connect/1/addons/${addonKey}/properties/${propertyKey}`
23
  );
24

25
  const response = await fetch(url, {
26
    method: "PUT",
27
    headers: {
28
      "Content-Type": "application/json",
29
      Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
30
    },
31
    body: JSON.stringify(body),
32
  });
33
  if (!response.ok) {
34
    const text = await response.text();
35
    throw new Error(`${response.status} ${text}`);
36
  }
37
  return await response.json();
38
}
39