How to upload avatars on Assets objects using REST API
Platform Notice: Cloud - This article applies to Atlassian products on the cloud platform.
Warning
This article makes use of Assets internal APIs, which might sometimes experience changes without prior notice, and their functionality may not always be guaranteed. Only our Assets official API is supported. Feel free to explore and use them, but please be mindful and cautious while doing so.
Purpose
There can be instances when customers want to upload avatars on objects using REST API. This is done in two steps:
- You need to upload the avatar first by specifying a UUID that you will generate on your own. When an avatar is uploaded successfully, the response returned will contain the server UUID.
- Then you use this server UUID with the Create/Edit object REST API which will create/update the object successfully with the uploaded avatar.
Solution
Use the below steps to upload an avatar on an object:
Step1: Upload the Avatar
First, do a POST to the following internal endpoint to upload the avatar: /jsm/assets/workspace/{workspaceId}/v1/avatar/upload
Additional Tip
Try the following URL to find the workspace id for the Assets instance running on your cloud site: https://<YOURSITE>.atlassian.net/rest/servicedeskapi/assets/workspace
Note that this endpoint accepts multipart/form-data
as the body type and expects the below two required fields:
file
: This is where you specify the file that contains your avataravatarUUID
: You can use a UUID online generator to generate a UUID or if you are using Postman, you can use, \{{$guid}} which will generate the UUID for you.
You send the request which will look something like the below:
curl --request POST 'https://api.atlassian.com/jsm/assets/workspace/{workspaceId}/v1/avatar/upload' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--header 'X-Atlassian-Token: no-check' \
--header 'Authorization: Basic <emailaddress:API token>' \
--form 'file=@"<yourfile>"' \
--form 'avatarUUID="<Client generated UUID>"'
You can also use Postman to send this request which will look as below:
If the call is successful, you will receive a 201 response and the server UUID will also be returned. The response with look something like below
{
"workspaceId": "<yourworkspaceID>",
"avatarUUID": "d9dd0d72-3347-4a5b-8bd9-e3ffb33fbbe8",
"url16": "https://api.atlassian.com/jsm/assets/workspace/<yourworkspaceID>/v1/avatar/d9dd0d72-3347-4a5b-8bd9-e3ffb33fbbe8/preview_16.png",
"url48": "https://api.atlassian.com/jsm/assets/workspace/<yourworkspaceID>/v1/avatar/d9dd0d72-3347-4a5b-8bd9-e3ffb33fbbe8/preview_48.png",
"url72": "https://api.atlassian.com/jsm/assets/workspace/<yourworkspaceID>/v1/avatar/d9dd0d72-3347-4a5b-8bd9-e3ffb33fbbe8/preview_72.png",
"url144": "https://api.atlassian.com/jsm/assets/workspace/<yourworkspaceID>/v1/avatar/d9dd0d72-3347-4a5b-8bd9-e3ffb33fbbe8/preview_144.png",
"url288": "https://api.atlassian.com/jsm/assets/workspace/<yourworkspaceID>/v1/avatar/d9dd0d72-3347-4a5b-8bd9-e3ffb33fbbe8/preview_288.png"
}
Step2: Associate the Avatar with the object
You can then use this server avatarUUID in your Create object / Edit object REST API call to upload the avatar on the object as shown below:
{
"objectTypeId": "2",
"attributes": [
{
"objectTypeAttributeId": "11",
"objectAttributeValues": [
{
"value": "Uploading avatar"
}
]
}
],
"avatarUUID": "d9dd0d72-3347-4a5b-8bd9-e3ffb33fbbe8",
"hasAvatar": true
}
This will associate the uploaded avatar to the object.
Here is the Assets REST API documentation: The Assets REST API