# Social profile

> POST /social/profile reads the public profile of a GitHub, Bluesky or Mastodon account from its official API: name, bio, followers, posts, join date and links.

`POST https://api.qelka.com/v1/social/profile`

Read the public profile of a GitHub, Bluesky or Mastodon account from the platform's official API, without signing in: name, bio, location, company, follower and post counts, creation date and the links the person published. Each lookup costs 1 credit when the platform answered, whether the profile exists or not.

## Request

| Field | Type | Required | Default | Description |
|---|---|---|---|---|
| `username` | string | Yes | none | A username with `platform`, a Bluesky handle with a dot (`bsky.app`), a Mastodon address (`user@server`), or a profile URL (`https://github.com/torvalds`, `https://bsky.app/profile/bsky.app`, `https://mastodon.social/@Gargron`). 1 to 2,048 characters. |
| `platform` | string | No | from `username` | `github`, `bluesky` or `mastodon`. Required for a plain username; a URL, a Mastodon address or a handle with a dot sets the platform. |
| `fresh` | boolean | No | `false` | `true` skips the 24-hour result cache and asks the platform again. |

A plain username sent with `platform: "mastodon"` is looked up on mastodon.social. A Bluesky handle without a dot gets `.bsky.social` appended. When both a URL and `platform` are sent, they must name the same platform.

```bash title="cURL"
curl https://api.qelka.com/v1/social/profile \
  --max-time 30 \
  -H "Authorization: Bearer $QELKA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"username": "torvalds", "platform": "github"}'
```
```javascript title="Node.js"
const response = await fetch('https://api.qelka.com/v1/social/profile', {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.QELKA_API_KEY}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({ username: 'torvalds', platform: 'github' }),
  signal: AbortSignal.timeout(30_000),
})
const result = await response.json()
console.log(result)
```
```python title="Python"
import os

import requests

api_key = os.environ["QELKA_API_KEY"]
response = requests.post(
    "https://api.qelka.com/v1/social/profile",
    headers={"Authorization": f"Bearer {api_key}"},
    json={"username": "torvalds", "platform": "github"},
    timeout=30,
)
result = response.json()
print(result)
```
```php title="PHP"
<?php
$ch = curl_init('https://api.qelka.com/v1/social/profile');
curl_setopt_array($ch, [
    CURLOPT_POST => true,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => [
        'Authorization: Bearer ' . getenv('QELKA_API_KEY'),
        'Content-Type: application/json',
    ],
    CURLOPT_POSTFIELDS => json_encode(['username' => 'torvalds', 'platform' => 'github']),
    CURLOPT_TIMEOUT => 30,
]);
$result = json_decode(curl_exec($ch), true);
print_r($result);
```
```go title="Go"
package main

import (
	"bytes"
	"encoding/json"
	"fmt"
	"net/http"
	"os"
	"time"
)

func main() {
	payload, _ := json.Marshal(map[string]any{"username": "torvalds", "platform": "github"})
	request, _ := http.NewRequest(http.MethodPost, "https://api.qelka.com/v1/social/profile", bytes.NewReader(payload))
	request.Header.Set("Authorization", "Bearer "+os.Getenv("QELKA_API_KEY"))
	request.Header.Set("Content-Type", "application/json")

	client := &http.Client{Timeout: 30 * time.Second}
	response, err := client.Do(request)
	if err != nil {
		panic(err)
	}
	defer response.Body.Close()

	var result map[string]any
	if err := json.NewDecoder(response.Body).Decode(&result); err != nil {
		panic(err)
	}
	fmt.Println(result)
}
```
```ruby title="Ruby"
require 'json'
require 'net/http'

uri = URI('https://api.qelka.com/v1/social/profile')
request = Net::HTTP::Post.new(uri)
request['Authorization'] = "Bearer #{ENV.fetch('QELKA_API_KEY')}"
request['Content-Type'] = 'application/json'
request.body = JSON.generate({ username: 'torvalds', platform: 'github' })

response = Net::HTTP.start(uri.host, uri.port, use_ssl: true, read_timeout: 30) do |http|
  http.request(request)
end
result = JSON.parse(response.body)
puts result
```

## Response

Read `status` first: `found` means `profile` is set.

