
# Get an account's X posts with Python, Node.js and cURL

Read an X account's latest posts, newest first, by username.

It is one call to [`GET /v1/x/users/{user}/posts`](/reference/x/getXUserPosts), which costs 1 credit a request, plus 2 per profile and 1 per post. Every snippet below ran against the live API on 27 October 2026, and the output is what the Python printed.

Set your key first. Create one at https://weirapp.io/dashboard/keys; every account gets 5,000 free credits a month.

```bash
export WEIR_API_KEY=weir_live_...
```

## Python

```python
import os

import requests

response = requests.get(
    "https://api.weirapp.io/v1/x/users/NASA/posts",
    headers={"Authorization": f"Bearer {os.environ['WEIR_API_KEY']}"},
    params={"limit": 5},
    timeout=60,
)
response.raise_for_status()
page = response.json()

for post in page["data"]:
    print(post["createdAt"], post["likeCount"], post["url"])
print("credits charged:", response.headers["X-Credits-Charged"])
```

## Node.js

```js
// Node.js 18 or later, as an ES module (save as example.mjs).
const response = await fetch("https://api.weirapp.io/v1/x/users/NASA/posts?limit=5", {
  headers: { Authorization: `Bearer ${process.env.WEIR_API_KEY}` },
});
if (!response.ok) throw new Error(`${response.status}: ${await response.text()}`);
const page = await response.json();

for (const post of page.data) console.log(post.createdAt, post.likeCount, post.url);
console.log("credits charged:", response.headers.get("x-credits-charged"));
```

## cURL

```bash
curl --request GET \
  --url 'https://api.weirapp.io/v1/x/users/NASA/posts?limit=5' \
  --header "Authorization: Bearer $WEIR_API_KEY"
```

## Output

```text
2026-10-23T23:37:56.000Z 7775 https://x.com/NASA/status/2113776971603689874
2026-10-26T19:29:09.000Z 4086 https://x.com/NASA/status/2114801524358406570
2026-10-25T22:30:00.000Z 7539 https://x.com/NASA/status/2114484649430798432
2026-10-25T21:04:02.000Z 0 https://x.com/NASA/status/2114463017043624059
2026-10-25T19:18:58.000Z 0 https://x.com/NASA/status/2114436576789082161
credits charged: 8
```

## The next page

A page ends with `meta.nextCursor`. Send it back as `cursor`, with every other parameter unchanged, until it is `null`. Each page is its own request and is charged as one.

```python
import os

import requests

headers = {"Authorization": f"Bearer {os.environ['WEIR_API_KEY']}"}
cursor = None
for number in range(1, 3):  # two pages; each page is its own charged request
    response = requests.get(
        "https://api.weirapp.io/v1/x/users/NASA/posts",
        headers=headers,
        params={"limit": 5, **({"cursor": cursor} if cursor else {})},
        timeout=60,
    )
    response.raise_for_status()
    page = response.json()
    print(f"page {number}: {len(page['data'])} posts, {response.headers['X-Credits-Charged']} credits")
    cursor = page["meta"]["nextCursor"]
    if not cursor:  # null means there is nothing more
        break
```

```text
page 1: 5 posts, 8 credits
page 2: 5 posts, 6 credits
```

## If a call fails

Failed calls are free. A `429` means too many requests a minute: wait the seconds in `Retry-After` and send it again. A `402` means the account is out of credits. A `503` means the source is busy and is safe to retry. Every code is on [Errors](/errors), and paging is on [Pagination](/pagination).
