Appearance
External API routes ​
Overview ​
routes/external-api.php is the integration API that customers call from their own systems (for example to pull assets into a website or another tool). RouteServiceProvider mounts it with prefix external, the api middleware group and the App\Http\Controllers namespace. Every route sits under v1, so all paths start with /external/v1. The file defines 12 routes: one public login route and 11 asset routes.
Controllers: App\Http\Controllers\DAM\v1\External\AuthController and App\Http\Controllers\DAM\v1\External\AssetsController (the asset routes are registered with Route::controller(AssetsController::class)).
| Method | Path | Controller@method | Auth |
|---|---|---|---|
| POST | /external/v1/login | AuthController@login | Public |
| POST | /external/v1/get-category | AssetsController@getCategory | Token |
| POST | /external/v1/get-category-with-file | AssetsController@getCategoryAndFiles | Token |
| POST | /external/v1/get-file-by-type | AssetsController@getAllAssetsByType | Token |
| POST | /external/v1/get-file-detail | AssetsController@getDetail | Token |
| POST | /external/v1/download-count | AssetsController@downloadCount | Token |
| POST | /external/v1/download-files | AssetsController@downloadMultipleFiles | Token |
| POST | /external/v1/search-assets | AssetsController@SearchAssets | Token |
| POST | /external/v1/generate-embed-code | AssetsController@generateEmbedCode | Token |
| GET | /external/v1/embed-code-list | AssetsController@getEmbedAssetsList | Token |
| POST | /external/v1/add-tag | AssetsController@addTagToAssets | Token |
| POST | /external/v1/get-thumbnail | AssetsController@getThumbnailByEmbed | Token |
Guard, middleware and throttling ​
- Login has only the
apigroup:LogApiRequests,throttle:api(600 requests per minute, keyed by user id or IP) andSubstituteBindings. - Token routes add
auth:external-api,external-apiandthrottle:600,1.auth:external-apiis a Passport guard over theexternal_appprovider, modelApp\Models\DAM\DamExternalApp(fillable:workspace_id,name,url,key,secrete,is_active). The authenticated "user" is the external app record, not a person.external-api(ExternalAPIMiddleware) also requires the token to be namedExternal Api Token. Otherwise it returns{"status": false, "code": 403, "message": "Access denied."}with HTTP 400.
- Every token route reads the workspace from the app record (
$request->user()->workspace_id), not from the request. - Most asset routes take a
roleparameter: the name of an active ACL role (DamAcl) in the app's workspace. Assets are filtered withFIND_IN_SET(role_id, acl_permission), so an app only sees assets that role can see. See Middleware and Assets.
Response envelope and errors ​
All methods return App\RestResource\RestResponse JSON:
| Helper | HTTP | Body |
|---|---|---|
success($data, $msg) | 200 | status: true, code: 200, message, data, error: [] |
validationError($errors) | 400 | status: false, code: 400, message: "Woops! Validation is failed.", error (field errors) |
warning($msg, $code = 402) | 402 unless a code is passed | status: false, code, message |
error($msg) | 500 | status: false, code: 500, message, data |
Errors you will see from every token route:
Workspace is not available.(warning, 402): the app's workspace was not found.Invalid Requested role.(error, 500):roledoes not match an active ACL role. Whenapp.envisproduction,error()replaces the message withWhoops! Something went wrong., so production callers get a generic 500 for a wrong role name.- Any exception:
error()with the exception message (generic in production).
POST /external/v1/login ​
Exchanges an app key and secret for a Passport token.
| Param | Rules |
|---|---|
app_key | required |
secret_key | required |
- Looks up
DamExternalAppwherekey = app_keyandsecrete = secret_key. - Success (
Login successfully.):data.workspace_id,data.access_token. The token is created with the nameExternal Api Token, whichexternal-apichecks. - Failure:
Invalid App and Secrete key.with HTTP 422. - Note:
data.workspace_idis set from$damApp->id, the external app's own id, not itsworkspace_idcolumn. AuthControlleralso has alogoutmethod, but no route points to it.
POST /external/v1/get-category ​
Top-level folders with one level of subfolders.
| Param | Rules |
|---|---|
role | required |
- Top-level folders (
parent_idnull) ordered byfolder_name, paginated 15 per page (fixed). - Each folder gets
workspace_unique_id(workspace url_slug),total_assets(live assets visible to the role),sub_category_countandsub_category_data(subfolders, each withworkspace_unique_id,total_assets,sub_category_count). - Success message:
Folder list has been retrieved successfully.datais a Laravel paginator.
POST /external/v1/get-category-with-file ​
Contents of one folder.
| Param | Rules |
|---|---|
category_id | required |
role | required |
total_record | optional, page size (default 48) |
sort_value | optional, sort column (default updated_at) |
sort_by | optional, direction (default DESC) |
data.folder: subfolders withcategory_name,workspace_unique_id,workspace_name,total_assets,sub_category_count.data.category_assets: paginated live assets in the folder visible to the role, withcategoryandtags.data.breadcrumb: the folder with itsparent.- Errors:
Folder not found.(folder not in the app's workspace), plus the common errors. Success message:Folder with assets fetched successfully.
POST /external/v1/get-file-by-type ​
Assets of one type across all folders.
| Param | Rules |
|---|---|
type | required, matched against digital_assets.type |
role | required |
total_record | optional, page size (default 48) |
sort_value | optional (default updated_at) |
sort_by | optional (default DESC) |
- Returns a paginator of live assets that have a folder (
category_idnot null), withtags. - Side effect: for each asset whose current version has
is_embed_code = 0, the method copies the file to the embed bucket in S3 and setsis_embed_code = 1. Each asset in the response getsis_embed_codeandembed_code. - Success message:
Assets list fetched successfully.
POST /external/v1/get-file-detail ​
One asset.
| Param | Rules |
|---|---|
asset_id | required |
role | required |
download_by | optional (defaults to desktop) |
- Loads the asset in the app's workspace (not deleted, visible to the role) with
category,category.parentandtags. The category is returned asbreadcrumb. - Side effect: writes a
DigitalAssetsDownloadrow withtype = view, IP and location. - Errors:
Assets not found.Success message:Asset detail fetched successfully.
POST /external/v1/download-count ​
Records a download.
| Param | Rules |
|---|---|
asset_id | required |
role | required |
- Inserts a
DigitalAssetsDownloadrow for the workspace and asset. It does not check that the asset belongs to the workspace or is visible to the role. - Success: empty
data, messageDownload count added successfully.
POST /external/v1/download-files ​
Download URL for one asset, or a ZIP for several assets and folders.
| Param | Rules |
|---|---|
assets_id | required, array of asset ids |
role | required |
category_id | optional, array of folder ids (subfolders are included) |
download_by | optional (defaults to desktop) |
- Total size 0:
You are trying to download empty folder.Over 2 GB (2147483648 bytes):Selected file is too large. Kindly reduce the individual file size below 2 GB to download. - One asset and no folders:
data.url(the asset'sdisplay_file) anddata.file_name. Logs a download row. - Otherwise builds
dam-download-<timestamp>-<app id>.zipunderpublic/upload/dam_assets_zip/and returnsdata.urlanddata.file_name. Logs a download row per asset added. - ZIP creation failure:
An error occurred creating your ZIP file.Empty ZIP:You are trying to download empty folder.(error, 500). - The asset and folder lookups here filter by id only; they do not filter by the app's workspace or the role.
- Success message:
Download successfully.
POST /external/v1/search-assets ​
Search live assets visible to the role.
| Param | Rules |
|---|---|
role | required |
search_text | optional; matches display_file_name (LIKE) or an exact tag name. A non-empty value also writes a DamSearchHistory row. |
type | optional, asset type |
popular_tag | optional, array of tag names |
popular_file_type | optional, array of file types |
orientation | optional: horizontal, vertical or square (filtered in PHP from width/height) |
start_date, end_date | optional dates, or all |
last_minutes | optional; when truthy the date filter becomes the last 30 minutes |
data.category_assets: matching assets (not paginated), each withshare_url(type=<base64 id>&status=<base64 "single">),workspace_unique_idandtags.- The
end_datebranch checkshas('start_date'), soend_dateis only read whenstart_dateis also sent. - Success message:
Search Data.
POST /external/v1/generate-embed-code ​
Turns on the embed code for an asset's current version.
| Param | Rules |
|---|---|
asset_id | required |
role | required |
- The asset must be visible to the role (
Asset is not available.otherwise). The lookup does not filter by workspace. - If the version has no embed yet, copies the file into the embed bucket and sets
is_embed_code = 1. data.is_embed_code,data.embed_code. Success message:Embed code generated successfully.
GET /external/v1/embed-code-list ​
Asset versions with an embed code.
| Param | Rules |
|---|---|
role | required |
- Returns
AssetsVersionrows (id,asset_id,workspace_id,user_id,file_name,display_file_name,thumbnail_file,acl_permission,is_embed_code,embed_code_date) joined to their current asset, not deleted, visible to the role. - The query has no
workspace_idfilter; it relies on the role id inacl_permission. - Success message:
Embed code list fetched successfully.
POST /external/v1/add-tag ​
Adds one tag to one asset.
| Param | Rules |
|---|---|
asset_id | required |
role | required (validated, but not used to check access) |
tag_name | required |
- Creates a
DigitalAssetsTagrow and returns it. Success message:New Tag added successfully. - The duplicate check reads
$request->assets_id(plural) while the insert usesasset_id, so theTag is already exists in this file.warning only fires when the caller also sendsassets_id. The method does not check that the asset belongs to the workspace.
POST /external/v1/get-thumbnail ​
Thumbnail URL from an embed key. A comment in the route file says it was added for one customer integration.
| Param | Rules |
|---|---|
workspace_id | required (validated, but the method uses the app's workspace) |
embed_key | required |
- Finds the asset whose version has this
embed_keyandis_embed_code = 1(Asset is not available.otherwise). The lookup does not filter by workspace. datais the S3 URL of the asset thumbnail, ornullwhen the asset has no thumbnail. Success message:Get thumbnail file successfully.