Contents
This page contains a step-by-step tutorial on how to retrieve the OAuth Bearer token, create a Player ID, retrieve available avatar creation and export parameters, create a MetaPerson avatar from a photo and download avatar's mesh, blendshapes and haircut in glb format and its textures 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.
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 the authorization procedure again.
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"
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 that will own all future avatars. Please note, that the Player ID does not expire.
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-04-14T07:09:55.976235Z", "comment": "curl sample" } SET "PLAYER=16322807-89e3-4223-a83c-1d6afa8abd11"
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-04-14T07:09:55.976235Z", "comment": "curl sample" } PLAYER="16322807-89e3-4223-a83c-1d6afa8abd11"
Query all available parameters for the female subtype of body_0.3 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.
curl -H "Authorization: Bearer %TOKEN%" ^ -X GET ^ "https://api.avatarsdk.com/parameters/available/body_0.3/?pipeline_subtype=female" { "female": { "avatar_modifications": [ "eye_iris_color", "eye_sclera_color", "parametric_eyes_texture", "teeth_color", "generated_haircut_texture_size", "generated_haircut_faces_count", "remove_smile", "remove_glasses", "remove_stubble", "enhance_lighting", "slightly_cartoonish_texture" ], "model_info": [ "gender", "race", "age", "hair_color", "skin_color", "eye_sclera_color", "eye_iris_color", "facial_landmarks_68" ] } }
curl -H "Authorization: Bearer $TOKEN" \ -X GET \ "https://api.avatarsdk.com/parameters/available/body_0.3/?pipeline_subtype=female" { "female": { "avatar_modifications": [ "eye_iris_color", "eye_sclera_color", "parametric_eyes_texture", "teeth_color", "generated_haircut_texture_size", "generated_haircut_faces_count", "remove_smile", "remove_glasses", "remove_stubble", "enhance_lighting", "slightly_cartoonish_texture" ], "model_info": [ "gender", "race", "age", "hair_color", "skin_color", "eye_sclera_color", "eye_iris_color", "facial_landmarks_68" ] } }
Query all available enumerable export parameters for the female subtype of body_0.3 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.
curl -H "Authorization: Bearer %TOKEN%" ^ -X GET ^ "https://api.avatarsdk.com/export_parameters/available/body_0.3/?pipeline_subtype=female" { "blendshapes": [ "mobile_51", "visemes_15" ], "haircuts": [ "generated", "long_disheveled", "long_wavy", "mid_length_straight", "ponytail_with_bangs", "short_disheveled", "short_simple", "afro", "afro_short", "balding", "balding2", "bob", "bob_parted", "burr_cut", "classic_side_part", "classic_tapper", "cowlick", "cowlick2", "crew_cut", "crew_cut2", "crew_cut3", "cuckoo_nest", "curtained_hair", "flattop", "high_volume_brushed_up", "long_afro", "long_bob", "long_dreads", "long_hair", "long_hair2", "man_bun", "man_bun2", "mid_length_curved", "ponytail", "rasta", "short_bob_asymmetrical_bangs", "short_curls", "short_curls2", "short_parted", "short_slick", "side_french_braid", "straight_bob_bangs", "top_knot", "wavy_shag", "corkscrew_curls", "long_crimped", "mid_length_ruffled", "mid_length_straight2", "mid_length_wispy", "roman", "shoulder_length", "very_long", "wavy_bob" ], "outfits": [ "outfit_meta_0", "outfit_meta_2", "outfit_meta_3" ] }
curl -H "Authorization: Bearer $TOKEN" \ -X GET \ "https://api.avatarsdk.com/export_parameters/available/body_0.3/?pipeline_subtype=female" { "blendshapes": [ "mobile_51", "visemes_15" ], "haircuts": [ "generated", "long_disheveled", "long_wavy", "mid_length_straight", "ponytail_with_bangs", "short_disheveled", "short_simple", "afro", "afro_short", "balding", "balding2", "bob", "bob_parted", "burr_cut", "classic_side_part", "classic_tapper", "cowlick", "cowlick2", "crew_cut", "crew_cut2", "crew_cut3", "cuckoo_nest", "curtained_hair", "flattop", "high_volume_brushed_up", "long_afro", "long_bob", "long_dreads", "long_hair", "long_hair2", "man_bun", "man_bun2", "mid_length_curved", "ponytail", "rasta", "short_bob_asymmetrical_bangs", "short_curls", "short_curls2", "short_parted", "short_slick", "side_french_braid", "straight_bob_bangs", "top_knot", "wavy_shag", "corkscrew_curls", "long_crimped", "mid_length_ruffled", "mid_length_straight2", "mid_length_wispy", "roman", "shoulder_length", "very_long", "wavy_bob" ], "outfits": [ "outfit_meta_0", "outfit_meta_2", "outfit_meta_3" ] }
We will use the following computation parameters for our avatar:
{ "avatar_modifications": { "remove_smile": true, "remove_glasses": true, "enhance_lighting": true } }
And the following export parameters:
{ "format": "glb", "blendshapes": { "list": ["mobile_51", "visemes_15"], "embed": true }, "haircuts": { "list": ["generated"], "embed": false }, "outfits": { "list": ["outfit_meta_0", "outfit_meta_2", "outfit_meta_3"] } }
Create an avatar with the parameters above and the photo.jpg image from the current directory (adjust path if necessary):
curl -H "Authorization: Bearer %TOKEN%" ^ -H "X-PlayerUID: %PLAYER%" ^ -X POST "https://api.avatarsdk.com/avatars/" ^ -F "name=test from curl sample" ^ -F "pipeline=body_0.3" ^ -F "pipeline_subtype=female" ^ -F "parameters={\"avatar_modifications\": {\"remove_smile\": true, \"remove_glasses\": true, \"enhance_lighting\": true}}" ^ -F "export_parameters={\"format\": \"glb\", \"blendshapes\": {\"list\": [\"mobile_51\", \"visemes_15\"], \"embed\": true}, \"haircuts\": {\"list\": [\"generated\"], \"embed\": false}, \"outfits\": {\"list\": [\"outfit_meta_0\", \"outfit_meta_2\", \"outfit_meta_3\"]}}" ^ -F "photo=@photo.jpg" { "code": "096281e9-fc9e-4b5b-bf3d-9ac68b5ca637", "created_on": "2020-11-24T13:39:53.490812Z", "description": "test from curl sample", "progress": 0, "status": "Uploading", "url": "https://api.avatarsdk.com/avatars/096281e9-fc9e-4b5b-bf3d-9ac68b5ca637/" } SET "AVATAR=096281e9-fc9e-4b5b-bf3d-9ac68b5ca637"
curl -H "Authorization: Bearer $TOKEN" \ -H "X-PlayerUID: $PLAYER" \ -X POST "https://api.avatarsdk.com/avatars/" \ -F "name=test from curl sample" \ -F "pipeline=body_0.3" \ -F "pipeline_subtype=female" \ -F "parameters={\"avatar_modifications\": {\"remove_smile\": true, \"remove_glasses\": true, \"enhance_lighting\": true}}" \ -F "export_parameters={\"format\": \"glb\", \"blendshapes\": {\"list\": [\"mobile_51\", \"visemes_15\"], \"embed\": true}, \"haircuts\": {\"list\": [\"generated\"], \"embed\": false}, \"outfits\": {\"list\": [\"outfit_meta_0\", \"outfit_meta_2\", \"outfit_meta_3\"]}}" \ -F "photo=@photo.jpg" { "code": "096281e9-fc9e-4b5b-bf3d-9ac68b5ca637", "created_on": "2020-11-24T13:39:53.490812Z", "description": "test from curl sample", "progress": 0, "status": "Uploading", "url": "https://api.avatarsdk.com/avatars/096281e9-fc9e-4b5b-bf3d-9ac68b5ca637/" } AVATAR="096281e9-fc9e-4b5b-bf3d-9ac68b5ca637"
Avatar computation starts after uploading the photo. Request the avatar status periodically (once per 5 seconds should be enough) to check avatar computation status and progress:
curl -H "Authorization: Bearer %TOKEN%" ^ -H "X-PlayerUID: %PLAYER%" ^ -X GET ^ "https://api.avatarsdk.com/avatars/%AVATAR%/" { "blendshapes": "https://api.avatarsdk.com/avatars/096281e9-fc9e-4b5b-bf3d-9ac68b5ca637/blendshapes/", "code": "096281e9-fc9e-4b5b-bf3d-9ac68b5ca637", "created_on": "2020-11-24T13:39:53.490812Z", "ctime": null, "description": "", "exports": "https://api.avatarsdk.com/avatars/096281e9-fc9e-4b5b-bf3d-9ac68b5ca637/exports/", "haircuts": "https://api.avatarsdk.com/avatars/096281e9-fc9e-4b5b-bf3d-9ac68b5ca637/haircuts/", "mesh": "https://api.avatarsdk.com/avatars/096281e9-fc9e-4b5b-bf3d-9ac68b5ca637/mesh/", "model_info": "https://api.avatarsdk.com/avatars/096281e9-fc9e-4b5b-bf3d-9ac68b5ca637/model_info/", "name": "test from curl sample", "pipeline": null, "pipeline_subtype": null, "preview": "https://api.avatarsdk.com/avatars/096281e9-fc9e-4b5b-bf3d-9ac68b5ca637/preview/", "progress": 0, "status": "Computing", "texture": "https://api.avatarsdk.com/avatars/096281e9-fc9e-4b5b-bf3d-9ac68b5ca637/texture/", "thumbnail": "https://api.avatarsdk.com/avatars/096281e9-fc9e-4b5b-bf3d-9ac68b5ca637/thumbnail/", "url": "https://api.avatarsdk.com/avatars/096281e9-fc9e-4b5b-bf3d-9ac68b5ca637/" }
curl -H "Authorization: Bearer $TOKEN" \ -H "X-PlayerUID: $PLAYER" \ -X GET \ "https://api.avatarsdk.com/avatars/$AVATAR/" { "blendshapes": "https://api.avatarsdk.com/avatars/096281e9-fc9e-4b5b-bf3d-9ac68b5ca637/blendshapes/", "code": "096281e9-fc9e-4b5b-bf3d-9ac68b5ca637", "created_on": "2020-11-24T13:39:53.490812Z", "ctime": null, "description": "", "exports": "https://api.avatarsdk.com/avatars/096281e9-fc9e-4b5b-bf3d-9ac68b5ca637/exports/", "haircuts": "https://api.avatarsdk.com/avatars/096281e9-fc9e-4b5b-bf3d-9ac68b5ca637/haircuts/", "mesh": "https://api.avatarsdk.com/avatars/096281e9-fc9e-4b5b-bf3d-9ac68b5ca637/mesh/", "model_info": "https://api.avatarsdk.com/avatars/096281e9-fc9e-4b5b-bf3d-9ac68b5ca637/model_info/", "name": "test from curl sample", "pipeline": null, "pipeline_subtype": null, "preview": "https://api.avatarsdk.com/avatars/096281e9-fc9e-4b5b-bf3d-9ac68b5ca637/preview/", "progress": 0, "status": "Computing", "texture": "https://api.avatarsdk.com/avatars/096281e9-fc9e-4b5b-bf3d-9ac68b5ca637/texture/", "thumbnail": "https://api.avatarsdk.com/avatars/096281e9-fc9e-4b5b-bf3d-9ac68b5ca637/thumbnail/", "url": "https://api.avatarsdk.com/avatars/096281e9-fc9e-4b5b-bf3d-9ac68b5ca637/" }
Once the avatar is ready, its status is set to Completed and progress is 100:
curl -H "Authorization: Bearer %TOKEN%" ^ -H "X-PlayerUID: %PLAYER%" ^ -X GET ^ "https://api.avatarsdk.com/avatars/%AVATAR%/" { "blendshapes": "https://api.avatarsdk.com/avatars/096281e9-fc9e-4b5b-bf3d-9ac68b5ca637/blendshapes/", "code": "096281e9-fc9e-4b5b-bf3d-9ac68b5ca637", "created_on": "2020-11-24T13:39:53.490812Z", "ctime": null, "description": "", "exports": "https://api.avatarsdk.com/avatars/096281e9-fc9e-4b5b-bf3d-9ac68b5ca637/exports/", "haircuts": "https://api.avatarsdk.com/avatars/096281e9-fc9e-4b5b-bf3d-9ac68b5ca637/haircuts/", "mesh": "https://api.avatarsdk.com/avatars/096281e9-fc9e-4b5b-bf3d-9ac68b5ca637/mesh/", "model_info": "https://api.avatarsdk.com/avatars/096281e9-fc9e-4b5b-bf3d-9ac68b5ca637/model_info/", "name": "test from curl sample", "pipeline": "body_0.3", "pipeline_subtype": "female", "preview": "https://api.avatarsdk.com/avatars/096281e9-fc9e-4b5b-bf3d-9ac68b5ca637/preview/", "progress": 100, "status": "Completed", "texture": "https://api.avatarsdk.com/avatars/096281e9-fc9e-4b5b-bf3d-9ac68b5ca637/texture/", "thumbnail": "https://api.avatarsdk.com/avatars/096281e9-fc9e-4b5b-bf3d-9ac68b5ca637/thumbnail/", "url": "https://api.avatarsdk.com/avatars/096281e9-fc9e-4b5b-bf3d-9ac68b5ca637/" }
curl -H "Authorization: Bearer $TOKEN" \ -H "X-PlayerUID: $PLAYER" \ -X GET \ "https://api.avatarsdk.com/avatars/$AVATAR/" { "blendshapes": "https://api.avatarsdk.com/avatars/096281e9-fc9e-4b5b-bf3d-9ac68b5ca637/blendshapes/", "code": "096281e9-fc9e-4b5b-bf3d-9ac68b5ca637", "created_on": "2020-11-24T13:39:53.490812Z", "ctime": null, "description": "", "exports": "https://api.avatarsdk.com/avatars/096281e9-fc9e-4b5b-bf3d-9ac68b5ca637/exports/", "haircuts": "https://api.avatarsdk.com/avatars/096281e9-fc9e-4b5b-bf3d-9ac68b5ca637/haircuts/", "mesh": "https://api.avatarsdk.com/avatars/096281e9-fc9e-4b5b-bf3d-9ac68b5ca637/mesh/", "model_info": "https://api.avatarsdk.com/avatars/096281e9-fc9e-4b5b-bf3d-9ac68b5ca637/model_info/", "name": "test from curl sample", "pipeline": "body_0.3", "pipeline_subtype": "female", "preview": "https://api.avatarsdk.com/avatars/096281e9-fc9e-4b5b-bf3d-9ac68b5ca637/preview/", "progress": 100, "status": "Completed", "texture": "https://api.avatarsdk.com/avatars/096281e9-fc9e-4b5b-bf3d-9ac68b5ca637/texture/", "thumbnail": "https://api.avatarsdk.com/avatars/096281e9-fc9e-4b5b-bf3d-9ac68b5ca637/thumbnail/", "url": "https://api.avatarsdk.com/avatars/096281e9-fc9e-4b5b-bf3d-9ac68b5ca637/" }
Once the avatar is ready, check avatar exports status:
curl -H "Authorization: Bearer %TOKEN%" ^ -H "X-PlayerUID: %PLAYER%" ^ -X GET ^ "https://api.avatarsdk.com/avatars/%AVATAR%/exports/" [ { "status": "Completed", "files": [ { "category": "haircuts", "static_files": [], "identity": "generated", "file": "https://api.avatarsdk.com/avatars/096281e9-fc9e-4b5b-bf3d-9ac68b5ca637/exports/bd051c28-d0f3-4fd4-b82d-f3428ab36213/files/generated/file/" }, { "category": null, "static_files": [ "https://api.avatarsdk.com/avatars/096281e9-fc9e-4b5b-bf3d-9ac68b5ca637/exports/bd051c28-d0f3-4fd4-b82d-f3428ab36213/files/avatar/static_files/outfit_meta_0.png", "https://api.avatarsdk.com/avatars/096281e9-fc9e-4b5b-bf3d-9ac68b5ca637/exports/bd051c28-d0f3-4fd4-b82d-f3428ab36213/files/avatar/static_files/outfit_meta_2.png", "https://api.avatarsdk.com/avatars/096281e9-fc9e-4b5b-bf3d-9ac68b5ca637/exports/bd051c28-d0f3-4fd4-b82d-f3428ab36213/files/avatar/static_files/outfit_meta_3.png" ], "identity": "avatar", "file": "https://api.avatarsdk.com/avatars/096281e9-fc9e-4b5b-bf3d-9ac68b5ca637/exports/bd051c28-d0f3-4fd4-b82d-f3428ab36213/files/avatar/file/" } ], "code": "bd051c28-d0f3-4fd4-b82d-f3428ab36213", "url": "https://api.avatarsdk.com/avatars/096281e9-fc9e-4b5b-bf3d-9ac68b5ca637/exports/bd051c28-d0f3-4fd4-b82d-f3428ab36213/", "created_on": "2020-11-24T13:55:25.831538Z", "avatar_code": "096281e9-fc9e-4b5b-bf3d-9ac68b5ca637" } ] SET "EXPORT=bd051c28-d0f3-4fd4-b82d-f3428ab36213"
curl -H "Authorization: Bearer $TOKEN" \ -H "X-PlayerUID: $PLAYER" \ -X GET \ "https://api.avatarsdk.com/avatars/$AVATAR/exports/" [ { "status": "Completed", "files": [ { "category": "haircuts", "static_files": [], "identity": "generated", "file": "https://api.avatarsdk.com/avatars/096281e9-fc9e-4b5b-bf3d-9ac68b5ca637/exports/bd051c28-d0f3-4fd4-b82d-f3428ab36213/files/generated/file/" }, { "category": null, "static_files": [ "https://api.avatarsdk.com/avatars/096281e9-fc9e-4b5b-bf3d-9ac68b5ca637/exports/bd051c28-d0f3-4fd4-b82d-f3428ab36213/files/avatar/static_files/outfit_meta_0.png", "https://api.avatarsdk.com/avatars/096281e9-fc9e-4b5b-bf3d-9ac68b5ca637/exports/bd051c28-d0f3-4fd4-b82d-f3428ab36213/files/avatar/static_files/outfit_meta_2.png" "https://api.avatarsdk.com/avatars/096281e9-fc9e-4b5b-bf3d-9ac68b5ca637/exports/bd051c28-d0f3-4fd4-b82d-f3428ab36213/files/avatar/static_files/outfit_meta_3.png" ], "identity": "avatar", "file": "https://api.avatarsdk.com/avatars/096281e9-fc9e-4b5b-bf3d-9ac68b5ca637/exports/bd051c28-d0f3-4fd4-b82d-f3428ab36213/files/avatar/file/" } ], "code": "bd051c28-d0f3-4fd4-b82d-f3428ab36213", "url": "https://api.avatarsdk.com/avatars/096281e9-fc9e-4b5b-bf3d-9ac68b5ca637/exports/bd051c28-d0f3-4fd4-b82d-f3428ab36213/", "created_on": "2020-11-24T13:55:25.831538Z", "avatar_code": "096281e9-fc9e-4b5b-bf3d-9ac68b5ca637" } ] EXPORT="bd051c28-d0f3-4fd4-b82d-f3428ab36213"
Once the avatar export is ready, download all its files: avatar mesh with blendshapes and outfits in one unified glb (as requested per export parameters), generated haircut and afro haircut with one static file (haircut texture):
curl -H "Authorization: Bearer %TOKEN%" ^ -H "X-PlayerUID: %PLAYER%" ^ -X GET ^ "https://api.avatarsdk.com/avatars/%AVATAR%/exports/%EXPORT%/files/avatar/file/" ^ -o "model.zip" curl -H "Authorization: Bearer %TOKEN%" ^ -H "X-PlayerUID: %PLAYER%" ^ -X GET ^ "https://api.avatarsdk.com/avatars/%AVATAR%/exports/%EXPORT%/files/avatar/static_files/outfit_meta_0.png" ^ -o "outfit_meta_0.png" curl -H "Authorization: Bearer %TOKEN%" ^ -H "X-PlayerUID: %PLAYER%" ^ -X GET ^ "https://api.avatarsdk.com/avatars/%AVATAR%/exports/%EXPORT%/files/avatar/static_files/outfit_meta_2.png" ^ -o "outfit_meta_2.png" curl -H "Authorization: Bearer %TOKEN%" ^ -H "X-PlayerUID: %PLAYER%" ^ -X GET ^ "https://api.avatarsdk.com/avatars/%AVATAR%/exports/%EXPORT%/files/avatar/static_files/outfit_meta_3.png" ^ -o "outfit_meta_3.png" curl -H "Authorization: Bearer %TOKEN%" ^ -H "X-PlayerUID: %PLAYER%" ^ -X GET ^ "https://api.avatarsdk.com/avatars/%AVATAR%/exports/%EXPORT%/files/generated/file/" ^ -o "generated.zip"
curl -H "Authorization: Bearer $TOKEN" \ -H "X-PlayerUID: $PLAYER" \ -X GET \ "https://api.avatarsdk.com/avatars/$AVATAR/exports/$EXPORT/files/avatar/file/" \ -o "model.zip" curl -H "Authorization: Bearer $TOKEN" \ -H "X-PlayerUID: $PLAYER" \ -X GET \ "https://api.avatarsdk.com/avatars/$AVATAR/exports/$EXPORT/files/avatar/static_files/outfit_meta_0.png" \ -o "outfit_meta_0.png" curl -H "Authorization: Bearer $TOKEN" \ -H "X-PlayerUID: $PLAYER" \ -X GET \ "https://api.avatarsdk.com/avatars/$AVATAR/exports/$EXPORT/files/avatar/static_files/outfit_meta_2.png" \ -o "outfit_meta_2.png" curl -H "Authorization: Bearer $TOKEN" \ -H "X-PlayerUID: $PLAYER" \ -X GET \ "https://api.avatarsdk.com/avatars/$AVATAR/exports/$EXPORT/files/avatar/static_files/outfit_meta_3.png" \ -o "outfit_meta_3.png" curl -H "Authorization: Bearer $TOKEN" \ -H "X-PlayerUID: $PLAYER" \ -X GET \ "https://api.avatarsdk.com/avatars/$AVATAR/exports/$EXPORT/files/generated/file/" \ -o "generated.zip"