User Manual

Assets - Create asset

Route URL

POST https://playcanvas.com/api/assets

Description

Create a new asset.

This endpoint currently only supports creating script, html, css, text, shader and json type assets.

Unlike other REST API endpoints. The Create Asset endpoint expects data to be sent in multipart/form-data

Example

curl -H "Authorization: Bearer {accessToken}" -X POST -F 'name={name}' -F 'projectId={projectId}' -F 'parent={parent}' -F 'preload={preload}' -F 'file=@./script.js'  https://playcanvas.com/api/assets

HTTP Request

POST https://playcanvas.com/api/assets
Authorization: Bearer {accessToken}
Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryTdsfsfT

------WebKitFormBoundaryTdsfsfT
Content-Disposition: form-data; name="projectId"

{projectId}
------WebKitFormBoundaryTdsfsfT
Content-Disposition: form-data; name="parent"

{parent}
------WebKitFormBoundaryTdsfsfT
Content-Disposition: form-data; name="preload"

{preload}
------WebKitFormBoundaryTdsfsfT
Content-Disposition: form-data; name=""; filename="script.js"
Content-Type: application/javascript

{fileContent}
------WebKitFormBoundaryTdsfsfT--

Parameters

name: string

Name of the asset

projectId: number

Project id to add the asset to

parent [optional]: number

Parent asset's id

preload [optional]: boolean

Preload the asset (true | false)

file [optional]: file

Data to store as the asset file.

Response Schema

Status: 201
{
    "id": int,
    "modifiedAt": date,
    "createdAt": date,
    "state": "ready" or "processing" or "error",
    "name": string,
    "type": string,
    "scope":{
        "type": string,
        "id": int
    },
    "source": bool,
    "sourceId": bool,
    "tags": list of strings,
    "preload": bool,
    "data": {
        ... asset data
    },
    "file": {
        "hash": string,
        "filename": string,
        "size": int,
        "url": string
    },
    "parent": int
}

Errors

401

Unauthorized

403

Forbidden

404

Project not found

429

Too many requests

Rate Limiting

This route uses a strict rate limit.