| Field | Type | Description |
|---|---|---|
| `id` | string | Identifier of this lookup: `lkp_` followed by 26 characters. |
| `object` | string | Always `social_profile`. |
| `input` | string | The `username` you sent, without surrounding spaces. |
| `platform` | string | `github`, `bluesky` or `mastodon`. |
| `username` | string | The handle that was looked up. |
| `instance` | string or null | The Mastodon server that was asked, such as `mastodon.social`. `null` on other platforms. |
| `status` | string | `found`, `not_found` or `unavailable`. |
| `profile` | object or null | The public profile. `null` unless `status` is `found`. |
| `profile.id` | string | The platform's identifier of the account: a number on GitHub and Mastodon, a DID on Bluesky. |
| `profile.username` | string | The handle as the platform spells it; `user@server` on Mastodon. |
| `profile.display_name` | string or null | The display name. |
| `profile.url` | string | The public profile URL. |
| `profile.avatar_url` | string or null | The avatar image URL. |
| `profile.bio` | string or null | The bio or description, as plain text. |
| `profile.location` | string or null | The location written on GitHub. `null` on Bluesky and Mastodon, which have no such field. |
| `profile.company` | string or null | The company written on GitHub. |
| `profile.website` | string or null | The website set on GitHub. |
| `profile.followers` | integer or null | Number of followers. |
| `profile.following` | integer or null | Number of accounts followed. |
| `profile.posts` | integer or null | Posts on Bluesky, statuses on Mastodon. `null` on GitHub. |
| `profile.repositories` | integer or null | Public repositories on GitHub. `null` elsewhere. |
| `profile.created_at` | string or null | When the account was created, ISO 8601. |
| `profile.account_type` | string or null | `user`, `organization` (GitHub) or `bot` (a GitHub bot, a Mastodon bot account or a Bluesky labeler). |
| `profile.verified` | boolean or null | Bluesky: `true` when a trusted verifier has verified the account, or the account is itself a trusted verifier. `null` on GitHub and Mastodon. |
| `profile.links` | array of objects | The website and social accounts on the profile, without duplicates. |
| `profile.links.platform` | string | The platform of the link, such as `x`, `youtube`, `mastodon` or `website`. |
| `profile.links.label` | string or null | The label the person gave the link, when the platform has one. |
| `profile.links.url` | string | The link. |
| `profile.links.verified` | boolean or null | Mastodon: `true` when the server confirmed that the linked page links back to the profile. `null` elsewhere. |
| `credits_used` | integer | Credits debited for this call: 1 unless `status` is `unavailable` or the key is a test key. |
| `cached` | boolean | `true` when the answer came from the 24-hour cache. |

```json title="Response"
{
  "id": "lkp_01M8CEGAACSNCNH8HSS50Y4JZ4",
  "object": "social_profile",
  "input": "torvalds",
  "platform": "github",
  "username": "torvalds",
  "instance": null,
  "status": "found",
  "profile": {
    "id": "1024025",
    "username": "torvalds",
    "display_name": "Linus Torvalds",
    "url": "https://github.com/torvalds",
    "avatar_url": "https://avatars.githubusercontent.com/u/1024025?v=4",
    "bio": null,
    "location": "Portland, OR",
    "company": "Linux Foundation",
    "website": null,
    "followers": 333220,
    "following": 0,
    "posts": null,
    "repositories": 12,
    "created_at": "2011-09-03T15:26:22Z",
    "account_type": "user",
    "verified": null,
    "links": []
  },
  "credits_used": 1,
  "cached": false
}
```

## Act on the status

| `status` | What it means | What to do | Billed |
|---|---|---|---|
| `found` | The platform returned a public profile. | Use `profile`. Counts are what the platform reported at the time of the lookup. | Yes, and cached 24 hours |
| `not_found` | The platform says no account has this handle. | Check the spelling, or the Mastodon server. | Yes, and cached 24 hours |
| `unavailable` | The platform did not answer within 5 seconds, rate limited the request or answered an error. | Try again later. | No, and not cached |

## Where each profile comes from

| Platform | Source |
|---|---|
| GitHub | GitHub REST API: `GET /users/{username}`, then `GET /users/{username}/social_accounts` for the linked accounts |
| Bluesky | Public AppView API at `public.api.bsky.app`: `app.bsky.actor.getProfile` |
| Mastodon | The server's own API: `GET /api/v1/accounts/lookup?acct=` |

