DELETE

Delete an asset

Deletes a file from the library and frees its storage. A file templates still use needs force=true.

View as Markdown
DELETEhttps://api.muzekit.com/v1/assets/:id
curl -X DELETE https://api.muzekit.com/v1/assets/ast_dQC3Z8RgqAH \
  -H "Authorization: Bearer $MUZEKIT_SECRET_KEY"

Add user=usr_… for a file in that end user's library.

Deleting a file frees its storage, and the file stops loading everywhere. If templates still use it, the request is refused with 409 asset_in_use, saying how many templates and naming the first few; deleting it would break them. Add force=true to delete it anyway. Any URL to the file you saved elsewhere stops working too.

JSON
{
  "error": {
    "type": "conflict_error",
    "code": "asset_in_use",
    "message": "This file is used in 2 templates (\"Spring sale\" and \"Menu card\"). Deleting it will break them: the file goes missing. Delete anyway with force.",
    "docs_url": "https://muzekit.com/docs/errors#asset_in_use",
    "templates": 2,
    "names": [ "Spring sale", "Menu card" ]
  }
}

Templates in the trash count too, since they can still be restored. With user, templates counts every template that uses the file, but names lists only that user's designs and workspace templates.

Examples

Delete a file from an end user's library

Pass the same user the file was uploaded with. Without it, the API looks in the workspace library and answers 404 asset_not_found.

curl -X DELETE "https://api.muzekit.com/v1/assets/ast_dQC3Z8RgqAH?user=usr_8fK2mQ1xZpR" \
  -H "Authorization: Bearer $MUZEKIT_SECRET_KEY"

Ask before deleting a file in use

Try without force first. On 409 asset_in_use, show the person the count and names, and send the request again with force=true only if they confirm.

# 1. Refused with 409 asset_in_use if templates use the file
curl -X DELETE "https://api.muzekit.com/v1/assets/ast_dQC3Z8RgqAH?user=usr_8fK2mQ1xZpR" \
  -H "Authorization: Bearer $MUZEKIT_SECRET_KEY"

# 2. After the person confirms
curl -X DELETE "https://api.muzekit.com/v1/assets/ast_dQC3Z8RgqAH?user=usr_8fK2mQ1xZpR&force=true" \
  -H "Authorization: Bearer $MUZEKIT_SECRET_KEY"

Remove all of an end user's uploads

When a user leaves your product, list their files and delete each one with force=true. A list returns up to 200 files, so repeat until it comes back empty.

USER_ID=usr_8fK2mQ1xZpR

for ID in $(curl -s "https://api.muzekit.com/v1/assets?user=$USER_ID" \
  -H "Authorization: Bearer $MUZEKIT_SECRET_KEY" | jq -r '.data[].id'); do
  curl -s -X DELETE "https://api.muzekit.com/v1/assets/$ID?user=$USER_ID&force=true" \
    -H "Authorization: Bearer $MUZEKIT_SECRET_KEY"
done

Response

JSON
{ "object": "asset", "id": "ast_dQC3Z8RgqAH", "deleted": true }