Skip to navigation

Task 4 - Create a Schema

View as Markdown

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:

MethodEndpointOperation
POST/companies/{companyId}/namespaces/{namespaceId}/schemas/draftCreate a Draft Schema
POST/companies/{companyId}/namespaces/{namespaceId}/schemasCreate 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

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

{
"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

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

|

Response

{
"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

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

{
"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

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

|

Response

{
"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"
}
}
}