Avatar WEB API curl usage sample

This page contains a step-by-step tutorial on how to retrieve OAuth Bearer token, create a Player, retrieve available Avatar creation parameters, create an avatar from a photo and download its model files along with extra Avatar meta-information using the curl command line utility.

To obtain curl utility for Windows, please visit the following page: https://curl.haxx.se/windows/. Please consult your Linux/macOS distributive packaging system help to install curl utility.

Please note that code samples syntax is different for Windows and for Linux/macOS platforms, thus see the corresponding sample section for your platform by clicking on the platform title.

Authorization

Go to https://accounts.avatarsdk.com/developer/ (create an application if you have no application yet), copy App Client ID and App Client Secret from Client Access application to the corresponding variables. Please make sure you have set Authorization Grant to Client credentials. Set the TOKEN variable to the access_token value after successful authorization. Please note, that token will expire in 36000 seconds and you will need to run authorization procedure again.

Windows
SET "CLIENT_ID=iCM5o..."
SET "CLIENT_SECRET=S8TM5..."
curl -X POST --user "%CLIENT_ID%:%CLIENT_SECRET%" ^
     "https://api.avatarsdk.com/o/token/" ^
     -F "grant_type=client_credentials"

{
  "access_token": "PAvD64lbikgVA0GzxgKV2ZhLnPbZ8P",
  "token_type": "Bearer",
  "expires_in": 36000,
  "scope": "read write"
}

SET "TOKEN=PAvD64lbikgVA0GzxgKV2ZhLnPbZ8P"
Linux
CLIENT_ID="iCM5o..."
CLIENT_SECRET="S8TM5..."
curl -X POST --user "$CLIENT_ID:$CLIENT_SECRET" \
     "https://api.avatarsdk.com/o/token/" \
     -F "grant_type=client_credentials"

{
  "access_token": "PAvD64lbikgVA0GzxgKV2ZhLnPbZ8P",
  "token_type": "Bearer",
  "expires_in": 36000,
  "scope": "read write"
}

TOKEN="PAvD64lbikgVA0GzxgKV2ZhLnPbZ8P"

Create a Player ID

Create a Player ID that will own all future avatars. Please note, that the Player ID does not expire.

Windows
curl -H "Authorization: Bearer %TOKEN%" ^
     -X POST ^
     "https://api.avatarsdk.com/players/" ^
     -F "comment=curl sample"

{
  "url": "https://api.avatarsdk.com/players/16322807-89e3-4223-a83c-1d6afa8abd11/",
  "code": "16322807-89e3-4223-a83c-1d6afa8abd11",
  "created_on": "2020-01-14T07:09:55.976235Z",
  "comment": "curl sample"
}

SET "PLAYER=16322807-89e3-4223-a83c-1d6afa8abd11"
Linux
curl -H "Authorization: Bearer $TOKEN" \
     -X POST \
     "https://api.avatarsdk.com/players/" \
     -F "comment=curl sample"

{
  "url": "https://api.avatarsdk.com/players/16322807-89e3-4223-a83c-1d6afa8abd11/",
  "code": "16322807-89e3-4223-a83c-1d6afa8abd11",
  "created_on": "2020-01-14T07:09:55.976235Z",
  "comment": "curl sample"
}

PLAYER="16322807-89e3-4223-a83c-1d6afa8abd11"

Query available parameters

Query all available parameters for base/mobile subtype of head_1.2 pipeline. Please note, that this request is useful during parameters discovery and should be omitted during normal application workflow once you figure out which parameters fit you best.

Windows
curl -H "Authorization: Bearer %TOKEN%" ^
     -X GET ^
     "https://api.avatarsdk.com/parameters/available/head_1.2/?pipeline_subtype=base/mobile"

