# Failing to change avatar using Discourse API

**URL:** https://meta.discourse.org/t/failing-to-change-avatar-using-discourse-api/261828
**Category:** Development
**Tags:** rest-api
**Created:** [April 16, 2023, 6:39am UTC](https://meta.discourse.org/t/failing-to-change-avatar-using-discourse-api/261828 "2023-04-16T06:39:25Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![EGreg](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/egreg/32/133614_2.png) [@EGreg](https://meta.discourse.org/u/EGreg)
#### Post date: [April 16, 2023, 6:39am UTC](https://meta.discourse.org/t/failing-to-change-avatar-using-discourse-api/261828/1 "2023-04-16T06:39:25Z")

</div>

I have an API key that has “Global” access, for “All Users”.

I do this:

```php
$updateAvatarUrl = sprintf("%s/u/%s/preferences/avatar/pick.json", $this->apiHost, $username);
$headers = array(
    "Api-Key: ".$this->apiKey,
    "Api-Username: ".$this->apiUsername
);
$data = array(
    'upload_id' => $uploadId,
    'type' => 'uploaded'
);
$response = Q_Utils::put($updateAvatarUrl, $data, null, null, $headers);

```

But the result I get back is:

```json
{"failed":"FAILED"}

```

I tried also sending it as `application/json`. Here is the full CURL info:

```php
$url = 'https://community.intercoin.app/u/fdhsjkgfs_dghjkl';

Headers:
0:
"Host: community.intercoin.app"
1:
"User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_1) AppleWebKit/537.36 (K HTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36"
2:
"Content-Type: application/x-www-form-urlencoded"
3:
"Content-Length: 28"
4:
"Api-Key: 3cf975095fd50e22e3631dc916c6d2c7694419ed421338dd7bba432ba1e71417"
5:
"Api-Username: system"

body:

upload_id=2159&type=uploaded

```

You can see that [Profile - fdhsjkgfs\_dghjkl - Intercoin](https://community.intercoin.app/u/fdhsjkgfs_dghjkl) exists.

The upload ID indeed exists too, this is what I get after I do the upload:

```json
{
  "id": 2159,
  "url": "https://community.intercoin.app/uploads/intercoin/original/2X/c/ce6121fe1571faa6c41ad28afdf6c30939ffbc56.png",
  "original_filename": "400.png",
  "filesize": 20636,
  "width": 360,
  "height": 360,
  "thumbnail_width": 360,
  "thumbnail_height": 360,
  "extension": "png",
  "short_url": "upload://trIsPeqspDPRwbMsOnjtDCBBMwK.png",
  "short_path": "/uploads/short-url/trIsPeqspDPRwbMsOnjtDCBBMwK.png",
  "retain_hours": null,
  "human_filesize": "20.2 KB"
}

```

So what is the problem? I followed what the docs say…

---

<div class="post-metadata">

### Author: ![EGreg](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/egreg/32/133614_2.png) [@EGreg](https://meta.discourse.org/u/EGreg)
#### Post date: [April 16, 2023, 7:08am UTC](https://meta.discourse.org/t/failing-to-change-avatar-using-discourse-api/261828/2 "2023-04-16T07:08:01Z")

</div>

And also, for some reason, the links in the description and website are not clickable after I set them using CURL:

 ![image](https://global.discourse-cdn.com/meta/original/4X/5/5/1/551b0da7e8a70d5a505acf6d36aabde145f66a61.jpeg)

But on other summary boxes, they are. With the same URLs.

What am I doing wrong, there?

```php
        Q_Utils::put($this->apiHost."/u/$username.json", array(
            'title' => 'Forum Engagement Bot',
            'bio_raw' => 'Powered by https://engageusers.ai',
            'website' => 'https://engageusers.ai'
        ), null, null, $headers);

```

---

<div class="post-metadata">

### Author: ![EGreg](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/egreg/32/133614_2.png) [@EGreg](https://meta.discourse.org/u/EGreg)
#### Post date: [April 16, 2023, 7:08am UTC](https://meta.discourse.org/t/failing-to-change-avatar-using-discourse-api/261828/3 "2023-04-16T07:08:58Z")

</div>

And finally .. is there any way in forum control panel to make the summary boxes appear fully to the public (with bio, website, etc.) rather than just with limited info?

---

<div class="post-metadata">

### Author: ![Moin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/moin/32/554653_2.png) [@Moin](https://meta.discourse.org/u/Moin)
#### Post date: [April 16, 2023, 7:50am UTC](https://meta.discourse.org/t/failing-to-change-avatar-using-discourse-api/261828/4 "2023-04-16T07:50:31Z")

</div>

> [@EGreg](#):
>
> But on other summary boxes, they are. With the same URLs.

Maybe that’s because these users reached trust level 1. To prevent spam, the links of new users do not work.

---

<div class="post-metadata">

### Author: ![EGreg](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/egreg/32/133614_2.png) [@EGreg](https://meta.discourse.org/u/EGreg)
#### Post date: [April 16, 2023, 8:02am UTC](https://meta.discourse.org/t/failing-to-change-avatar-using-discourse-api/261828/5 "2023-04-16T08:02:09Z")

</div>

Is it possible to set trust level of a user via API?

---

<div class="post-metadata">

### Author: ![Moin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/moin/32/554653_2.png) [@Moin](https://meta.discourse.org/u/Moin)
#### Post date: [April 16, 2023, 8:06am UTC](https://meta.discourse.org/t/failing-to-change-avatar-using-discourse-api/261828/6 "2023-04-16T08:06:02Z")

</div>

I just searched here and found

> [@Update user details](https://meta.discourse.org/t/update-user-details/238554):
>
> Hi, I was wondering how can we update users group and trust level via API. I haven’t found anything in the docs. Much appreciated.

> [@Update user details](https://meta.discourse.org/t/update-user-details/238554/2):
>
> See [How to reverse engineer the Discourse API](https://meta.discourse.org/t/how-to-reverse-engineer-the-discourse-api/20576)

So it seems possible.

---

<div class="post-metadata">

### Author: ![EGreg](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/egreg/32/133614_2.png) [@EGreg](https://meta.discourse.org/u/EGreg)
#### Post date: [April 16, 2023, 4:55pm UTC](https://meta.discourse.org/t/failing-to-change-avatar-using-discourse-api/261828/7 "2023-04-16T16:55:38Z")

</div>

By the way, the answer to the original question was that “SSO overrides avatar” was turned on. Turning it off solved the problem.

I was also able to successfully upgrade the trust level via the API and this causes the full summary box to appear. Thanks, fam!
