Creating a Schema
Creates a customized schema as per user specifications.
Creating a Schema Definition
The sampleCreateSchemaDef function demonstrates how to create a schema definition using the DICE ID SDK. It prompts the user for the attribute name, schema name, and schema version, and then calls the createSchema function to create the schema.
API Elements
schema_input: An object that holds the attribute, schema name, and schema version for creating the schema.
schema_input.attributes: An object that stores the attribute name and its data type.
attr_name: Stores the attribute name entered by the user.
schema_name: Stores the schema name entered by the user.
schema_version: Stores the schema version entered by the user.
diceidsdk.issuer.createSchema(): Creates a schema using the schema_input.
Imports the
ISSUER_XAPIKEY
constant from theappconfig
module.resp: Holds the response from the createSchema API, including the schema details.
schemaOutput: Stores the created schema output.
err: Stores any error that occurs during the process.
Running the Code
Step 1: Add the sampleCreateSchemaDef function: Copy the sampleCreateSchemaDef function code and paste it into your JavaScript file after importing the diceidsdk module.
Step 2: Obtain an API Key: Make sure you have an API key from the DiceID platform. Set the ISSUER_XAPIKEY
constant in the appconfig.js
file to your actual API key.
Step 3: Run the function: Invoke the sampleCreateSchemaDef function in your code to execute it. For example:
Step 4: Provide input: The function will prompt you to enter the attribute name, schema name, and schema version. Enter the required information in the terminal or command prompt.
Step 4: Once the createSchema function completes, you can handle the response within the .then()
block of the promise or perform any necessary error handling in the .catch()
block.
Last updated