Upload a file for a ticket message
/v1/tickets/uploads Uploads a file to send with a message: send its bytes as the body, with Content-Type: application/octet-stream and its size in Content-Length (400 length_required without it), and its name in filename. Then name its id in fileIds when you open a ticket or reply.
Screenshots (PNG, JPEG, GIF or WebP), PDFs and text files named .txt or .log, up to 10 MB each (413 payload_too_large). What a file is comes from its bytes, not its name (422 unsupported_file). An upload not sent with a message within a day is removed; up to 20 can wait at once (409 too_many_uploads), and up to 60 can be made an hour (429 rate_limited). Location is the upload's address, to remove it. An Idempotency-Key is accepted, but an upload's answer isn't kept: a key can be sent again once its upload has finished.
Time. The whole upload must arrive within 5 minutes of the request's start: a slower one is cut off (the connection is closed, often with a plain 408 that isn't JSON), and nothing is kept.
Scopes
The token needs this scope. Without it, the request is refused with insufficient_scope (see Scopes).
-
support:write - Open and answer tickets. Open support tickets and reply to them.
Headers
| Field | Type and description |
|---|---|
Idempotency-Key | string 1 to 255 characters A key of your own for this request, like a UUID: letters, digits and |
Query parameters
| Field | Type and description |
|---|---|
filename Required | string 1 to 200 characters The file's name, like |
Request body
The file itself, as the request's raw body, with Content-Type: application/octet-stream.
Example request
curl -X PUT "https://api.rabbitflare.com/v1/tickets/uploads?filename=checkout-error.png" \
-H "Authorization: Bearer $RABBITFLARE_TOKEN" \
-H "Content-Type: application/octet-stream" \
--data-binary "@upload.bin" import { readFile } from "node:fs/promises";
const res = await fetch("https://api.rabbitflare.com/v1/tickets/uploads?filename=checkout-error.png", {
method: "PUT",
headers: {
Authorization: `Bearer ${process.env.RABBITFLARE_TOKEN}`,
"Content-Type": "application/octet-stream",
},
body: await readFile("upload.bin"),
});
if (!res.ok) throw new Error(`Rabbitflare API error ${res.status}: ${await res.text()}`);
const { data } = await res.json();
console.log(data); import { readFile } from "node:fs/promises";
import { Rabbitflare } from "@rabbitflare/api";
const rf = new Rabbitflare({ token: process.env.RABBITFLARE_TOKEN });
const data = await rf.tickets.uploads.create({
filename: "checkout-error.png",
body: await readFile("upload.bin"),
});
console.log(data); <?php
$ch = curl_init('https://api.rabbitflare.com/v1/tickets/uploads?filename=checkout-error.png');
curl_setopt_array($ch, [
CURLOPT_CUSTOMREQUEST => 'PUT',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 360,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . getenv('RABBITFLARE_TOKEN'),
'Content-Type: application/octet-stream',
],
CURLOPT_POSTFIELDS => file_get_contents('upload.bin'),
]);
$body = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
if ($body === false || $status >= 400) {
throw new RuntimeException("Rabbitflare API error $status: $body");
}
print_r(json_decode($body, true)['data']); import os
import requests
response = requests.put(
"https://api.rabbitflare.com/v1/tickets/uploads",
headers={
"Authorization": "Bearer " + os.environ["RABBITFLARE_TOKEN"],
"Content-Type": "application/octet-stream",
},
params={
"filename": "checkout-error.png",
},
data=open("upload.bin", "rb"),
timeout=360,
)
response.raise_for_status()
print(response.json()["data"]) Response
201 Created Returns the TicketFile object in data.
The TicketFile object's fields 4 fields
| Field | Type and description |
|---|---|
id | string The file's id: what |
filename | string The file's name, as it's downloaded. |
contentType | string The file's type, found from its bytes: a PNG, JPEG, GIF or WebP picture, a PDF, or plain text. Known values: |
sizeBytes | integer The file's size, in bytes. |
Example response
{
"data": {
"id": "5e6f7a8b-9c0d-4e1f-a2b3-c4d5e6f7a8b9",
"filename": "checkout-error.png",
"contentType": "image/png",
"sizeBytes": 184320
}
} Errors
The errors this request can answer besides those every request can (a missing token, a missing scope, the rate limits). Each answer is an Error object (see Errors).
| Status and code | When, and what to do |
|---|---|
400 invalid_ | A query parameter is unknown or has a wrong value ( Correct or remove the parameter named in |
400 length_ | An upload was sent without a Content-Length header. Send the file's size in Content-Length. |
409 too_ | Twenty uploads already wait to be sent with a message. Send them with a message, or remove the ones you don't need (DELETE /v1/tickets/uploads/{uploadId}). Uploads not sent within a day are removed. |
409 attachments_ | Files can't be attached right now. Describe the problem in words, or try again later. |
413 payload_ | The body is larger than the operation accepts (1 MB for JSON). Send less data; uploads have their own limit. |
413 file_ | The file is larger than one attachment may be (10 MB). Send a smaller file. |
415 unsupported_ | The body isn't sent as application/json (or application/octet-stream for uploads). Send Content-Type: application/json with a JSON body. |
422 empty_ | The file is empty. Upload the file with its bytes. |
422 unsupported_ | The file isn't one that can be attached: screenshots (PNG, JPEG, GIF or WebP), PDFs and text files. What a file is comes from its bytes, not its name. Send one of those (a text file's name must end in .txt or .log). |
429 rate_ | Too many requests. Wait for Retry-After seconds, then go on more slowly. |