> This page is for Schema Service, version v2.
> For other versions, use one of these documentation indexes:
> - v3 (latest) (default): https://autodesk.ferndocs.com/schema/schema-service/v3/llms.txt
> - v2: https://autodesk.ferndocs.com/schema/schema-service/v2/llms.txt

> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://autodesk.ferndocs.com/schema/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://autodesk.ferndocs.com/schema/_mcp/server.

# Task 4 - Create a Schema

This task explains how to create a schema for your application.

A schema is an object in the Forge Schema service that represents a schema specification. A schema specification is a blueprint that describes how information is organized and constrained within a block of data. It is essentially a JSON specification that defines the constituents of the data. It provides a structure and set of rules to keep everything consistent and interoperable in a system.

## Expected task outcome

By the end of this task you will be able to:

* Create a draft schema.
* Fetch a draft schema.
* Publish schema.
* Fetch a Published schema.

## Endpoints used in this task

You will use the following API endpoints in this task:

| Method | Endpoint                                                        | Operation                   |
| ------ | --------------------------------------------------------------- | --------------------------- |
| POST   | /companies/\{companyId}/namespaces/\{namespaceId}/schemas/draft | Create a Draft Schema       |
| POST   | /companies/\{companyId}/namespaces/\{namespaceId}/schemas       | Create a Published Schema   |
| GET    | /schemas/\{schemaVersionId}                                     | Fetch a Version of a Schema |

## Step 1 - Create a Draft Schema

In postman, Select **Task 3 > POST Create a Draft Schema**  and click **Send**. The equivalent cURL request is as follows.

### Request

```ruby
 curl -X POST \
     'https://developer-stg.api.autodesk.com/schema/v2/companies/<COMPNAY_ID/namespaces/<NAMESPACE_ID/schemas/draft' \
     -H 'Content-Type: application/json' \
     -H 'Accept: application/json' \
     -H 'Authorization: Bearer <YOUR_ACCERSS_TOKEN>' \
     -d '{
         "attributes": {,
         "extensionId": "",
         "extensionStatus": "draft",
         "version": "1.0.0",
         "schema":
         }
         }'
```

|

In Postman, a script in the **Tests** tab saves the ID of the schema to a variable named `DRAFT_SCHEMA_ID`, so that it can be used in subsequent API calls.

### Response

```json

{
  "data": {
     "type": "versions",
     "id": "propertySets:sujit_00091.mildsteel:door-draft",
     "attributes": {
         "extensionId": "propertySets:sujit_00091.mildsteel:door",
         "extensionStatus": "draft",
         "schema": "{\"typeid\":\"sujit_00091.mildsteel:door-1.0.0\",\"inherits\":[\"autodesk.unit:unit.derived-1.0.0\"],\"properties\":[{\"id\":\"doorHandleCount\",\"typeid\":\"Uint32\"},{\"id\":\"name\",\"typeid\":\"String\"}]}",
         "version": "draft",
         "title": "NA",
         "description": "NA",
         "createdBy": "vRx4GPkPtgn6UwldLHddl1XoPxPNgm25",
         "createTime": "2022-06-20T04:55:09Z"
     }
 }
}
```

## Step 2 - Fetch Draft Schema

In postman, Select **Task 3 > GET Fetch Draft Schema** request and click send. The equivalent cURL request is as follows.

### Request

```ruby
 curl -X GET \
     'https://developer-stg.api.autodesk.com/schema/v2/schemas/<DRAFT_SCHEMA_VERSION_ID>' \
     -H 'Authorization: Bearer <YOUR_ACCERSS_TOKEN>'
```

|

### Response

```json

{
 "data": {
     "type": "versions",
     "id": "<SCHEMA_DRAFT_VERSION_ID>",
     "attributes": {
         "extensionId": "propertySets:autodesk_0001.mildsteel:door",
         "extensionStatus": "draft",
         "schema": "{\"typeid\":\"autodesk_0001.mildsteel:door-1.0.0\",\"inherits\":[\"autodesk.unit:unit.derived-1.0.0\"],\"properties\":[{\"id\":\"doorHandleCount\",\"typeid\":\"Uint32\"},{\"id\":\"name\",\"typeid\":\"String\"}]}",
         "version": "draft",
         "title": "NA",
         "description": "NA",
         "createdBy": "vRx4GPkPtgn6UwldLHddl1XoPxPNgm25",
         "createTime": "2022-06-21T12:45:12Z"
     }
 }
}
```

## Step 3 - Publish Schema

In postman, Select **Task 3 > POST Publish Schema** and click **Send**. The equivalent cURL request is as follows.

Note the `extensionStatus` attribute is Published.

### Request

```ruby
 curl -X POST \
     'https://developer-stg.api.autodesk.com/schema/v2/companies/<COMPNAY_ID/namespaces/<NAMESPACE_ID/schemas/draft' \
     -H 'Content-Type: application/json' \
     -H 'Accept: application/json' \
     -H 'Authorization: Bearer' \
     -d '{
             "attributes": {,
                 "extensionId": "",
                 "extensionStatus": "published",
                 "version": "1.1.1",
                 "schema":
             }
         }'
```

|

In postman, note the **extensionStatus** as **published**

### Response

```json

{
  "data": {
     "type": "versions",
     "id": "propertySets:autodesk_0001.mildsteel:door-1.1.1",
     "attributes": {
         "extensionId": "propertySets:autodesk_0001.mildsteel:door",
         "extensionStatus": "published",
         "schema": "{\"typeid\":\"autodesk_0001.mildsteel:door-1.1.1\",\"inherits\":[\"autodesk.unit:unit.derived-1.0.0\"],\"properties\":[{\"id\":\"doorHandleCount\",\"typeid\":\"Uint32\"},{\"id\":\"name\",\"typeid\":\"String\"}]}",
         "version": "1.1.1",
         "title": "NA",
         "description": "NA",
         "createdBy": "vRx4GPkPtgn6UwldLHddl1XoPxPNgm25",
         "createTime": "2022-06-22T09:16:41Z"
     }
 }
}
```

In Postman, a script in the **Tests** tab saves the ID of the schema to a variable named `SCHEMA_ID`, so that it can be used in subsequent API calls.

## Step 4 - Fetch Published Schema

In postman, Select **Task 3 > GET Fetch Published Schema** and click **Send**. The equivalent cURL request is as follows.

### Request

```ruby
 curl -X GET \
     'https://developer-stg.api.autodesk.com/schema/v2/schemas/<SCHEMA_VERSION_ID>' \
     -H 'Authorization: Bearer <YOUR_ACCERSS_TOKEN>'
```

|

## Response

```json

{
  "data": {
     "type": "versions",
     "id": "propertySets:autodesk_0001.mildsteel:door-1.1.1",
     "attributes": {
         "extensionId": "propertySets:autodesk_0001.mildsteel:door",
         "extensionStatus": "published",
         "schema": "{\"typeid\":\"autodesk_0001.mildsteel:door-1.1.1\",\"inherits\":[\"autodesk.unit:unit.derived-1.0.0\"],\"properties\":[{\"id\":\"doorHandleCount\",\"typeid\":\"Uint32\"},{\"id\":\"name\",\"typeid\":\"String\"}]}",
         "version": "1.1.1",
         "title": "NA",
         "description": "NA",
         "createdBy": "vRx4GPkPtgn6UwldLHddl1XoPxPNgm25",
         "createTime": "2022-06-22T09:16:42Z"
     }
 }
}
```