The upload returns a file_id. How do I get the PDF onto the vehicle's inspection_report field?
Uploading a file and attaching it to a record
Common question, written up by the Supero team.
1 answer
Over REST it's two calls: upload, then write the whole file reference from the 201 body onto the record with an ordinary update. Store the object, not the bare file_id.
REF=$(curl -s -X POST https://api.supero.dev/api/v1/files/acme/upload \
-H "X-API-Key: $SUPERO_API_KEY" -F "file=@inspection.pdf")
curl -X PUT https://api.supero.dev/api/v1/crud/acme/vehicle/$VEHICLE_UUID \
-H "X-API-Key: $SUPERO_API_KEY" -H "Content-Type: application/json" \
-d "{\"inspection_report\": $REF}"The SDKs do both in one call, org.files.attach(vehicle_uuid, "vehicle", "inspection_report", "inspection.pdf") in Python, and delete the uploaded file if the record write fails. On a list: true gallery field attach appends; over REST you read the array, append the reference and write the whole array back.
Two limits catch people. The API takes up to 25 MB per file, but both SDKs refuse images over 10 MB locally before sending. Audio and video aren't on the allowed list and get a 400 Unsupported file type.
Your answer
Know the answer? Sign in to post it. It takes an email address and a 6-digit code.
Sign in to answer