# Off-site avatar via API?

**URL:** https://meta.discourse.org/t/off-site-avatar-via-api/168370
**Category:** Development
**Tags:** rest-api
**Created:** [October 27, 2020, 10:55am UTC](https://meta.discourse.org/t/off-site-avatar-via-api/168370 "2020-10-27T10:55:51Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Judith](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/judith/32/289903_2.png) [@Judith](https://meta.discourse.org/u/Judith)
#### Post date: [October 27, 2020, 10:55am UTC](https://meta.discourse.org/t/off-site-avatar-via-api/168370/1 "2020-10-27T10:55:51Z")

</div>

I have a community Rails site. I’m using SSO so that community members don’t have to separately log into Discourse and I’m using the Discourse API in order to facilitate exchange of information between the two servers. Now I’d like to unify user avatars, i.e. use the same avatar on the forum as on my main site. How do I do that?

I tried what I usually do for API requests, namely a Faraday POST request to [https://discuss.diem25.org/uploads.json](https://discuss.diem25.org/uploads.json) with API key and API-Username in the header and the following body:

```plaintext
{ 
          "type": "avatar", 
          "user_id": user_id,
          "file": "https://internal.diem25.org/.../user.jpg",
          "synchronous": "true"
        }

```

This request results in an Internal Server Error. I’m also not opposed to re-uploading the file as a last resort, but that seems to be difficult to impossible at first glance, using Faraday.

---

<div class="post-metadata">

### Author: ![osioke](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/osioke/32/238946_2.png) [@osioke](https://meta.discourse.org/u/osioke)
#### Post date: [October 27, 2020, 11:27am UTC](https://meta.discourse.org/t/off-site-avatar-via-api/168370/2 "2020-10-27T11:27:17Z")

</div>

Why not try the `sso overrides avatar` site setting and pass the avatar URL with the SSO system? It may be better to handle this with SSO rather than making uploads manually with the API.

---

<div class="post-metadata">

### Author: ![Judith](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/judith/32/289903_2.png) [@Judith](https://meta.discourse.org/u/Judith)
#### Post date: [October 27, 2020, 12:26pm UTC](https://meta.discourse.org/t/off-site-avatar-via-api/168370/3 "2020-10-27T12:26:24Z")

</div>

Thanks, that’s a good idea, it just poses the integration problem the other way round, because right now some users have an avatar on Discourse and don’t have an avatar on my site. So my choices are, it seems, to upload all Discourse avatars to my site and then set “sso overrides avatar”, or to upload all of my avatars to Discourse. 😒

---

<div class="post-metadata">

### Author: ![blake](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/blake/32/157322_2.png) [@blake](https://meta.discourse.org/u/blake)
#### Post date: [October 28, 2020, 6:29pm UTC](https://meta.discourse.org/t/off-site-avatar-via-api/168370/4 "2020-10-28T18:29:22Z")

</div>

> [@Judith](#):
>
> This request results in an Internal Server Error.

I think that is because you can’t just specify a url for a file in faraday, it has to be read in as a file first, or something like that.

However, you can use the discourse\_api gem to update an avatar by specifying a url:

```plaintext
client.update_avatar(
  username: "norbert6",
  url: "http://vignette1.wikia.nocookie.net/despicableme/images/1/15/Jerryindespicableme.png"
)

```
