Mobile App Integration

Integrate a mobile app with the Pelcro Open API — authenticate, store the JWT, and call protected endpoints.

The Pelcro Open API provides RESTful endpoints for mobile app integration. Use the authentication endpoints to obtain a customer JWT, then send that token in the Authorization header on protected requests.

Base URL: https://www.pelcro.com/api/v1/sdk
Full reference: Open API

# Log in, then call a protected endpoint
POST /api/v1/sdk/auth/login?site_id={site_id}
Content-Type: application/json

{ "email": "[email protected]", "password": "password" }

# The response includes data.auth_token — store it securely, then:
POST /api/v1/sdk/customer?site_id={site_id}
Authorization: Bearer {auth_token}

Prerequisites

RequirementDescription
Site IDYour Pelcro site identifier (from the dashboard), sent as ?site_id= on every request.
HTTPSAll API requests must use HTTPS.
JSONSend Content-Type: application/json with JSON bodies on POST/PUT.

Authentication flow

Mobile App → Register / Login → receive JWT (data.auth_token) → store securely → send as Authorization: Bearer on protected endpoints

Authentication endpoints

EndpointMethodAuth requiredDescription
/auth/registerPOSTNoRegister a new customer and receive an auth token.
/auth/loginPOSTNoLog in an existing customer and receive an auth token.
/auth/logoutPOSTYesInvalidate (blacklist) the current token.
/auth/idp/loginPOSTNoSocial / identity-provider login (google, facebook, auth0).
/auth/passwordless/requestPOSTNoRequest a passwordless login token by email.
/auth/passwordless/loginPOSTNoLog in using a passwordless token.

Site & configuration

EndpointMethodAuth requiredDescription
/siteGETNoGet the site configuration (the Site resource).
/planGET / POSTNoRetrieve a single plan by plan_id.
/plan/ip/authorizationGETNoFree plans whose authorized IP ranges include the requester's IP.
/plan/domain/authorizationGETNoFree plans whose authorized domains match the requester's email domain.
/geo/countryGETNoResolve the visitor's country by IP.
/locationGETNoResolve the visitor's location.

Authentication pattern

Register a new customer

POST /api/v1/sdk/auth/register?site_id={site_id}
Content-Type: application/json

{
  "email": "[email protected]",
  "password": "securePassword123",
  "first_name": "John",
  "last_name": "Doe"
}
FieldTypeRequiredDescription
emailstringYesThe customer's email address (unique per account).
passwordstringYesMinimum 6 characters (stricter if Strong Password Enforcement is enabled).
first_namestringNoFirst name.
last_namestringNoLast name.
display_namestringNoDisplay name (max 100 characters).
usernamestringNoUnique username (alphanumeric / dashes / underscores, max 100).
phonestringNoPhone number.
languagestringNoTwo-letter language code (e.g. en, fr).
metadataobjectNoArbitrary key-value pairs.

Success response (200): the shared Customer resource, including data.auth_token and data.token.

{
  "status": "success",
  "data": {
    "id": 1039,
    "email": "[email protected]",
    "first_name": "John",
    "last_name": "Doe",
    "auth_token": "eyJ0xxx",
    "token": "eyJ0xxx",
    "subscriptions": null,
    "addresses": null
  }
}

Log in an existing customer

POST /api/v1/sdk/auth/login?site_id={site_id}
Content-Type: application/json

{ "email": "[email protected]", "password": "securePassword123" }
FieldTypeRequiredDescription
emailstringYes*The customer's email (*required if username is not provided).
usernamestringYes*Username (*required if email is not provided).
passwordstringYesThe customer's password.

Note: provide either email or username. After repeated failed attempts the account is temporarily locked, returning 400 with a "Too many login attempts" validation message (default: 10 attempts / 5-minute window, configurable per account).

The success response is the same Customer resource shape as register, with the customer's subscriptions, addresses, etc. populated.

Store the token securely

After register/login, persist data.auth_token in the platform's secure storage:

  • iOS: Keychain Services
  • Android: Keystore / EncryptedSharedPreferences

Make authenticated requests

Send the token in the Authorization header on protected endpoints:

PUT /api/v1/sdk/customer?site_id={site_id}
Authorization: Bearer {auth_token}
Content-Type: application/json

{ "first_name": "Jane", "last_name": "Smith" }

Log out

POST /api/v1/sdk/auth/logout?site_id={site_id}
Authorization: Bearer {auth_token}

Logout blacklists the token server-side (it can no longer be used) and returns the customer resource. Clear the token from device storage afterwards.


Token management

PropertyValue
TypeJWT (JSON Web Token)
TTL60 days by default; configurable per site via auth_token_ttl_days (1–365).
StorageSecure device storage (Keychain / Keystore).
HeaderAuthorization: Bearer {token}

You can mint a fresh token without re-entering credentials via POST /customer/refresh (protected).


Response & error formats

Successful responses return JSON under a data key — either {"status":"success","data":{…}} or {"error":false,"data":…} depending on the endpoint. The shape of each object is documented in Resources.

Errors come back in one of two shapes (see Errors for the full reference):

  • Validation (400) — {"errors":{"field":["message"]}}
  • Application / auth{"error":{"report_id":null,"status":404,"message":"…"}} (report_id is present on server errors)

HTTP status codes

CodeMeaningAction
200SuccessProcess the response.
400Bad requestValidation failed ({"errors":{…}}) or a business rule rejected the request.
401UnauthorizedNo token was provided on a protected endpoint — prompt the user to log in.
403ForbiddenThe token is invalid, expired, or blacklisted — re-authenticate.
404Not foundMissing resource, or a domain rejection (e.g. invalid credentials).
429Too many requestsThrottled (e.g. passwordless/email requests) — back off and retry.
500Server errorRetry later or contact support with the report_id.

Error examples

Validation (400):

{ "errors": { "email": ["The email has already been taken."] } }

Invalid credentials (404):

{ "error": { "report_id": null, "status": 404, "message": "Invalid credentials! Please try again." } }

Account locked (400):

{ "errors": { "email": ["Too many login attempts. Please try again later."] } }

No token provided (401):

{ "error": { "message": "Token not provided" } }

Invalid / expired token (403):

{ "error": { "status": 403, "message": "Authentication token has expired, please try again" } }

Security best practices

  1. Store tokens in secure storage — iOS Keychain, Android Keystore / EncryptedSharedPreferences.
  2. Never store tokens in plain text — avoid UserDefaults, SharedPreferences, or plain files.
  3. Use HTTPS only and validate SSL certificates.
  4. Handle expiry — on 403, clear the token and re-authenticate (or refresh proactively).
  5. Clear tokens on logout — remove them from secure storage completely.
  6. Never log tokens.
  7. Consider certificate pinning for additional protection.

Complete reference

This guide covers the most common endpoints for mobile integration. For the full list — subscriptions, memberships, payment methods, addresses, e-commerce, and invoices — see the Open API reference.


Quick-start checklist

StepAction
1Get your site_id from the Pelcro dashboard.
2Implement register / login to obtain the JWT (data.auth_token).
3Store the token in secure device storage (Keychain / Keystore).
4Send Authorization: Bearer {token} on protected requests.
5On 403, re-authenticate (or refresh via POST /customer/refresh).
6Call POST /auth/logout to blacklist the token server-side.
7Test the auth flow and error handling.

Additional resources

For support, contact [email protected].