Organization API: Run Your Companies From Your App
An organization is a company on the Standard plan that pays for other companies. Everything it does in the app, its software can do through the Accounting API: check how many companies the plan covers, raise or lower that number, add a company, and work inside any of its companies.
To try this end to end in the sandbox first, run Run Multiple Companies with Separate Books.
These operations are part of the same Accounting API as journals and invoices, under the Organization tag. There is no separate API or contract.
Organization API or Partner API? The organization API runs your own group of companies on Standard. A platform that provisions companies for its customers, manages their users and opens sessions for them uses the Partner API, which is Enterprise only.
Before you start
- A Standard organization. Subscribe to Standard from the company that will pay. That company is the organization.
- An App Connect client in the organization company, with these permissions:
| Permission | Lets the client |
|---|---|
organization:company-list | List the organization's companies, read one company's usage, and read the totals against the plan |
company:add | Add a company to the organization |
company:subscription | Change or preview the company count |
organization:company-token | Get a token for one of the organization's companies |
Add the permissions your app needs inside each company too: step 5 reads journals, so it needs accounting:journal-list, and creating invoices would need invoice:add. A company token carries exactly these, never more, so grant only what your app uses. See authentication and tokens for creating the client and keeping its secret on your server.
1. Get an organization token
Working in your own language? These samples use plain HTTP. For a typed client in TypeScript, Python, Go, Java or PHP, generate one from the OpenAPI spec.
export BASE="https://api.paprel.com"
export PARTNER_DOMAIN="app.paprel.com"
export ORG_TOKEN="$(curl --fail --silent --show-error \
-X POST "$BASE/v1/app-connect/oauth/token" \
-H "content-type: application/json" \
--data "$(jq -n --arg id "$CLIENT_ID" --arg secret "$CLIENT_SECRET" \
'{grant_type:"client_credentials", client_id:$id, client_secret:$secret}')" \
| jq -r '.access_token')"
2. Check capacity
curl "$BASE/v1/organization/usage" \
-H "authorization: Bearer $ORG_TOKEN" \
-H "x-partner-domain: $PARTNER_DOMAIN"
companies.limit is how many companies the plan pays for, the organization included, and companies.used is how many it has, with a count per status in companies.by_status. A free slot is limit - used. It works like the Partner API's usage call and is light enough to call before every change.
To list the companies, call GET /v1/organization/companies. It is paged like the Partner API's company list: pass next_cursor back as cursor until it is null. The list carries no usage; read one company's users, clients and API operations for the billing period with GET /v1/organization/companies/{id}.
3. Raise the company count
Preview first, then change. The preview prices the change with Stripe and returns a proration_date. Send it back so the charge matches the preview.
export PRORATION_DATE="$(curl --fail --silent --show-error \
"$BASE/v1/subscription/company-quantity/preview?company_quantity=6" \
-H "authorization: Bearer $ORG_TOKEN" \
-H "x-partner-domain: $PARTNER_DOMAIN" \
| jq -r '.data.proration_date')"
curl -X PUT "$BASE/v1/subscription/company-quantity" \
-H "authorization: Bearer $ORG_TOKEN" \
-H "x-partner-domain: $PARTNER_DOMAIN" \
-H "content-type: application/json" \
--data "$(jq -n --argjson date "$PRORATION_DATE" '{company_quantity: 6, proration_date: $date}')"
Send the change soon after the preview: a proration_date more than an hour old is ignored and the change is priced at the time it arrives.
An increase is charged at once to the organization's saved card, for the rest of the billing period, and applies only if that payment goes through. One change adds at most 50 companies; raise the count in steps beyond that.
When the card needs the customer. If the bank asks for 3-D Secure or declines the payment, the company count stays the same and no charge is left pending. The call answers 402 COMPANY_QUANTITY_PAYMENT_ACTION_REQUIRED with a message and subscription_url, the Subscription page in the web app. The Subscription page shows the plan. Use a card that supports saved-card payments without additional confirmation, or contact support.
When the outcome is not known yet. If the billing provider's answer is lost or Core cannot record the result yet, the call answers 202 Accepted with pending_company_quantity, the count the change is moving to, and pending_change_id, its operation ID. Paprel checks the subscription and settles the change once the new count shows there. An unresolved change can require operator review. Until then the organization keeps the lower of the two counts for adding companies. Read GET /v1/organization/usage to see when it has settled.
One change at a time. While a change is open, another answers 409 COMPANY_QUANTITY_CHANGE_IN_PROGRESS.
4. Add a company
curl -X POST "$BASE/v1/company/organization-companies" \
-H "authorization: Bearer $ORG_TOKEN" \
-H "x-partner-domain: $PARTNER_DOMAIN" \
-H "content-type: application/json" \
--data '{
"company_name": "Acme Retail",
"currency_id": "SGD",
"locale": "en-SG",
"timezone": "Asia/Singapore",
"contact_first_name": "Mei",
"contact_last_name": "Tan",
"contact_email": "finance@acme-retail.example",
"contact_phone_number": "+6560000000",
"company_signature": "Acme Retail Pte. Ltd.",
"address_street1": "1 Example Street",
"address_city": "Singapore",
"address_state": "Singapore",
"address_zip_code": "000001",
"address_country": "SG"
}'
The request body is the same CompanyFormModel as any company; see the API reference for every field. The new company takes one free slot. With none free, the call answers 409 ORGANIZATION_CAPACITY_FULL: raise the count first.
5. Work in one of the companies
Exchange the same credentials with member_company_id for a token that acts in that company:
export COMPANY_TOKEN="$(curl --fail --silent --show-error \
-X POST "$BASE/v1/app-connect/oauth/token" \
-H "content-type: application/json" \
--data "$(jq -n --arg id "$CLIENT_ID" --arg secret "$CLIENT_SECRET" --arg company "$COMPANY_ID" \
'{grant_type:"client_credentials", client_id:$id, client_secret:$secret, member_company_id:$company}')" \
| jq -r '.access_token')"
curl "$BASE/v1/accounting/journals" \
-H "authorization: Bearer $COMPANY_TOKEN" \
-H "x-partner-domain: $PARTNER_DOMAIN"
The token works in that one company only, with the permissions your client was granted, except the ones that only make sense for the organization (organization:*, company:add, company:subscription), and every token issued this way is recorded in the activity log of both the organization and the company. A company outside your organization is refused with 403 ORGANIZATION_COMPANY_MISMATCH.
Lowering the count
Set a lower company_quantity the same way. It applies at once, and the unused time on the removed companies becomes account credit for the next invoices. Credit is not paid out. The count can't go below the companies in use (409 COMPANY_QUANTITY_BELOW_IN_USE), so delete a company first.
Errors you may see
| Status and code | Meaning |
|---|---|
402 COMPANY_QUANTITY_PAYMENT_ACTION_REQUIRED | The card requires confirmation or was declined. Use a card that supports saved-card payments without additional confirmation, or contact support |
202 with pending_company_quantity | Paprel is reconciling the change with Stripe. Operator review may be needed |
409 COMPANY_QUANTITY_CHANGE_IN_PROGRESS | Another company-count change is still open |
403 ORGANIZATION_REQUIRED | The token's company is not an organization |
403 ORGANIZATION_COMPANY_MISMATCH | member_company_id is not one of the organization's companies |
403 ORGANIZATION_COMPANY_TOKEN_NOT_ALLOWED | The client lacks organization:company-token |
403 ORGANIZATION_COMPANY_TOKEN_NO_PERMISSIONS | The client has no permissions to carry into the company; grant the ones your app needs there |
404 ORGANIZATION_COMPANY_NOT_FOUND | The company read asked for a company outside the organization |
409 ORGANIZATION_CAPACITY_FULL | No free slot to add a company |
409 COMPANY_QUANTITY_BELOW_IN_USE | The new count is below the companies in use |
409 COMPANY_QUANTITY_INCREASE_TOO_LARGE | One change may add at most max_increase companies (50); raise the count in steps |
409 COMPANY_QUANTITY_SET_AT_CHECKOUT | The organization is on its trial; the count is chosen when it subscribes |
409 SUBSCRIPTION_CANCEL_PENDING | The plan is set to end; keep the plan first |
409 ORGANIZATION_PLAN_INACTIVE, ORGANIZATION_PLAN_REQUIRED | No live Standard plan |
429 ORGANIZATION_DAILY_COMPANY_LIMIT | The organization has added its daily limit of companies; try again later |
429 with no body | The client sent too many requests; company-count changes and previews allow 6 a minute, retry after a minute |
Done in the app only
Suspending, resuming and deleting a company stay in the web app. Suspend and delete ask a signed-in user to confirm with an email or authenticator code, which an API client can't give.
For prices, see pricing. For how organizations, companies and partners fit together, see the glossary.