{
  "base/mobile": {
    "model_info": {
      "plus": [
        "skin_color",
        "gender",
        "age",
        "race",
        "facial_landmarks_68",
        "eye_sclera_color",
        "eye_iris_color",
        "lips_color"
      ]
    },
    "additional_textures": {
      "plus": ["lips_mask"]
    },
    "blendshapes": {
      "base": ["mobile_51"]
    },
    "avatar_modifications": {
      "plus": [
        "curved_bottom",
        "slightly_cartoonish_texture",
        "parametric_eyes_texture",
        "add_glare",
        "add_eyelid_shadow",
        "eye_iris_color",
        "eye_sclera_color",
        "lips_color",
        "repack_texture",
        "teeth_color",
        "remove_smile"
      ]
    }
  }
}
Linux
curl -H "Authorization: Bearer $TOKEN" \
     -X GET \
     "https://api.avatarsdk.com/parameters/available/head_1.2/?pipeline_subtype=base/mobile"

{
  "base/mobile": {
    "model_info": {
      "plus": [
        "skin_color",
        "gender",
        "age",
        "race",
        "facial_landmarks_68",
        "eye_sclera_color",
        "eye_iris_color",
        "lips_color"
      ]
    },
    "additional_textures": {
      "plus": ["lips_mask"]
    },
    "blendshapes": {
      "base": ["mobile_51"]
    },
    "avatar_modifications": {
      "plus": [
        "curved_bottom",
        "slightly_cartoonish_texture",
        "parametric_eyes_texture",
        "add_glare",
        "add_eyelid_shadow",
        "eye_iris_color",
        "eye_sclera_color",
        "lips_color",
        "repack_texture",
        "teeth_color",
        "remove_smile"
      ]
    }
  }
}

Query available enumerable export parameters

Query all available enumerable export parameters for the base/mobile subtype of the head_1.2 pipeline. Please note, that this request is useful during parameters discovery and should be omitted during regular application workflow once you figure out which parameters fit you best.

Windows
curl -H "Authorization: Bearer %TOKEN%" ^
     -X GET ^
     "https://api.avatarsdk.com/export_parameters/available/head_1.2/?pipeline_subtype=base/mobile"

{
  "blendshapes": [
    "mobile_51"
  ]
}
Linux
curl -H "Authorization: Bearer $TOKEN" \
     -X GET \
     "https://api.avatarsdk.com/export_parameters/available/head_1.2/?pipeline_subtype=base/mobile"

{
  "blendshapes": [
    "mobile_51"
  ]
}

Create an avatar

We will use the following parameters for our avatar:

{
  "model_info": {
    "plus": [
      "gender",
      "age",
      "race"
    ]
  },
  "avatar_modifications": {
    "plus": {
      "curved_bottom": true
    }
  }
}

And the following export parameters:

{
  "format": "glb",
  "embed": true,
  "additional_textures": [
    "lips_mask"
  ],
  "embed_textures": true,
  "blendshapes": {
    "list": [
      "mobile_51"
    ]
  }
}

Please note: since we are using Exports API, blendshapes should be specified in export parameters.

Save avatar parameters and export parameters into the files parameters.json and export_parameters.json correspondingly. Run the avatar computation request with the parameters files above, the photo.jpg image from the current directory (adjust path if necessary), TOKEN and PLAYER values obtained earlier and save the avatar code for further use:

Windows
curl -H "Authorization: Bearer %TOKEN%" ^
     -H "X-PlayerUID: %PLAYER%" ^
     -X POST "https://api.avatarsdk.com/avatars/" ^
     -F "name=test from curl sample" ^
     -F "pipeline=head_1.2" ^
     -F "pipeline_subtype=base/mobile" ^
     -F "parameters=<parameters.json" ^
     -F "export_parameters=<export_parameters.json" ^
     -F "photo=@photo.jpg"

{
  "url": "https://api.avatarsdk.com/avatars/0c60a909-2e5b-4c49-9365-368b4cf78d43/",
  "code": "0c60a909-2e5b-4c49-9365-368b4cf78d43",
  "status": "Uploading",
  "progress": 0,
  "created_on": "2020-01-14T07:44:12.554903Z",
  "name": "test from curl sample",
  "description": ""
}

SET "AVATAR=0c60a909-2e5b-4c49-9365-368b4cf78d43"
Linux
curl -H "Authorization: Bearer $TOKEN" \
     -H "X-PlayerUID: $PLAYER" \
     -X POST "https://api.avatarsdk.com/avatars/" \
     -F "name=test from curl sample" \
     -F "pipeline=head_1.2" \
     -F "pipeline_subtype=base/mobile" \
     -F "parameters=<parameters.json" \
     -F "export_parameters=<export_parameters.json" \
     -F "photo=@photo.jpg"

