Create a Document

Scope: Content
POST https://api.lucentcms.com/api/documents

When you create a document you have to provide the schema, the content and the subdocs if they do exist.

{
    "data": {
      	"schema": "products",
        "content": {
            "title": "A title",
            "price": 12.45,
            "isDiscount": true
        },
        "subdocs": {
            "product_variants": [
                {
                    "schema": "variants",
                    "content": {}
                }
            ],
            "vendor": {
                "schema": "vendors",
                "content": {
                    "categories": [
                        {
                            "schema": "categories",
                            "id": "5067d26c-e547-4689-9abe-13895943c34a"
                        }
                    ]
                }
            }
        }
    }
}

Hierarchical Documents

When creating a document inside a hierarchical schema, you also have to include the parent of your document in the body of your request. Below you can find three demo requests which showcase how to create 3 documents inside a hierarchical schema.

The structure is as follows:

  • Parent Document
    • 1st Child
      • 2nd Child

The following headers are used in all 3 requests:

POST /api/documents

Content-Type: application/json
Authentication: Bearer {sys-user-secret}
Lucent-Channel: {channel-id}
Lucent-User: {sys-user-key}
Accept-Language: en-GB
Host: api.lucentcms.com

In order to create the Parent Document:

{
    "data": {
        "schema": "demoSchema",
        "move":{
            "parent": ""
        } ,
        "content": {
            "title":  "Parent Document"
        }
    }
}

The response would be: 200 OK

{
    "data": {
        "id": "1234abcd..."
      ...
    }
}

So in order to create the 1st Child:

{
    "data": {
        "schema": "demoSchema",
        "move":{
            "parent": "1234abcd..." //Id of Parent Document
        } ,
        "content": {
            "title":  "1st Child"
        }
    }
}

Again, the response would be: 200 OK

{
    "data": {
        "id": "4321dcba..."
      ...
    }
}

Finally, in order to create the 2nd child, the request would be:

{
    "data": {
        "schema": "demoSchema",
        "move":{
            "parent": "4321dcba..." //Id of 1st Child
        } ,
        "content": {
            "title":  "2nd Child"
        }
    }
}