Bulk Upload Profile Avatars via the API

1. Get All User IDs

The first step in this process is to get the id of all of the users in your workspace. To do that, call this endpoint:

GET https://api.getguru.com/api/v1/members

The response should look something like what you see below. For the third step of this process, you will need the user.id for each user.

[
    {
        "userAttributes": {
            "BILLING_TYPE": "CORE"
        },
        "user": {
            "id": "99af1e84-a0d6-4c56-92b1-5382cf1cdade",
            "status": "ACTIVE",
            "email": "[email protected]",
            "lastName": "Iversonn",
            "firstName": "Allen",
            "profilePicUrl": "https://pp.getguru.com/3a6767f90e994119a0877c2c071599df.png"
        },
        "id": "[email protected]",
        "dateCreated": "2022-02-09T22:01:59.136+0000",
        "groups": [
            {
               <<<groupInfo>>>
            },
            {
               <<<groupInfo>>>
            },
            {
               <<<groupInfo>>>
            }
        ]
    },
    {
          "userAttributes": {
              "BILLING_TYPE": "CORE"
          },
          "user": {
              "id": "a5bee3bb-7bac-4864-979e-cc1041f688f1",
              "status": "ACTIVE",
              "email": "[email protected]",
              "lastName": "Howard",
              "firstName": "Carrie",
              "profilePicUrl": "https://pp.getguru.com/01dde0a3f0434fe2adbb1631a40a29cf.png"
          },
          "id": "[email protected]",
          "dateCreated": "2022-02-09T22:01:59.487+0000",
          "groups": [
              {
                 <<<groupInfo>>>
              },
              {
                 <<<groupInfo>>>
              },
              {
                 <<<groupInfo>>>
              },
              {
                 <<<groupInfo>>>
              },
              {
                 <<<groupInfo>>>
              },
              {
                 <<<groupInfo>>>
              }
          ]
    }
]

2. Upload Avatar File

Now, call the endpoint below to upload an avatar to our system. This step is just getting the file into our system - it is not tying the avatar to the user profile yet. That will be done in the next step.

POST https://api.getguru.com/app/picture

The request should have a body type of form-data, with the key being set to profilePic (file type) and the value being set to the file you are uploading. Here is an cURL example:

curl --location 'https://api.getguru.com/app/picture' \
--header 'Content-Type: multipart/form-data' \
--header 'Accept: application/json' \
--header 'Authorization: <<basic auth>>' \
--form 'profilePic=@"/Users/me/Downloads/myAvatar.png"'

You will receive a JSON response that looks like this:

{
    "uploadedPictureUrl": "https://pp.getguru.com/e4039932194jg3df8b3f7cf997a94a06.png"
}

3. Tie Uploaded Avatar to Profile

Now that we have the user's ID (from Step 1) and the avatar URL (from Step 2), we can associate the avatar with the user's profile. Let's first get the current state of the user's profile using this endpoint:

GET https://api.getguru.com/api/v1/people/{userId}

The response should look something like this:

{
    "pronouns": "",
    "displayName": "Joe Beddia",
    "manager": {
        "displayName": "Joe Duffy Admin",
        "userId": "f92b946e-b1e6-4ec9-adac-7e5c9ed9244e",
        "id": "ef336cec-1de6-4960-a33f-def3625f8efb",
        "email": "[email protected]",
        "profilePicUrl": "https://pp.getguru.com/e4039970b78648df8b3f7cf997a94a06.png",
        "lastName": "Duffy Admin",
        "firstName": "Joe"
    },
    "userId": "8e20337e-f173-45bf-a2e3-a90f6e5d8f5f",
    "slackProfileDetails": [],
    "jobTitle": "Individual Contributor",
    "id": "5b4b8fa9-313c-449c-914d-5ab961105aaa",
    "status": "ACTIVE",
    "email": "[email protected]",
    "profilePicUrl": "https://pp.getguru.com/2217c55f124f495a8910aef02b644be6.png",
    "userProfile": {
        "roleLevel": "Individual Contributor",
        "useCaseList": [],
        "role": "Enablement"
    },
    "lastName": "Beddia",
    "firstName": "Joe"
}

Now call the endpoint below to update the user's profile. Use the response from the API call above and pass it along as the request body in the PUT endpoint below. Replace the profilePicUrl field with the uploadedPictureUrl field from Step 2.

PUT https://api.getguru.com/api/v1/people/{userId}

{
    "pronouns": "",
    "displayName": "Joe Beddia",
    "manager": {
        "displayName": "Joe Duffy Admin",
        "userId": "f92b946e-b1e6-4ec9-adac-7e5c9ed9244e",
        "id": "ef336cec-1de6-4960-a33f-def3625f8efb",
        "email": "[email protected]",
        "profilePicUrl": "https://pp.getguru.com/e4039970b78648df8b3f7cf997a94a06.png",
        "lastName": "Duffy Admin",
        "firstName": "Joe"
    },
    "userId": "8e20337e-f173-45bf-a2e3-a90f6e5d8f5f",
    "slackProfileDetails": [],
    "jobTitle": "Individual Contributor",
    "id": "5b4b8fa9-313c-449c-914d-5ab961105aaa",
    "status": "ACTIVE",
    "email": "[email protected]",
    "profilePicUrl": "https://pp.getguru.com/e4039932194jg3df8b3f7cf997a94a06.png", //this is the new profile pic uploaded in Step 2
    "userProfile": {
        "roleLevel": "Individual Contributor",
        "useCaseList": [],
        "role": "Enablement"
    },
    "lastName": "Beddia",
    "firstName": "Joe"
}