Upload File to Order
curl --request POST \
--url https://api.example.com/orders/{id}/attach_assetsimport requests
url = "https://api.example.com/orders/{id}/attach_assets"
response = requests.post(url)
print(response.text)const options = {method: 'POST'};
fetch('https://api.example.com/orders/{id}/attach_assets', 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://api.example.com/orders/{id}/attach_assets",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://api.example.com/orders/{id}/attach_assets"
req, _ := http.NewRequest("POST", url, nil)
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.example.com/orders/{id}/attach_assets")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/orders/{id}/attach_assets")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
response = http.request(request)
puts response.read_bodyOrders
Upload File to Order
End-to-end guide: upload a file, attach it to an order, and notify the customer.
POST
/
orders
/
{id}
/
attach_assets
Upload File to Order
curl --request POST \
--url https://api.example.com/orders/{id}/attach_assetsimport requests
url = "https://api.example.com/orders/{id}/attach_assets"
response = requests.post(url)
print(response.text)const options = {method: 'POST'};
fetch('https://api.example.com/orders/{id}/attach_assets', 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://api.example.com/orders/{id}/attach_assets",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://api.example.com/orders/{id}/attach_assets"
req, _ := http.NewRequest("POST", url, nil)
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.example.com/orders/{id}/attach_assets")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/orders/{id}/attach_assets")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
response = http.request(request)
puts response.read_bodyBeta. The order asset management and notification endpoints are in active
development. The request and response shapes shown here are stable for
production use, but we may add new fields or capabilities without notice.
Contact support to be notified of breaking changes.
Overview
A common workflow for custom/made-to-order products is:- Upload a file via the Upload Asset flow
- Attach it to a specific order
- Notify the customer so they receive the download email
1. Upload the file
Create an internal asset and upload the file body. See Upload Asset for the full reference.# Step 1a: Create the asset and get the presigned upload URL
RESPONSE=$(curl -s -X POST 'https://app.filemonk.io/api/v1/external/assets' \
-H 'X-Auth-Token: fm_api_key_your_key_here' \
-H 'Content-Type: application/json' \
-d '{
"asset": {
"type": "internal",
"filename": "custom-song.mp3",
"byte_size": 5242880,
"content_type": "audio/mpeg"
}
}')
ASSET_ID=$(echo $RESPONSE | jq -r '.asset.id')
UPLOAD_URL=$(echo $RESPONSE | jq -r '.upload.url')
# Step 1b: Upload the file body
curl -X PUT "$UPLOAD_URL" \
-H "Content-Type: audio/mpeg" \
-H "Content-Disposition: inline; filename=\"custom-song.mp3\"" \
--upload-file ./custom-song.mp3
import { readFile, stat } from 'node:fs/promises';
const API_KEY = 'fm_api_key_your_key_here';
const BASE = 'https://app.filemonk.io/api/v1/external';
// Step 1a: Create the asset
const filePath = './custom-song.mp3';
const stats = await stat(filePath);
const create = await fetch(`${BASE}/assets`, {
method: 'POST',
headers: {
'X-Auth-Token': API_KEY,
'Content-Type': 'application/json'
},
body: JSON.stringify({
asset: {
type: 'internal',
filename: 'custom-song.mp3',
byte_size: stats.size,
content_type: 'audio/mpeg'
}
})
}).then(r => r.json());
// Step 1b: Upload the file body
const body = await readFile(filePath);
await fetch(create.upload.url, {
method: 'PUT',
headers: create.upload.headers,
body
});
const assetId = create.asset.id;
import os
import requests
API_KEY = 'fm_api_key_your_key_here'
BASE = 'https://app.filemonk.io/api/v1/external'
# Step 1a: Create the asset
file_path = './custom-song.mp3'
byte_size = os.path.getsize(file_path)
create = requests.post(
f'{BASE}/assets',
headers={'X-Auth-Token': API_KEY},
json={
'asset': {
'type': 'internal',
'filename': 'custom-song.mp3',
'byte_size': byte_size,
'content_type': 'audio/mpeg'
}
}
).json()
# Step 1b: Upload the file body
with open(file_path, 'rb') as f:
requests.put(create['upload']['url'], headers=create['upload']['headers'], data=f).raise_for_status()
asset_id = create['asset']['id']
2. Attach the asset to the order
curl -X POST "https://app.filemonk.io/api/v1/external/orders/$ORDER_ID/attach_assets" \
-H 'X-Auth-Token: fm_api_key_your_key_here' \
-H 'Content-Type: application/json' \
-d "{\"asset_ids\": [\"$ASSET_ID\"]}"
const orderId = 'a1b2c3d4-e5f6-7890-abcd-ef1234567890';
await fetch(`${BASE}/orders/${orderId}/attach_assets`, {
method: 'POST',
headers: {
'X-Auth-Token': API_KEY,
'Content-Type': 'application/json'
},
body: JSON.stringify({ asset_ids: [assetId] })
});
order_id = 'a1b2c3d4-e5f6-7890-abcd-ef1234567890'
requests.post(
f'{BASE}/orders/{order_id}/attach_assets',
headers={'X-Auth-Token': API_KEY},
json={'asset_ids': [asset_id]}
).raise_for_status()
3. Notify the customer
curl -X POST "https://app.filemonk.io/api/v1/external/orders/$ORDER_ID/notify" \
-H 'X-Auth-Token: fm_api_key_your_key_here' \
-H 'Content-Type: application/json'
const notify = await fetch(`${BASE}/orders/${orderId}/notify`, {
method: 'POST',
headers: {
'X-Auth-Token': API_KEY,
'Content-Type': 'application/json'
}
}).then(r => r.json());
console.log('Notified at:', notify.notified_at);
notify = requests.post(
f'{BASE}/orders/{order_id}/notify',
headers={'X-Auth-Token': API_KEY}
).json()
print('Notified at:', notify['notified_at'])
You can also use an external URL asset instead of uploading a file. Create
the asset with
type: "external" and external_url pointing to your hosted
file, then follow steps 2 and 3 above.Using an external URL instead
If your file is already hosted elsewhere, skip the upload and create an external asset instead:cURL
curl -X POST 'https://app.filemonk.io/api/v1/external/assets' \
-H 'X-Auth-Token: fm_api_key_your_key_here' \
-H 'Content-Type: application/json' \
-d '{
"asset": {
"type": "external",
"external_url": "https://cdn.example.com/songs/custom-song-1042.mp3",
"name": "Custom Song"
}
}'
⌘I