Skip to navigation

Task 5 - Create and-fetch a Schema

View as Markdown

Task 5 - 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 Published schema

Endpoints used in this task

You will use the following API endpoints in this task:

.. list-table:: :widths: 10, 50, 40 :header-rows: 1

    • Method
    • Endpoint
    • Operation
    • POST
    • /groups/{groupId}/libraries/{libraryId}/schemas:draft-create
    • Create a Draft Schema_
    • POST
    • /groups/{groupId}/libraries/{libraryId}/schemas
    • Publish New Schema_
    • GET
    • /schemas/propertySets:{groupId}.{libraryId}:{schemaId}-{version}
    • Fetch a Version of a Schema_

Step 1 - Create a Draft Schema

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

Note the status attribute is draft.

Request

curl -X POST \
'https://developer-stg.api.autodesk.com/schema/v3/groups/<GROUP_ID>/libraries/<LIBRARY_ID>/schemas:draft-create' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H 'Authorization: Bearer <YOUR_ACCERSS_TOKEN>' \
-D {
"qualifier": "<GROUP_ID>.<LIBRARY_ID>",
"name": "<SCHEMA_ID>",
"semanticVersion": "<VERSION_OF_SCHEMA>",
"schemaType": "propertySets",
"releaseType": "major",
"title": "<SCHEMA_TITLE>",
"description": "<SCHEMA_DESCRIPTION>",
"status": "draft",
"schema": "{\"typeid\":\"<GROUP_ID>.<LIBRARY_ID>:<SCHEMA_ID>-<VERSION_OF_SCHEMA>\",\"properties\":[{\"id\":\"height\",\"typeid\":\"Uint32\"}]}"
}

|

Response

{
"qualifier": "<GROUP_ID>.<LIBRARY_ID>",
"name": "<SCHEMA_ID>",
"semanticVersion": "<VERSION_OF_SCHEMA>",
"schemaType": "propertySets",
"title": "<SCHEMA_TITLE>",
"description": "<SCHEMA_DESCRIPTION>",
"status": "draft",
"schema": "{\"typeid\":\"<GROUP_ID>.<LIBRARY_ID>:<SCHEMA_ID>-<VERSION_OF_SCHEMA>\",\"properties\":[{\"id\":\"height\",\"typeid\":\"Uint32\"}]}",
"createdBy": "AYK3q05maQE8bVpTG2sTnYwPj0Jn6f8J",
"createTime": "2022-08-19T03:15:25Z"
}

Step 2 - Fetch Draft Schema

In postman, Select Task 5 > 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/v3/schemas/propertySets:<GROUP_ID>.<LIBRARY_ID>:<SCHEMA_ID>>-draft' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H 'Authorization: Bearer <YOUR_ACCERSS_TOKEN>' \

|

Response

{
"qualifier": "<GROUP_ID>.<LIBRARY_ID>",
"name": "<SCHEMA_ID>",
"semanticVersion": "<VERSION_OF_SCHEMA>",
"schemaType": "propertySets",
"title": "<SCHEMA_TITLE>",
"description": "<SCHEMA_DESCRIPTION>",
"status": "draft",
"schema": "{\"typeid\":\"<GROUP_ID>.<LIBRARY_ID>:<SCHEMA_ID>-<VERSION_OF_SCHEMA>\",\"properties\":[{\"id\":\"height\",\"typeid\":\"Uint32\"}]}",
"createdBy": "AYK3q05maQE8bVpTG2sTnYwPj0Jn6f8J",
"createTime": "2022-09-14T10:26:40Z"
}

Note the status attribute is draft.

Step 3 - Publish Schema

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

Note the status attribute is Published.

Request

curl -X POST \
'https://developer-stg.api.autodesk.com/schema/v3/groups/<GROUP_ID>/libraries/<LIBRARY_ID>/schemas' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H 'Authorization: Bearer <YOUR_ACCERSS_TOKEN>' \
-D '{
"qualifier": "<GROUP_ID>.<LIBRARY_ID>",
"name": "<SCHEMA_ID>",
"semanticVersion": "<VERSION_OF_SCHEMA>",
"schemaType": "propertySets",
"releaseType": "major",
"title": "<SCHEMA_TITLE>",
"description": "<SCHEMA_DESCRIPTION>",
"status": "published",
"schema": "{\"typeid\":\"<GROUP_ID>.<LIBRARY_ID>:<SCHEMA_ID>-<VERSION_OF_SCHEMA>\",\"properties\":[{\"id\":\"height\",\"typeid\":\"Uint32\"}]}"
}'

|

Response

{
"qualifier": "<GROUP_ID>.<LIBRARY_ID>",
"name": "<SCHEMA_ID>",
"semanticVersion": "<VERSION_OF_SCHEMA>",
"schemaType": "propertySets",
"title": "<SCHEMA_TITLE>",
"description": "<SCHEMA_DESCRIPTION>",
"status": "published",
"schema": "{\"typeid\":\"<GROUP_ID>.<LIBRARY_ID>:<SCHEMA_ID>-<VERSION_OF_SCHEMA>\",\"properties\":[{\"id\":\"height\",\"typeid\":\"Uint32\"}]}",
"createdBy": "AYK3q05maQE8bVpTG2sTnYwPj0Jn6f8J",
"createTime": "2022-08-19T02:58:29Z"
}

Step 4 - Fetch Published Schema

In postman, Select Task 5 > 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/v3/schemas/propertySets:<GROUP_ID>.<LIBRARY_ID>:<SCHEMA_ID>-<VERSION_OF_SCHEMA>' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H 'Authorization: Bearer <YOUR_ACCERSS_TOKEN>' \

|

Response

{
"qualifier": "<GROUP_ID>.<LIBRARY_ID>",
"name": "<SCHEMA_ID>",
"semanticVersion": "<VERSION_OF_SCHEMA>",
"schemaType": "propertySets",
"title": "<SCHEMA_TITLE>",
"description": "<SCHEMA_DESCRIPTION",
"status": "published",
"schema": "{\"typeid\":\"<GROUP_ID>.<LIBRARY_ID>:<SCHEMA_ID>-<VERSION_OF_SCHEMA>\",\"properties\":[{\"id\":\"height\",\"typeid\":\"Uint32\"}]}",
"createdBy": "AYK3q05maQE8bVpTG2sTnYwPj0Jn6f8J",
"createTime": "2022-08-16T06:52:00Z"
}

Note the status attribute is published.