//native
type Linode = {
token: string;
};
/**
* Create a support ticket attachment
* Adds a file attachment to an open support ticket on your account. Use an attachment to help customer support resolve your ticket. The file attachment is submitted in the request as `multipart/form-data` type. Accepted file extensions include: `.gif`, `.jpg`, `.jpeg`, `.pjpg`, `.pjpeg`, `.tif`, `.tiff`, `.png`, `.pdf`, or `.txt`.
>
---
- __OAuth scopes__.
```
account:read_write
```
[Learn more...](https://techdocs.akamai.com/linode-api/reference/get-started#oauth)
*/
export async function main(
auth: Linode,
apiVersion: "v4" | "v4beta",
ticketId: string,
body: { file: string },
) {
const url = new URL(
`https://api.linode.com/${apiVersion}/support/tickets/${ticketId}/attachments`,
);
const formData = new FormData();
for (const [k, v] of Object.entries(body)) {
if (v !== undefined && v !== "") {
formData.append(k, String(v));
}
}
const response = await fetch(url, {
method: "POST",
headers: {
Authorization: "Bearer " + auth.token,
},
body: formData,
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 235 days ago