Skip to content

API

Sync a list from your own system

For the program your IT team writes. It keeps a list, like your jobs, the same as your ERP, on the schedule you set.

Your ERP or accounting system already knows your jobs: each one's number, name, whether it's open, its foreman, superintendent and PM, its customer. List sync keeps a PortalBase list the same, so forms fill in from the job a crew picks.

It works for any list your company keeps in Setup, under Lists: jobs, customers, stores, rooms, lines. It's the same as editing the list there, with a mapping you save once.

1. Before you start

  • An admin makes the list in Setup, under Lists, with the fields you'll send: Foreman as a person, Division as one of a list, Customer as text.
  • A super admin makes a service account in Setup, under Connections, with a role that has reference.manage for the whole company. Super admin or Admin at the top of your company has it. Then a key for it that can make changes.
  • People go first. A person field is matched by employee ID, so your foremen and supervisors need to be in PortalBase with the same IDs before the first sync.
  • Map your columns, status words and choice words once in Setup, under Lists, on the list's Sync tab. The API uses that mapping.
  • Your company's keys call https://app.portalbaseai.com/api/v1. portalbaseai.com is our site and demo, and refuses them.

2. Send rows as JSON

POST to https://app.portalbaseai.com/api/v1/lists/jobs/sync, where jobs is the list's key, with your key as Authorization: Bearer pbk_... One row per item. A row finds its item by key, then by code.

curl https://app.portalbaseai.com/api/v1/lists/jobs/sync \
  -H "Authorization: Bearer $PORTALBASE_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: 3f8b1c2e-6a4d-4e7f-9b2a-1c5d8e0f7a36" \
  -d '{
    "preview": true,
    "rows": [
      {
        "code": "24-1031",
        "label": "Lakeview Clinic addition",
        "status": "open",
        "fields": { "foreman": "E1042", "division": "mechanical", "customer": "Northfield Health" }
      }
    ]
  }'

In JSON, null clears a value. A field you leave out keeps what it has.

3. Or send the list as CSV

Send the export itself with Content-Type: text/csv and the choices in the query string. An empty cell keeps what's there.

To start from a file that works, download the list from its Sync tab in Setup. It's what's there now, in columns the sync reads: people by employee ID, choices in words, links by key or code as you mapped them.

curl "https://app.portalbaseai.com/api/v1/lists/jobs/sync?preview=true" \
  -H "Authorization: Bearer $PORTALBASE_KEY" \
  -H "Content-Type: text/csv" \
  --data-binary @jobs.csv

4. Check first

With preview set, nothing changes. The answer says what would be added, changed, left as it is, taken out of use or refused, row by row, and any status or choice word the mapping doesn't know yet. Send it again without preview to apply.

A row whose item is in the file is in use, unless its status says otherwise. Open, active and in use mean in use; closed, inactive and complete mean not. Map other words, like Soft closed, on the Sync tab.

5. People on a list

A person field takes an employee ID, or an email if the mapping says so. If nobody has it, or two people do, the field is left blank and the row says so, without the ID. A sync never adds or invites anyone.

6. Items from another list

A link field, like a job's Customer, takes the key of an item on the list it points at. If your file has the customer number instead, set that field to find by code on the Sync tab, or send links_by with the mapping, like { "customer": "code" }. Case doesn't matter.

The item has to be on that list already, in use or not. If it isn't, or two items share the code, the row is refused and the reason names the key or code, so you can fix it there. Sync the linked list first, customers before jobs.

A form that picks a job can read the job's customer, one step through the link: fill in the customer's billing contact, or ask a question only when the customer's kind is Healthcare. In the form builder, the customer's fields show as Customer: Billing contact. In a form definition sent to the API, that's fields.customer.billing_contact, or words.customer.billing_contact for its words. Publishing makes the link field and the field it reads available offline, so phones and laptops fill it in with no signal. A customer out of use isn't read. It opens with the phone update that reads through links.

7. Taking out what's gone

Add turn_off_missing to take items the file doesn't list out of use, with max_turn_off, the most it may take out. If more would go, nothing is changed. Items out of use stay for old records and reports, keep their values, and come back if a later file lists them.

curl "https://app.portalbaseai.com/api/v1/lists/jobs/sync?turn_off_missing=true&max_turn_off=25" \
  -H "Authorization: Bearer $PORTALBASE_KEY" \
  -H "Content-Type: text/csv" \
  --data-binary @open-jobs.csv

