# API returning user ID of -1 when uploading avatar

**URL:** https://meta.discourse.org/t/api-returning-user-id-of-1-when-uploading-avatar/71784
**Category:** Development
**Created:** [Outubro 10, 2017, 8:45pm UTC](https://meta.discourse.org/t/api-returning-user-id-of-1-when-uploading-avatar/71784 "2017-10-10T20:45:16Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Frank\_Bailey](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/frank_bailey/32/83927_2.png) [@Frank\_Bailey](https://meta.discourse.org/u/Frank_Bailey)
#### Post date: [Outubro 10, 2017, 8:45pm UTC](https://meta.discourse.org/t/api-returning-user-id-of-1-when-uploading-avatar/71784/1 "2017-10-10T20:45:16Z")

</div>

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

 ![upload_issue](https://global.discourse-cdn.com/meta/original/3X/4/6/4655f6799f94095d24b1ea50fd310cf4c46a30ae.jpg)

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`.

---

<div class="post-metadata">

### Author: ![DeanMarkTaylor](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/deanmarktaylor/32/102462_2.png) [@DeanMarkTaylor](https://meta.discourse.org/u/DeanMarkTaylor)
#### Post date: [Outubro 10, 2017, 10:07pm UTC](https://meta.discourse.org/t/api-returning-user-id-of-1-when-uploading-avatar/71784/2 "2017-10-10T22:07:15Z")

</div>

> [@Frank\_Bailey](#):
>
> The response shows a user ID of -1, which would seem to indicate that something is going wrong in the background.

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.

---

<div class="post-metadata">

### Author: ![MakaryGo](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/makarygo/32/187426_2.png) [@MakaryGo](https://meta.discourse.org/u/MakaryGo)
#### Post date: [Outubro 10, 2017, 10:15pm UTC](https://meta.discourse.org/t/api-returning-user-id-of-1-when-uploading-avatar/71784/3 "2017-10-10T22:15:59Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Frank\_Bailey](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/frank_bailey/32/83927_2.png) [@Frank\_Bailey](https://meta.discourse.org/u/Frank_Bailey)
#### Post date: [Outubro 11, 2017, 5:25am UTC](https://meta.discourse.org/t/api-returning-user-id-of-1-when-uploading-avatar/71784/4 "2017-10-11T05:25:07Z")

</div>

That was just the ticket, thank you MakaryGo 🙂

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?

---

<div class="post-metadata">

### Author: ![MakaryGo](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/makarygo/32/187426_2.png) [@MakaryGo](https://meta.discourse.org/u/MakaryGo)
#### Post date: [Outubro 11, 2017, 9:36am UTC](https://meta.discourse.org/t/api-returning-user-id-of-1-when-uploading-avatar/71784/5 "2017-10-11T09:36:45Z")

</div>

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