curl --request POST \
--url https://formhug.ai/api/v1/attachments \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"file_name": "cover.png",
"content_type": "image/png",
"file_size": 123456
}
'import requests
url = "https://formhug.ai/api/v1/attachments"
payload = {
"file_name": "cover.png",
"content_type": "image/png",
"file_size": 123456
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({file_name: 'cover.png', content_type: 'image/png', file_size: 123456})
};
fetch('https://formhug.ai/api/v1/attachments', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://formhug.ai/api/v1/attachments",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'file_name' => 'cover.png',
'content_type' => 'image/png',
'file_size' => 123456
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://formhug.ai/api/v1/attachments"
payload := strings.NewReader("{\n \"file_name\": \"cover.png\",\n \"content_type\": \"image/png\",\n \"file_size\": 123456\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://formhug.ai/api/v1/attachments")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"file_name\": \"cover.png\",\n \"content_type\": \"image/png\",\n \"file_size\": 123456\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://formhug.ai/api/v1/attachments")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"file_name\": \"cover.png\",\n \"content_type\": \"image/png\",\n \"file_size\": 123456\n}"
response = http.request(request)
puts response.read_body{
"data": {
"upload_id": "<string>",
"upload_url": "<string>",
"expires_at": "2023-11-07T05:31:56Z",
"purpose": "header_image"
}
}{
"error": "Content type \"text/html\" is not allowed"
}{
"error": "<string>"
}{
"error": "File too large (max 5 MB)"
}{
"error": "Invalid field input",
"error_details": [
{
"attribute": "purpose",
"message": "must be one of: header_image, wallpaper_image, rich_text_image, choice_image, product_image, booking_image"
}
]
}Prepare a form-element attachment upload
Prepare a 2-step upload for a form-element image. purpose selects the kind:
header_image / wallpaper_image (theme images), rich_text_image, or a
field-element image (choice_image, product_image, booking_image).
Returns a one-time upload_id and an upload_url.
Send the file to upload_url with an HTTP PUT: the raw file bytes as the
request body and the Content-Type header set to the value you declared in
content_type (it must match). Use the upload_url exactly as returned.
Then consume the upload_id: theme images go into a theme update
(header.images[].upload_id / wallpaper.image.upload_id); rich_text_image
is finalized via POST /api/v1/attachment_commitments; field-element images go
into the form create / update fields payload (choices[].image.upload_id,
goods_items[].images[].upload_id, reservation_items[].images[].upload_id).
No PAT scope required.
curl --request POST \
--url https://formhug.ai/api/v1/attachments \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"file_name": "cover.png",
"content_type": "image/png",
"file_size": 123456
}
'import requests
url = "https://formhug.ai/api/v1/attachments"
payload = {
"file_name": "cover.png",
"content_type": "image/png",
"file_size": 123456
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({file_name: 'cover.png', content_type: 'image/png', file_size: 123456})
};
fetch('https://formhug.ai/api/v1/attachments', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://formhug.ai/api/v1/attachments",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'file_name' => 'cover.png',
'content_type' => 'image/png',
'file_size' => 123456
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://formhug.ai/api/v1/attachments"
payload := strings.NewReader("{\n \"file_name\": \"cover.png\",\n \"content_type\": \"image/png\",\n \"file_size\": 123456\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://formhug.ai/api/v1/attachments")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"file_name\": \"cover.png\",\n \"content_type\": \"image/png\",\n \"file_size\": 123456\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://formhug.ai/api/v1/attachments")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"file_name\": \"cover.png\",\n \"content_type\": \"image/png\",\n \"file_size\": 123456\n}"
response = http.request(request)
puts response.read_body{
"data": {
"upload_id": "<string>",
"upload_url": "<string>",
"expires_at": "2023-11-07T05:31:56Z",
"purpose": "header_image"
}
}{
"error": "Content type \"text/html\" is not allowed"
}{
"error": "<string>"
}{
"error": "File too large (max 5 MB)"
}{
"error": "Invalid field input",
"error_details": [
{
"attribute": "purpose",
"message": "must be one of: header_image, wallpaper_image, rich_text_image, choice_image, product_image, booking_image"
}
]
}Authorizations
Personal Access Token prefixed with fh_. Sent as Authorization: Bearer fh_xxx.
The scope required by each endpoint is listed in that endpoint's description.
Body
What this attachment is for. header_image / wallpaper_image are theme images consumed by a theme update; rich_text_image is finalized via POST /api/v1/attachment_commitments; choice_image / product_image / booking_image are field-element images referenced from the form create / update fields payload.
header_image, wallpaper_image, rich_text_image, choice_image, product_image, booking_image Original file name (with extension).
"cover.png"
MIME type. Must be one of image/jpeg, image/png, image/webp, image/gif. Pinned into the upload URL — the PUT must send this exact Content-Type.
"image/png"
File size in bytes. Must be ≤ 5 MB.
123456
Response
Upload credentials issued
Prepare-step response for the 2-step form-element attachment upload. Send the file to upload_url with an HTTP PUT: the raw file bytes as the request body and the Content-Type header set to the value you declared in content_type (it must match). Use upload_url exactly as returned. Then consume the upload_id per its purpose: theme images in a theme update; rich_text_image via POST /api/v1/attachment_commitments; field-element images (choice_image / product_image / booking_image) inside the form create / update fields payload.
Show child attributes
Show child attributes
Was this page helpful?