Only what the platform shows to anyone without an account is read. The API never signs in and reads no private field, follower list or post content.

## What the API keeps

The API returns only what the person made public on the platform. The request log keeps the username masked. A profile describes a person: use it for purposes they would expect, such as showing the profile they connected to your app.

## Examples

### Look up a Bluesky handle with a test key

Test keys return a simulated profile without calling the platform. With a test key in `QELKA_API_KEY`, this request returns:

```bash title="cURL"
curl https://api.qelka.com/v1/social/profile \
  --max-time 30 \
  -H "Authorization: Bearer $QELKA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"username": "example.com", "platform": "bluesky"}'
```
```javascript title="Node.js"
const response = await fetch('https://api.qelka.com/v1/social/profile', {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.QELKA_API_KEY}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({ username: 'example.com', platform: 'bluesky' }),
  signal: AbortSignal.timeout(30_000),
})
const result = await response.json()
console.log(result)
```
```python title="Python"
import os

import requests

api_key = os.environ["QELKA_API_KEY"]
response = requests.post(
    "https://api.qelka.com/v1/social/profile",
    headers={"Authorization": f"Bearer {api_key}"},
    json={"username": "example.com", "platform": "bluesky"},
    timeout=30,
)
result = response.json()
print(result)
```

```json title="Response"
{
  "id": "lkp_01M8CH2R3B8WQ5ZJ0NY7KDXG4E",
  "object": "social_profile",
  "input": "example.com",
  "platform": "bluesky",
  "username": "example.com",
  "instance": null,
  "status": "found",
  "profile": {
    "id": "did:plc:simulated0000000000000000",
    "username": "example.com",
    "display_name": "Simulated Profile",
    "url": "https://bsky.app/profile/example.com",
    "avatar_url": null,
    "bio": "A simulated profile returned to test keys.",
    "location": null,
    "company": null,
    "website": null,
    "followers": 1200,
    "following": 80,
    "posts": 340,
    "repositories": null,
    "created_at": "2020-01-15T10:00:00Z",
    "account_type": "user",
    "verified": false,
    "links": []
  },
  "credits_used": 0,
  "cached": false
}
```

## Errors

| Status | Type | When |
|---|---|---|
| 400 | [invalid_request](https://qelka.com/docs/errors#invalid_request) | `username` is missing, empty or longer than 2,048 characters, `platform` is not `github`, `bluesky` or `mastodon`, the body is not a JSON object, or it has a field the request table does not list |
| 401 | [invalid_api_key](https://qelka.com/docs/errors#invalid_api_key) | The key is missing, unknown or revoked |
| 402 | [insufficient_credits](https://qelka.com/docs/errors#insufficient_credits) | Your balance is less than 1 credit (live keys only) |
| 403 | [forbidden](https://qelka.com/docs/errors#forbidden) | The key is restricted to other endpoints |
| 405 | [invalid_request](https://qelka.com/docs/errors#invalid_request) | The method is not `POST` |
| 422 | [unprocessable_input](https://qelka.com/docs/errors#unprocessable_input) | `username` is not a valid handle or profile URL for its platform, a plain username was sent without `platform`, `platform` does not match the platform of the URL, or the Mastodon server is not a public host |
| 429 | [rate_limited](https://qelka.com/docs/errors#rate_limited) | Too many requests: wait `Retry-After` seconds |
| 500 | [internal_error](https://qelka.com/docs/errors#internal_error) | Unexpected error on our side: retry with backoff |

No error is billed. A platform that does not answer is not an error: it is a `200` with `status` `unavailable` and `credits_used: 0`.

## Related

- [Social profile API](https://qelka.com/products/social-profile-lookup)
- Free tools: [GitHub profile lookup](https://qelka.com/tools/github-profile-lookup), [Bluesky profile viewer](https://qelka.com/tools/bluesky-profile-viewer)
- [Username search](https://qelka.com/docs/api-reference/username): where else the same username is taken
- [Batch](https://qelka.com/docs/api-reference/batch): up to 100 profiles in one call, each item with `type: "social_profile"`
- [Bulk](https://qelka.com/docs/api-reference/bulk): a whole column of profile URLs with `type=social_profile`
- [Caching](https://qelka.com/docs/caching), [Errors](https://qelka.com/docs/errors), [Test mode](https://qelka.com/docs/test-mode)
