# Advanced - Schema preparation

## 1. Getting a token

[Getting a token](https://docs.metahumansdk.io/service-apis-for-creating-virtual-avatars/getting-started/getting-a-token)

## 2. Creating a schema

You must describe all your types and model IDs in a JSON file.\
For example, you have 2 types of models - body and hair. The JSON structure will then look like this:

{% code title="schema.json" %}

```json
{
	"hair" : [ # <- model type
		"hairM_01", "hairF_01" # <- model id
	],
	"body": [
		"body_01", "body_02", "body_03"
	]
}
```

{% endcode %}

\
In this example, 5 models are declared: 2 body IDs and 3 hairstyle IDs.

\
You can also leave the JSON empty, then when assembled, only the head will be generated.

{% code title="schema.json" %}

```json
{
}
```

{% endcode %}

{% hint style="warning" %}
Note: You can't do nested model types. there are only 2 levels: types and IDs.
{% endhint %}

Sending your schema.

{% tabs %}
{% tab title="curl" %}

```bash
token="ENTER_YOUR_TOKEN"
schema_path="ENTER_SCHEMA_PATH"

curl -X 'PUT' \
  'https://api.metahumansdk.io/glb_const/schema' \
  -H 'accept: application/json' \
  -H 'Content-Type: multipart/form-data' \
  -F "token=$token" \
  -F "schema=@$schema_path;type=application/json"
```

{% endtab %}

{% tab title="python" %}
{% code lineNumbers="true" %}

```python
import requests

schema_path = "ENTER_SCHEMA_PATH"
token = "ENTER_YOUR_TOKEN"

if __name__ == "__main__":
    service_url = "https://api.metahumansdk.io/glb_const"
    service_headers = {"accept": "application/json"}

    files = {
        "token": (None, token),
        "schema": ("schema.json", open(schema_path, 'r'), "application/json")
    }
    response = requests.put(service_url + "/schema", headers=service_headers, files=files)
    assert (response.status_code == 200)
    assert ('result' in response.json())
    print(response.json())
```

{% endcode %}
{% endtab %}
{% endtabs %}

You should get:

```json
{
  "result": {
    "status": "schema loaded successfully"
  }
}
```

## 4. Uploading GLB models

You must add *all* the models declared in the schema.

Sending your GLB file.

{% hint style="info" %}
Note: To calculate the hash you can use the command `sha256sum` in the terminal.
{% endhint %}

{% hint style="info" %}
Note: If you want the texture with the skin color to be automatically repainted in the color taken from the face, the name of this material should contain "skin". The "baseColorFactor" component of the material is repainted.
{% endhint %}

{% tabs %}
{% tab title="curl" %}

```bash
token="ENTER_YOUR_TOKEN"
glb_path="ENTER_GLB_PATH"
glb_hash="ENTER_GLB_HASH"
data_type="ENTER_DATA_TYPE"
data_id="ENTER_DATA_ID"

curl -X 'PUT' \
  'https://api.metahumansdk.io/glb_const/glb' \
  -H 'accept: application/json' \
  -H 'Content-Type: multipart/form-data' \
  -F "token=$token" \
  -F "data=@$glb_path" \
  -F "sha256=$glb_hash" \
  -F "data_type=$data_type" \
  -F "data_id=$data_id"
```

{% endtab %}

{% tab title="python" %}
{% code lineNumbers="true" %}

```python
import requests

token="ENTER_YOUR_TOKEN"
glb_path="ENTER_GLB_PATH"
glb_hash="ENTER_GLB_HASH"
data_type="ENTER_DATA_TYPE"
data_id="ENTER_DATA_ID"

if __name__ == "__main__":
    service_url = "https://api.metahumansdk.io/glb_const"
    service_headers = {"accept": "application/json"}
    files = {
        "token": (None, token),
        "data": ("model", open(glb_path, "rb"), "model/gltf-binary"),
        "sha256": (None, glb_hash),
        "data_type": (None, data_type),
        "data_id": (None, data_id)
    }
    response = requests.put(service_url + "/glb", headers=service_headers, files=files)
    assert (response.status_code == 200)
    assert ('result' in response.json())
    print(response.json())
```

{% endcode %}
{% endtab %}
{% endtabs %}

You should get:

```json
{
  "result": {
    "status": "model loaded successfully"
  }
}
```
