/api/v1 prefix on your NodeLoc site, for example https://www.nodeloc.com/api/v1/me. For requests with a body, send Content-Type: application/json and a single JSON object. Use the API path without a language prefix.
Choose a session credential
Both credentials represent the same type of NodeLoc session. Send one credential per request. If you send both, a nonempty session cookie takes precedence, even if it has expired. A session expires 60 days after creation. Activity leaves that expiry unchanged. Send browser writes from the same origin. The server checks browser origin information, and native HTTPS requests need no separate CSRF token.
The general
/api/v1 API uses account sessions. The app development CLI uses its Api-Key with app platform endpoints. To offer “Sign in with NodeLoc” on another website, use the OAuth 2.0 / OpenID Connect flow and use its access token with the OAuth endpoints.
Sign in with a password
Send the username or email address and password toPOST /api/v1/auth/login. This example shows an initial request with placeholders.
A successful login returns HTTP
200 with a user object and sets the session cookie. A native request without Sec-Fetch-Mode also receives a session token in JSON. Browser clients can rely on the cookie. Here is a native success response.
Handle two-factor authentication and CAPTCHA
- If the login returns HTTP
401witherror.codeset tosecond_factor_required, prompt for an authenticator or backup code. Repeat the login request with the originalloginandpasswordplus the newcode. An incorrect or previously used code returnssecond_factor_invalid. - To remember the device at the user’s request, send
"trust_device": truewith the code. The browser receives a trusted-device cookie. A native client also receivestrust_tokenin JSON. For later logins to the same account, a native client can send this token inX-Nodeloc-Trustand omit the code while the trust remains valid. The token lasts 30 days, and the password is still required. - Read
GET /api/v1/auth/captchafor site settings. When enabled, useprovider,site_key,actions.login,login_mode, andlogin_after_failures. If the server returnscaptcha_requiredorcaptcha_invalid, complete the configured challenge and send the new token ascaptcha.
GET /api/v1/auth/providers. In NodeLoc’s system-browser sign-in flow, send the returned one-time code to POST /api/v1/auth/app/exchange. Include the matching code_verifier if the flow started with a PKCE challenge. A successful exchange returns 200 with user and token. The code expires after two minutes. An expired code or failed verification returns 400 invalid_code. Start sign-in again to get a new code.
Read or update a profile
CallGET /api/v1/me with a session credential. This native-client example uses the site URL in BASE_URL and the current session token in NODELOC_SESSION_TOKEN.
GET /api/v1/me/account returns an account object with phone, has_password, password_changed_at, created_at, pending_email, and cover_url. For public profiles, GET /api/v1/users/{username} returns user and stats. If the user hides their level and reputation, responses to other viewers omit trust_level, tier_name, and stats.votes_received. An unknown user returns 404 not_found.
Use PUT /api/v1/me to edit a profile. Read the current profile first and send each value you want to keep. An omitted field or empty string clears the corresponding value. The request field is bio, and the raw text in the read response is bio_raw.
http:// or https://. A successful update returns 200 with a basic user object. Call GET /api/v1/me to retrieve the full updated profile. A field validation error returns 422 invalid with the reason keyed by request field in error.fields.
Verify identity and manage sessions
When an operation returns403 reauth_required, send {"password":"<password>"} or {"code":"<one-time-code>"} to POST /api/v1/me/reauth with the current session. A successful request returns 200 and verified_until. Retry the original operation in the same session within 10 minutes. To manage two-factor authentication, GET /api/v1/me/two-factor returns enabled and backup_codes_left. Send a POST to the same path to get the authenticator secret and uri, then submit {"code":"<authenticator-code>"} in a PUT to enable it. The response contains 10 backup_codes. Show the secret and backup codes only to the current user and keep them out of logs.
Each session entry has an
id, user_agent, ip, last_seen_at, created_at, and current. Use the numeric id to revoke a specific session. A native client should remove its stored session token after signing out.
Handle errors
Use the HTTP status anderror.code to choose the next action. Display message to the user because its wording can vary with locale and account state.