{
  "url": "https://api.avatarsdk.com/avatars/0c60a909-2e5b-4c49-9365-368b4cf78d43/",
  "code": "0c60a909-2e5b-4c49-9365-368b4cf78d43",
  "status": "Uploading",
  "progress": 0,
  "created_on": "2020-01-14T07:44:12.554903Z",
  "name": "test from curl sample",
  "description": ""
}

AVATAR="0c60a909-2e5b-4c49-9365-368b4cf78d43"

Poll avatar status

Once the photo is uploaded avatar computation is started. Request the avatar status periodically (once per 5 seconds should be enough) to check avatar computation status and progress:

Windows
curl -H "Authorization: Bearer %TOKEN%" ^
     -H "X-PlayerUID: %PLAYER%" ^
     -X GET ^
     "https://api.avatarsdk.com/avatars/%AVATAR%/"

{
  "url": "https://api.avatarsdk.com/avatars/0c60a909-2e5b-4c49-9365-368b4cf78d43/",
  "code": "0c60a909-2e5b-4c49-9365-368b4cf78d43",
  "status": "Computing",
  "progress": 0,
  "name": "test from curl sample",
  "description": "",
  "created_on": "2020-01-14T07:44:12.554903Z",
  "ctime": null,
  "model_info": "https://api.avatarsdk.com/avatars/0c60a909-2e5b-4c49-9365-368b4cf78d43/model_info/",
  "thumbnail": "https://api.avatarsdk.com/avatars/0c60a909-2e5b-4c49-9365-368b4cf78d43/thumbnail/",
  "mesh": "https://api.avatarsdk.com/avatars/0c60a909-2e5b-4c49-9365-368b4cf78d43/mesh/",
  "texture": "https://api.avatarsdk.com/avatars/0c60a909-2e5b-4c49-9365-368b4cf78d43/texture/",
  "preview": "https://api.avatarsdk.com/avatars/0c60a909-2e5b-4c49-9365-368b4cf78d43/preview/",
  "haircuts": "https://api.avatarsdk.com/avatars/0c60a909-2e5b-4c49-9365-368b4cf78d43/haircuts/",
  "blendshapes": "https://api.avatarsdk.com/avatars/0c60a909-2e5b-4c49-9365-368b4cf78d43/blendshapes/",
  "pipeline": null,
  "pipeline_subtype": null
}
Linux
curl -H "Authorization: Bearer $TOKEN" \
     -H "X-PlayerUID: $PLAYER" \
     -X GET \
     "https://api.avatarsdk.com/avatars/$AVATAR/"

{
  "url": "https://api.avatarsdk.com/avatars/0c60a909-2e5b-4c49-9365-368b4cf78d43/",
  "code": "0c60a909-2e5b-4c49-9365-368b4cf78d43",
  "status": "Computing",
  "progress": 0,
  "name": "test from curl sample",
  "description": "",
  "created_on": "2020-01-14T07:44:12.554903Z",
  "ctime": null,
  "model_info": "https://api.avatarsdk.com/avatars/0c60a909-2e5b-4c49-9365-368b4cf78d43/model_info/",
  "thumbnail": "https://api.avatarsdk.com/avatars/0c60a909-2e5b-4c49-9365-368b4cf78d43/thumbnail/",
  "mesh": "https://api.avatarsdk.com/avatars/0c60a909-2e5b-4c49-9365-368b4cf78d43/mesh/",
  "texture": "https://api.avatarsdk.com/avatars/0c60a909-2e5b-4c49-9365-368b4cf78d43/texture/",
  "preview": "https://api.avatarsdk.com/avatars/0c60a909-2e5b-4c49-9365-368b4cf78d43/preview/",
  "haircuts": "https://api.avatarsdk.com/avatars/0c60a909-2e5b-4c49-9365-368b4cf78d43/haircuts/",
  "blendshapes": "https://api.avatarsdk.com/avatars/0c60a909-2e5b-4c49-9365-368b4cf78d43/blendshapes/",
  "pipeline": null,
  "pipeline_subtype": null
}