8. Or drop a file each night

If your system can export a file on a schedule but can't run a program, an admin sets the list to A file each night in Setup, under Lists, on its Sync tab. Then your system sends the file with PUT, any time before 2 AM where your company is, and PortalBase applies it then through the same sync and mapping.

curl -X PUT "https://app.portalbaseai.com/api/v1/lists/jobs/sync/files?turn_off_missing=true" \
  -H "Authorization: Bearer $PORTALBASE_KEY" \
  -H "Content-Type: text/csv" \
  --data-binary @open-jobs.csv
  • The file is checked when it arrives, the way a preview is. One that can't be read is refused then.
  • A newer file replaces one still waiting. Send it again whenever it changes.
  • turn_off_missing is the only choice. Leave it out and nothing is taken out of use.
  • A night that would take more than 10 items out of use, or more than a quarter of the list, is held. Nothing changes, and the admins are told. One of them checks it in Setup and applies it or drops it.
  • The answer is 202 with the file's id and when it runs. The run it makes shows on the list's Sync tab.

9. What a sync locks

While a list is set to anything but Kept here, what its last sync filled is changed in your system, not in PortalBase: the words, the code and each field the file had, on the items it listed. Someone who tries to change one in Setup is told to change it in your system, and the next sync brings it over. In use stays open, and so do items someone adds by hand.

10. Retries

Send an Idempotency-Key, a UUID of your own, with each file. Sending the same key again returns the first run and changes nothing more. Each request is one transaction: all of it is saved, or none.

11. The answer

The run's id, the list version it published when the items changed, its counts and one line per row. A line names the item by key and which columns and fields changed, never a value.

{
  "ok": true,
  "result": {
    "run_id": "0193c2d0-...",
    "version": 12,
    "counts": { "added": 3, "changed": 12, "unchanged": 395, "turned_off": 2, "turned_on": 0, "refused": 1 },
    "rows": [
      { "row": 7, "item_key": "24-1063", "action": "added", "fields": [], "reason": "No one has the employee ID in Foreman. It's left blank." }
    ]
  }
}

GET /api/v1/lists/jobs/sync/runs/{id} reads a run again.

12. Reading a list

GET /api/v1/lists lists your lists and their fields. GET /api/v1/lists/jobs/items gives a list's items with their values, a page at a time: in_use=true, false or all, changed_since, limit up to 1,000, and next_cursor back as cursor. Person, equipment and place values come with their names.

A field that holds an item from another list says which in links_to, like customers. Its value is that item's key, and the item's words come under names.

changed_since gives the items whose words, code, order, in use or values changed since then. A new version of the list leaves the other items alone, so a nightly reader gets only what changed.

13. Each item where it is

Give a list a place field, like a job's Site, and a sync can fill it by place code. Then the list can show each item only where it is: a form filled at a place offers the items at that place, above it or under it, and every item with no place. It narrows what crews pick from. Records, reports and this API still see every item, and an answer is never refused for where its item is.

A program turns it on with save_list_settings and items_by_place. It needs the place field, and makes that field available offline so phones can narrow with no signal. Phones and laptops offer the same items the web does, with Show all for the rest. It opens with the phone update that has the narrowed picker.

14. In reports

Turn on In reports for a list field in Setup, under Lists, and report numbers about form records slice and filter by it: inspections by foreman, answers by region. The value is the picked item's at the last report refresh, so a job that changes foreman counts under the new one.

POST /api/v1/queries/list_report_metrics lists those fields with record_type lists and a field:<id> key, next to your company fields. Use that key to slice or filter in POST /api/v1/queries/run_report.

A link reaches one step: turn on In reports for a field on the list it points at, and reports slice by it through the link, named like Jobs: Customer: Region. A link field itself slices by the linked item, named by its words.

15. Limits

  • Up to 20,000 rows, open and closed, so a whole list goes in one file. 1 MB a request or nightly file.
  • A list holds up to 5,000 items in use, and keeps up to 50,000, closed ones included. A list has up to 30 fields, 5 of them links.
  • A closed item leaves the list 90 days after it went out of use, so crews can't pick it, and is kept for records only: records, reports and GET items still have it, with its values. An item that's already closed the first time a file or a save sends it is kept for records only right away. The answer's kept_for_records says how many. Reopen one on the Lists page, or list it in the next file.
  • Your key's usual rate limit applies.
  • An AI tool can't sync a list.