Create an Asset from raw bytes
Creates an Asset in one of two ways. The Content-Type of the request picks one.
Raw bytes. The body is the file. AdCrunch answers 201 with a ready Asset. Do not use multipart/form-data.
curl --data-binary @ad.png \
-H "Authorization: Bearer $ADCRUNCH_API_KEY" \
"https://api.adcrunch.dev/assets?filename=ad.png"
The bytes stream into storage. AdCrunch identifies the type from the bytes, and the Content-Type is only a hint. A file that AdCrunch refuses leaves no object and no Asset.
The request needs a Content-Length. A body with no length answers 411.
Size. This route takes a body up to 95 MB. Over that, it answers 413 with error set to use_upload_url: reserve an upload with POST /assets/uploads, and PUT the file to the URL. A body over the limit of the Cloudflare plan of the domain, 100 MB at the lowest, never reaches AdCrunch. Cloudflare refuses it at the edge with its own 413 page, with no use_upload_url. Send a large video to POST /assets/uploads.
Import from a URL. The JSON body needs a Content-Length and is at most 8 KB. Send Content-Type: application/json with { "sourceUrl": "https://...", "name": "..." }. sourceUrl must be an https URL on port 443, else the answer is 400 with error set to invalid_url. Its host must be a public name: an IP address, a local or private host, or an AdCrunch domain (adcrunch.dev and its subdomains) answers 400 with error set to source_not_allowed. AdCrunch answers 202 with a pending Asset, and a Workflow fetches the file. Poll GET /assets/{id} until status is ready or failed. A failed Asset has a failureCode: source_unreachable (the source did not answer, answered with an error, or sent the file in part), source_length_unknown (the source sent no Content-Length), too_large, unsupported_type or unreadable. The import does not follow a redirect to a URL that is not https.
curl -X POST \
-H "Authorization: Bearer $ADCRUNCH_API_KEY" \
-H "Content-Type: application/json" \
-d '{"sourceUrl":"https://example.com/ad.png"}' \
"https://api.adcrunch.dev/assets"
/assetsAuthorizationBearer token · headerrequiredSend Authorization: Bearer <credential>.
Use an API key (acr_…), from the AdCrunch console under Settings → API keys.
The credential names the organization, and no operation takes an organization parameter.
See https://docs.adcrunch.dev/api/authentication.
filenamestringnamestringapplication/jsonThe raw bytes of the file with any Content-Type except application/json, or a JSON import { sourceUrl, name? }.
namestringThe name to show in place of the filename.
sourceUrlstringrequiredAn https URL of an image or a video.
The stored Asset, already ready.
contentHashstringrequiredAdCrunch’s own hash of the stored bytes. A hint for de-duplication, never an identity, and never a provider’s hash. Empty when the store reports none.
createdAtnumberrequiredMilliseconds since the Unix epoch, UTC.
createdBystringrequiredThe user who reserved the upload.
deletedAtnumber | nullrequiredAlways null here. A deleted Asset is not answered.
durationMsnumber | nullrequiredHow long the video runs, in milliseconds, read from the header of the file at finalize. null for an image. For a video, null when the file does not state it, or for an Asset uploaded before AdCrunch read it.
failureCodestring | nullrequiredWhy AdCrunch refused the file, as a code. Branch on this field, never on failureReason. unsupported_type: the bytes are not an accepted image or video. too_large: the file is over the size limit. unreadable: AdCrunch could not read the header of the file. source_unreachable: an import could not fetch the file from its source URL. source_length_unknown: the source of an import sent no Content-Length. null unless status is failed.
failureReasonstring | nullrequiredWhy AdCrunch refused the file, as a sentence. null unless status is failed.
filenamestringrequiredThe name the file was uploaded under. Never a lookup key.
heightnumber | nullrequiredThe height in pixels as the file is displayed, with its rotation applied, read from the header of the file at finalize. null when the file does not state it, or for an Asset uploaded before AdCrunch read it.
idstringrequiredThe id of the Asset, ast_….
keystringrequiredWhere the bytes are held. Read-only, and never sent by you.
kindstringrequiredFollows from mimeType. It selects how a provider takes the file.
imagevideomimeTypestringrequiredThe type that finalize identified from the stored bytes. The Content-Type of the upload does not set it.
namestring | nullrequiredThe name a person gave this Asset, and what a provider receives at a future registration. null until somebody renames it, and the filename is the fallback.
organizationIdstringrequiredThe organization that owns the Asset.
sizeBytesnumberrequiredRead from the stored object at finalize.
statusstringrequiredready once AdCrunch has inspected the bytes. Only a ready Asset can be registered. pending: the bytes have not been inspected yet. failed: AdCrunch refused the file and deleted it. failureCode and failureReason say why. A read answers an Asset in every status. A list answers ready Assets only.
pendingreadyfailedupdatedAtnumber | nullrequiredWhen the Asset last changed, in milliseconds since the Unix epoch, UTC: at finalize, or at the last rename.
widthnumber | nullrequiredThe width in pixels as the file is displayed, with its rotation applied, read from the header of the file at finalize. null when the file does not state it, or for an Asset uploaded before AdCrunch read it.
The import started. The Asset is pending. Poll GET /assets/{id} until it is ready or failed.
contentHashstringrequiredAdCrunch’s own hash of the stored bytes. A hint for de-duplication, never an identity, and never a provider’s hash. Empty when the store reports none.
createdAtnumberrequiredMilliseconds since the Unix epoch, UTC.
createdBystringrequiredThe user who reserved the upload.
deletedAtnumber | nullrequiredAlways null here. A deleted Asset is not answered.
durationMsnumber | nullrequiredHow long the video runs, in milliseconds, read from the header of the file at finalize. null for an image. For a video, null when the file does not state it, or for an Asset uploaded before AdCrunch read it.
failureCodestring | nullrequiredWhy AdCrunch refused the file, as a code. Branch on this field, never on failureReason. unsupported_type: the bytes are not an accepted image or video. too_large: the file is over the size limit. unreadable: AdCrunch could not read the header of the file. source_unreachable: an import could not fetch the file from its source URL. source_length_unknown: the source of an import sent no Content-Length. null unless status is failed.
failureReasonstring | nullrequiredWhy AdCrunch refused the file, as a sentence. null unless status is failed.
filenamestringrequiredThe name the file was uploaded under. Never a lookup key.
heightnumber | nullrequiredThe height in pixels as the file is displayed, with its rotation applied, read from the header of the file at finalize. null when the file does not state it, or for an Asset uploaded before AdCrunch read it.
idstringrequiredThe id of the Asset, ast_….
keystringrequiredWhere the bytes are held. Read-only, and never sent by you.
kindstringrequiredFollows from mimeType. It selects how a provider takes the file.
imagevideomimeTypestringrequiredThe type that finalize identified from the stored bytes. The Content-Type of the upload does not set it.
namestring | nullrequiredThe name a person gave this Asset, and what a provider receives at a future registration. null until somebody renames it, and the filename is the fallback.
organizationIdstringrequiredThe organization that owns the Asset.
sizeBytesnumberrequiredRead from the stored object at finalize.
statusstringrequiredready once AdCrunch has inspected the bytes. Only a ready Asset can be registered. pending: the bytes have not been inspected yet. failed: AdCrunch refused the file and deleted it. failureCode and failureReason say why. A read answers an Asset in every status. A list answers ready Assets only.
pendingreadyfailedupdatedAtnumber | nullrequiredWhen the Asset last changed, in milliseconds since the Unix epoch, UTC: at finalize, or at the last rename.
widthnumber | nullrequiredThe width in pixels as the file is displayed, with its rotation applied, read from the header of the file at finalize. null when the file does not state it, or for an Asset uploaded before AdCrunch read it.
The request does not match the schema of this operation: a field is missing or has the wrong type, or the body is not valid JSON. error is invalid_request, and issues names each field. Nothing was changed.
issuesobject[]requiredOne entry for each field that does not match.
Show propertiesHide properties
objectinstringrequiredThe part of the request that holds the field.
bodycookieheadersparamsquerymessagestringrequiredA sentence to show a person. Written to say what to do next. Reworded whenever it can be said better, so never branch on it.
pathstringrequiredA JSON Pointer into that part of the request, such as /filename. An empty string is the whole part.
errorstringrequiredA stable code for the failure. This is the field to branch on. It does not change for a given failure.
invalid_requestmessagestringrequiredA sentence to show a person. Written to say what to do next. Reworded whenever it can be said better, so never branch on it.
No API key, or one that does not resolve. See the security scheme. error is unauthorized.
errorstringrequiredA stable code for the failure. This is the field to branch on. It does not change for a given failure.
unauthorizedmessagestringrequiredA sentence to show a person. Written to say what to do next. Reworded whenever it can be said better, so never branch on it.
The organization has no active subscription. An owner subscribes at paywallUrl. error is organization_unentitled.
paywallUrlstring<uri>requiredThe page where an owner of the organization subscribes. Show it to the person.
errorstringrequiredA stable code for the failure. This is the field to branch on. It does not change for a given failure.
organization_unentitledmessagestringrequiredA sentence to show a person. Written to say what to do next. Reworded whenever it can be said better, so never branch on it.
The caller does not hold asset:write. error is forbidden.
errorstringrequiredA stable code for the failure. This is the field to branch on. It does not change for a given failure.
forbiddenmessagestringrequiredA sentence to show a person. Written to say what to do next. Reworded whenever it can be said better, so never branch on it.
The request has no Content-Length. error is length_required. This holds for a raw body and for a JSON body.
errorstringrequiredA stable code for the failure. This is the field to branch on. It does not change for a given failure.
messagestringrequiredA sentence to show a person. Written to say what to do next. Reworded whenever it can be said better, so never branch on it.
The body is too large. error names why:
use_upload_url: the body is over 95 MB. UsePOST /assets/uploads.payload_too_large: the JSON body of an import is over 8 KB.too_large: the file is over the limit for its kind, 30 MB for an image and 4 GB for a video. AdCrunch stored nothing.
A body over the limit of the Cloudflare plan of the domain gets a 413 from Cloudflare, before AdCrunch runs. That answer has no error code.
errorstringrequiredA stable code for the failure. This is the field to branch on. It does not change for a given failure.
messagestringrequiredA sentence to show a person. Written to say what to do next. Reworded whenever it can be said better, so never branch on it.
AdCrunch refused the file. error names why:
unsupported_type: the bytes are no type that AdCrunch accepts.unreadable: the file ends before its header does.
errorstringrequiredA stable code for the failure. This is the field to branch on. It does not change for a given failure.
messagestringrequiredA sentence to show a person. Written to say what to do next. Reworded whenever it can be said better, so never branch on it.