Once the avatar is ready, its status is set to Completed and progress is 100:

Windows
curl -H "Authorization: Bearer %TOKEN%" ^
     -H "X-PlayerUID: %PLAYER%" ^
     -X GET ^
     "https://api.avatarsdk.com/avatars/%AVATAR%/"

{
  "url": "https://api.avatarsdk.com/avatars/0c60a909-2e5b-4c49-9365-368b4cf78d43/",
  "code": "0c60a909-2e5b-4c49-9365-368b4cf78d43",
  "status": "Completed",
  "progress": 100,
  "name": "test from curl sample",
  "description": "",
  "created_on": "2020-01-14T07:44:12.554903Z",
  "ctime": null,
  "model_info": "https://api.avatarsdk.com/avatars/0c60a909-2e5b-4c49-9365-368b4cf78d43/model_info/",
  "thumbnail": "https://api.avatarsdk.com/avatars/0c60a909-2e5b-4c49-9365-368b4cf78d43/thumbnail/",
  "mesh": "https://api.avatarsdk.com/avatars/0c60a909-2e5b-4c49-9365-368b4cf78d43/mesh/",
  "texture": "https://api.avatarsdk.com/avatars/0c60a909-2e5b-4c49-9365-368b4cf78d43/texture/",
  "preview": "https://api.avatarsdk.com/avatars/0c60a909-2e5b-4c49-9365-368b4cf78d43/preview/",
  "haircuts": "https://api.avatarsdk.com/avatars/0c60a909-2e5b-4c49-9365-368b4cf78d43/haircuts/",
  "blendshapes": "https://api.avatarsdk.com/avatars/0c60a909-2e5b-4c49-9365-368b4cf78d43/blendshapes/",
  "pipeline": "head_1.2",
  "pipeline_subtype": "base/mobile"
}
Linux
curl -H "Authorization: Bearer $TOKEN" \
     -H "X-PlayerUID: $PLAYER" \
     -X GET \
     "https://api.avatarsdk.com/avatars/$AVATAR/"

{
  "url": "https://api.avatarsdk.com/avatars/0c60a909-2e5b-4c49-9365-368b4cf78d43/",
  "code": "0c60a909-2e5b-4c49-9365-368b4cf78d43",
  "status": "Completed",
  "progress": 100,
  "name": "test from curl sample",
  "description": "",
  "created_on": "2020-01-14T07:44:12.554903Z",
  "ctime": null,
  "model_info": "https://api.avatarsdk.com/avatars/0c60a909-2e5b-4c49-9365-368b4cf78d43/model_info/",
  "thumbnail": "https://api.avatarsdk.com/avatars/0c60a909-2e5b-4c49-9365-368b4cf78d43/thumbnail/",
  "mesh": "https://api.avatarsdk.com/avatars/0c60a909-2e5b-4c49-9365-368b4cf78d43/mesh/",
  "texture": "https://api.avatarsdk.com/avatars/0c60a909-2e5b-4c49-9365-368b4cf78d43/texture/",
  "preview": "https://api.avatarsdk.com/avatars/0c60a909-2e5b-4c49-9365-368b4cf78d43/preview/",
  "haircuts": "https://api.avatarsdk.com/avatars/0c60a909-2e5b-4c49-9365-368b4cf78d43/haircuts/",
  "blendshapes": "https://api.avatarsdk.com/avatars/0c60a909-2e5b-4c49-9365-368b4cf78d43/blendshapes/",
  "pipeline": "head_1.2",
  "pipeline_subtype": "base/mobile"
}

Check avatar export

Once the avatar is ready, check avatar exports status:

Windows
curl -H "Authorization: Bearer %TOKEN%" ^
     -H "X-PlayerUID: %PLAYER%" ^
     -X GET ^
     "https://api.avatarsdk.com/avatars/%AVATAR%/exports/"

