API returning user ID of -1 when uploading avatar

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.

2 Likes

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.

3 Likes

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?