API returning user ID of -1 when uploading avatar

AI-generated summary

The issue is with the Dischord API returning a user ID of -1 when uploading an avatar. Frank_Bailey is testing the API with Postman and successfully uploads the image, but it’s not assigned to any user. DeanMarkTaylor suggests that the api_username parameter is set to system, resulting in a default ID of -1, which is used to identify bots.

MakaryGo provides the solution, stating that a second API call (PUT /users/{username}/preferences/avatar/pick) is required to assign the uploaded avatar to the user, using the upload_id returned by the initial request. Frank_Bailey confirms that this resolves the issue and suggests that the documentation should be clearer about the need for this second step. MakaryGo explains that the user_id in the first request is for authentication purposes, specifically the API Key issued for that user.

I’m trying to use the Dischord API to upload user avatars. I’m testing with Postman because I couldn’t get it working with curl in PHP. With Postman I can see that the POST to the API is actually succeeding, but that the avatar is not assigned to any user. The response shows a user ID of -1, which would seem to indicate that something is going wrong in the background. Here is my Postman config

I can’t see anything obviously wrong with the way I’ve set it up, and the images are definitely getting uploaded and cropped and resized (I’ve checked that the URLs in the responses do in fact exist). If anyone has any insight into what might be going wrong I’d be grateful.

EDIT: The same response is received regardless of whether I set synchronous to true or false.

The parameter api_username specifies the user you are executing the API action as…
… in this case you are likely using system where the default ID for this user is -1.

Negative value user ID’s I believe are used to identify bots.

According to http://docs.discourse.org I believe you should afterwards send a
PUT /users/{username}/preferences/avatar/pick
with upload_id returned by this.

That was just the ticket, thank you MakaryGo :slight_smile:

I think the documentation should be a bit clearer that the second step is required, because what’s the point of specifying the user_id in the first request if the uploaded avatar isn’t automatically assigned to the user?

Because you have to specify user_id that is connecting with API, the one that the API Key is issued for, I guess?