Skip to main content

Sort lines API

Sort any list alphabetically: imports, todo lists, CSV headers, and more.

EndpointPOST https://astraltext.com/api/v1/sort-lines
AuthBearer token, free
Sendsinput: text
Returnsresult: text
optionasc | desc
PriceFree. 1,000 calls a day, 60 a minute.

When to call it

A sorted list is a reviewable list: an ordered set of allowed values, imports or translation keys makes a diff show what actually changed. Putting the sort in the pipeline means it happens before the file is committed, not after somebody notices.

For a one-off, the browser version needs no token and never sends your data anywhere: it runs on your own machine.

Example

curl
curl -X POST https://astraltext.com/api/v1/sort-lines \
  -H "Authorization: Bearer ast_YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"input": "éclair\nbanana\nApple\ncherry", "option": "asc"}'
response
{
  "tool": "sort-lines",
  "result": "Apple\nbanana\ncherry\néclair",
  "chars": 26,
  "ms": 8
}

In your language

JavaScript
const res = await fetch("https://astraltext.com/api/v1/sort-lines", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.ASTRAL_TOKEN}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({"input": "éclair\nbanana\nApple\ncherry", "option": "asc"}),
});
if (!res.ok) throw new Error((await res.json()).detail);
const { result } = await res.json();
Python
import os, requests

res = requests.post(
    "https://astraltext.com/api/v1/sort-lines",
    headers={"Authorization": f"Bearer {os.environ['ASTRAL_TOKEN']}"},
    json={"input": "éclair\nbanana\nApple\ncherry", "option": "asc"},
    timeout=30,
)
res.raise_for_status()
result = res.json()["result"]

Parameters

FieldTypeNotes
inputstringRequired. Up to 200,000 characters per call.
optionstringOne of: asc, desc.

Errors

Errors are RFC 7807 problem documents with a stable type you can branch on.

missing-token401No Authorization header.
bad-request400input missing or the wrong type.
bad-option400option is not one of the listed values.
tool-failed422The input could not be processed. detail says why.
quota-exceeded429Past 1,000 calls today.

Questions

How do I sort in reverse?
Send "option": "desc". The default is "asc".
How are accents and case treated?
The comparison is locale-aware and case-insensitive, so an accented word sorts next to its unaccented neighbour instead of after every ASCII letter.
Are blank lines kept?
Yes, they sort with everything else. Remove them first if you do not want them in the result.

Other endpoints

A token takes thirty seconds

Free, no card, 1,000 calls a day, and the same token works on astraltext.com, astralpdf.com, astraljson.com and astralbatch.com.

Get a free token