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

Create an avatar

We will use the following parameters for our avatar:

{
  "model_info": {
    "plus": [
      "gender",
      "age",
      "race"
    ]
  },
  "additional_textures": {
    "plus": ["lips_mask"]
  },
  "blendshapes": {
    "base": ["mobile_51"]
  }
}

Create an avatar with the parameters above and a photo.jpg photo from the current directory (adjust path if necessary):

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={\"model_info\": {\"plus\":[\"gender\",\"age\",\"race\"]},\"additional_textures\": {\"plus\":[\"lips_mask\"]},\"blendshapes\": {\"base\":[\"mobile_51\"]}}" ^
     -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={\"model_info\": {\"plus\":[\"gender\",\"age\",\"race\"]},\"additional_textures\": {\"plus\":[\"lips_mask\"]},\"blendshapes\": {\"base\":[\"mobile_51\"]}}" \
     -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"
}

Download model files

Once the avatar is ready, download its mesh (zipped archive) and texture:

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

curl -H "Authorization: Bearer %TOKEN%" ^
     -H "X-PlayerUID: %PLAYER%" ^
     -X GET ^
     "https://api.avatarsdk.com/avatars/%AVATAR%/texture/" ^
     -o "model.jpg"
Linux
curl -H "Authorization: Bearer $TOKEN" \
     -H "X-PlayerUID: $PLAYER" \
     -X GET \
     "https://api.avatarsdk.com/avatars/$AVATAR/mesh/" \
     -o "model.zip"

curl -H "Authorization: Bearer $TOKEN" \
     -H "X-PlayerUID: $PLAYER" \
     -X GET \
     "https://api.avatarsdk.com/avatars/$AVATAR/texture/" \
     -o "model.jpg"

Download blendshapes

Download avatar blendshapes (mobile_51 was stated in parameters on avatar creation request) in FBX format as zip archive:

Windows
curl -H "Authorization: Bearer %TOKEN%" ^
     -H "X-PlayerUID: %PLAYER%" ^
     -X GET ^
     "https://api.avatarsdk.com/avatars/%AVATAR%/blendshapes/?fmt=fbx" ^
     -o "blendshapes.zip"
Linux
curl -H "Authorization: Bearer $TOKEN" \
     -H "X-PlayerUID: $PLAYER" \
     -X GET \
     "https://api.avatarsdk.com/avatars/$AVATAR/blendshapes/?fmt=fbx" \
     -o "blendshapes.zip"

Download haircuts

Note: avatars with head_1.2 pipeline have no separate haircut. Thus this section is applicable only for pipelines, which have separate haircuts set, like animated_face or head_2.0.

Query all computed haircuts for the avatar, download haircut mesh and texture:

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

[
  {
    "gender": "unisex",
    "identity": "generated",
    "mesh": "https://api.avatarsdk.com/avatars/3c78e0ec-bc22-415f-8917-fee6ecc7204d/haircuts/generated/mesh/",
    "model": "https://api.avatarsdk.com/avatars/3c78e0ec-bc22-415f-8917-fee6ecc7204d/",
    "pointcloud": "https://api.avatarsdk.com/avatars/3c78e0ec-bc22-415f-8917-fee6ecc7204d/haircuts/generated/pointcloud/",
    "preview": "https://api.avatarsdk.com/avatars/3c78e0ec-bc22-415f-8917-fee6ecc7204d/haircuts/generated/preview/",
    "texture": "https://api.avatarsdk.com/avatars/3c78e0ec-bc22-415f-8917-fee6ecc7204d/haircuts/generated/texture/",
    "url": "https://api.avatarsdk.com/avatars/3c78e0ec-bc22-415f-8917-fee6ecc7204d/haircuts/generated/"
  }
]

curl -H "Authorization: Bearer %TOKEN%" ^
     -H "X-PlayerUID: %PLAYER%" ^
     -X GET ^
     "https://api.avatarsdk.com/avatars/%AVATAR%/haircuts/generated/mesh/" ^
     -o "generated.zip"

curl -H "Authorization: Bearer %TOKEN%" ^
     -H "X-PlayerUID: %PLAYER%" ^
     -X GET ^
     "https://api.avatarsdk.com/avatars/%AVATAR%/haircuts/generated/texture/" ^
     -o "generated.png"
Linux
curl -H "Authorization: Bearer $TOKEN" \
     -H "X-PlayerUID: $PLAYER" \
     -X GET \
     "https://api.avatarsdk.com/avatars/$AVATAR/haircuts/"

[
  {
    "gender": "unisex",
    "identity": "generated",
    "mesh": "https://api.avatarsdk.com/avatars/3c78e0ec-bc22-415f-8917-fee6ecc7204d/haircuts/generated/mesh/",
    "model": "https://api.avatarsdk.com/avatars/3c78e0ec-bc22-415f-8917-fee6ecc7204d/",
    "pointcloud": "https://api.avatarsdk.com/avatars/3c78e0ec-bc22-415f-8917-fee6ecc7204d/haircuts/generated/pointcloud/",
    "preview": "https://api.avatarsdk.com/avatars/3c78e0ec-bc22-415f-8917-fee6ecc7204d/haircuts/generated/preview/",
    "texture": "https://api.avatarsdk.com/avatars/3c78e0ec-bc22-415f-8917-fee6ecc7204d/haircuts/generated/texture/",
    "url": "https://api.avatarsdk.com/avatars/3c78e0ec-bc22-415f-8917-fee6ecc7204d/haircuts/generated/"
  }
]

curl -H "Authorization: Bearer $TOKEN" \
     -H "X-PlayerUID: $PLAYER" \
     -X GET \
     "https://api.avatarsdk.com/avatars/$AVATAR/haircuts/generated/mesh/" \
     -o "generated.zip"

curl -H "Authorization: Bearer $TOKEN" \
     -H "X-PlayerUID: $PLAYER" \
     -X GET \
     "https://api.avatarsdk.com/avatars/$AVATAR/haircuts/generated/texture/" \
     -o "generated.png"

Retrieve additional textures

Download additional texture (lips_mask was stated in parameters on avatar creation request):

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

[
  {
    "identity": "lips_mask",
    "file": "https://api.avatarsdk.com/avatars/0c60a909-2e5b-4c49-9365-368b4cf78d43/textures/lips_mask/file/"
  },
  {
    "identity": "model",
    "file": "https://api.avatarsdk.com/avatars/0c60a909-2e5b-4c49-9365-368b4cf78d43/textures/model/file/"
  }
]

curl -H "Authorization: Bearer %TOKEN%" ^
     -H "X-PlayerUID: %PLAYER%" ^
     -X GET ^
     "https://api.avatarsdk.com/avatars/%AVATAR%/textures/lips_mask/file/" ^
     -o "lips_mask.png"
Linux
curl -H "Authorization: Bearer $TOKEN" \
     -H "X-PlayerUID: $PLAYER" \
     -X GET \
     "https://api.avatarsdk.com/avatars/$AVATAR/textures/"

[
  {
    "identity": "lips_mask",
    "file": "https://api.avatarsdk.com/avatars/0c60a909-2e5b-4c49-9365-368b4cf78d43/textures/lips_mask/file/"
  },
  {
    "identity": "model",
    "file": "https://api.avatarsdk.com/avatars/0c60a909-2e5b-4c49-9365-368b4cf78d43/textures/model/file/"
  }
]

curl -H "Authorization: Bearer $TOKEN" \
     -H "X-PlayerUID: $PLAYER" \
     -X GET \
     "https://api.avatarsdk.com/avatars/$AVATAR/textures/lips_mask/file/" \
     -o "lips_mask.png"

Retrieve model info

Request avatar info (gender, age, and race were stated in parameters on avatar creation request):

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": "male",
  "age": "not_child",
  "gender_confidence": 0.9999961853027344,
  "races": {
    "white": 1,
    "black": 1.785005032672871e-09,
    "asian": 1.384531517212295e-10
  },
  "age_confidence": 1,
  "race_confidence": 1
}
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": "male",
  "age": "not_child",
  "gender_confidence": 0.9999961853027344,
  "races": {
    "white": 1,
    "black": 1.785005032672871e-09,
    "asian": 1.384531517212295e-10
  },
  "age_confidence": 1,
  "race_confidence": 1
}