[
  {
    "status": "Completed",
    "files": [
      {
        "category": null,
        "static_files": [],
        "identity": "avatar",
        "file": "https://api.avatarsdk.com/avatars/0c60a909-2e5b-4c49-9365-368b4cf78d43/exports/37560867-6072-4333-9a9c-b67fb72e248a/files/avatar/file/"
      }
    ],
    "code": "37560867-6072-4333-9a9c-b67fb72e248a",
    "url": "https://api.avatarsdk.com/avatars/0c60a909-2e5b-4c49-9365-368b4cf78d43/exports/37560867-6072-4333-9a9c-b67fb72e248a/",
    "comment": null,
    "created_on": "2020-01-14T07:44:12.554903Z",
    "avatar_code": "0c60a909-2e5b-4c49-9365-368b4cf78d43"
  }
]

SET "EXPORT=37560867-6072-4333-9a9c-b67fb72e248a"
Linux
curl -H "Authorization: Bearer $TOKEN" \
     -H "X-PlayerUID: $PLAYER" \
     -X GET \
     "https://api.avatarsdk.com/avatars/$AVATAR/exports/"

[
  {
    "status": "Completed",
    "files": [
      {
        "category": null,
        "static_files": [],
        "identity": "avatar",
        "file": "https://api.avatarsdk.com/avatars/0c60a909-2e5b-4c49-9365-368b4cf78d43/exports/37560867-6072-4333-9a9c-b67fb72e248a/files/avatar/file/"
      }
    ],
    "code": "37560867-6072-4333-9a9c-b67fb72e248a",
    "url": "https://api.avatarsdk.com/avatars/0c60a909-2e5b-4c49-9365-368b4cf78d43/exports/37560867-6072-4333-9a9c-b67fb72e248a/",
    "comment": null,
    "created_on": "2020-01-14T07:44:12.554903Z",
    "avatar_code": "0c60a909-2e5b-4c49-9365-368b4cf78d43"
  }
]

EXPORT="37560867-6072-4333-9a9c-b67fb72e248a"

Download avatar export files

Once the avatar export is ready, download all its files: avatar mesh with blendshapes and textures in one unified glb (as requested per export parameters):

Windows
curl -H "Authorization: Bearer %TOKEN%" ^
     -H "X-PlayerUID: %PLAYER%" ^
     -X GET ^
     "https://api.avatarsdk.com/avatars/%AVATAR%/exports/%EXPORT%/files/avatar/file/" ^
     -o "avatar.zip"
Linux
curl -H "Authorization: Bearer $TOKEN" \
     -H "X-PlayerUID: $PLAYER" \
     -X GET \
     "https://api.avatarsdk.com/avatars/$AVATAR/exports/$EXPORT/files/avatar/file/" \
     -o "avatar.zip"

Retrieve model info

Request avatar info (gender, age, and race were stated in parameters on avatar creation request). Please note: avatar info (requested in avatar computation parameters) is also available within the model.json file in the avatar.zip archive.

Windows
curl -H "Authorization: Bearer %TOKEN%" ^
     -H "X-PlayerUID: %PLAYER%" ^
     -X GET ^
     "https://api.avatarsdk.com/avatars/%AVATAR%/model_info/"

{
  "pipeline": "head_1.2",
  "race": "white",
  "pipeline_subtype": "base/mobile",
  "gender": "female",
  "age": "not_child",
  "gender_confidence": 1,
  "races": {
    "white": 0.9999293088912964,
    "black": 6.207711428229956e-11,
    "asian": 7.072898733895272e-05
  },
  "age_confidence": 1,
  "race_confidence": 0.9999293088912964
}
Linux
curl -H "Authorization: Bearer $TOKEN" \
     -H "X-PlayerUID: $PLAYER" \
     -X GET \
     "https://api.avatarsdk.com/avatars/$AVATAR/model_info/"

{
  "pipeline": "head_1.2",
  "race": "white",
  "pipeline_subtype": "base/mobile",
  "gender": "female",
  "age": "not_child",
  "gender_confidence": 1,
  "races": {
    "white": 0.9999293088912964,
    "black": 6.207711428229956e-11,
    "asian": 7.072898733895272e-05
  },
  "age_confidence": 1,
  "race_confidence": 0.9999293088912964
}