Skip to content

M5-S1 — The HTTP API: a credential, a view, and your first calls

Section titled “M5-S1 — The HTTP API: a credential, a view, and your first calls”
ModuleM5 — The API and an external client
After this session you canGive an outside program exactly the access it needs, and read the suite’s data with it over HTTP the way every client should.
TimeFacilitated: 63 min · On your own: 63 min
Before you startM4-S2. Your terminal with curl and jq. Your practice space’s API address and the link to its sandbox mailbox, from your enrolment message. Signed in as yourself.
Go deeperCalling the HTTP API · Backend quickstart · Reading data

◆ Orientation (1 min) — The careers site needs a key and a door

Section titled “◆ Orientation (1 min) — The careers site needs a key and a door”

The web agency will build Meridian’s careers site (R-10). Before they write a line, you decide what their program may reach, issue its credential, and make the calls yourself, so that the contract you hand over is one you have proved. The portal you have used all course is itself just a client of this API; now you meet the API directly.

▤ Concept (4 min) — How every call works

Section titled “▤ Concept (4 min) — How every call works”

Every call goes to the tenant’s own host, with a path starting /api. The gateway on that host checks your credential, works out the tenant from the host name, and passes the call on. You never call a service directly and never send a tenant id: the host is the tenant.

sequenceDiagram
  participant C as Your client
  participant G as Gateway (tenant host)
  participant P as Platform
  C->>G: GET /api/v1/v/{viewId}/v3/entities/jobs/entries<br/>x-app-token: …
  G->>G: check the credential,<br/>tenant from the host,<br/>view access
  G->>P: the call, as the token's user
  P-->>C: 200 and the payload (or an error envelope)

What to notice: identity and tenant are decided at the gateway from the credential and the host; nothing you put in other headers can change them.

The version is part of the path and belongs to each operation: one resource often has v1, v2 and v3 side by side. Use the highest version an operation offers. Records are named by their entity’s normalized name (jobs) or id; a record’s fields sit under value, keyed by normalized name.

The credential: an API token, and who it really is

Section titled “The credential: an API token, and who it really is”

An API token is the simplest credential: send it as x-app-token on every call. It belongs to an application user, a user record that stands for a program and cannot sign in to the portal. A tenant administrator adds that user, and the platform emails the token once to that administrator; nobody can display it again, and if it is lost, an administrator selects Regenerate Token. A token carries no scopes of its own: every call runs as its application user, with exactly that user’s access. Least privilege is therefore set on the user, one application user per integration.

Reading an entity’s records directly needs Edit on that entity, which would also let the program change the design’s records in Administration. The narrow door is a view: a call to /api/v1/v/{viewId}/… is checked against the view’s own Access Permission, and reaches only the records and fields the view exposes. Give the application user access to one view built for it, and nothing else.

A plain (not view-scoped) list or count on an entity the caller may not list does not answer 403: it answers a successful, empty list and a zero count. A view-scoped call answers 403 when the view forbids it. So an empty first read means “check the access” before it means “there is no data”. Reading one known record directly gives an explicit refusal and settles it.

The response envelope, and the v3 exception

Section titled “The response envelope, and the v3 exception”

Successful answers are wrapped: { "success": true, "result": … }. One exception: a GET on a v3 path returns the bare payload, for example { "entries": [ … ] }. Errors are always wrapped, v3 included. Older releases still wrap v3 reads, so a client that may talk to more than one release unwraps by shape: take result only when the body says "success": true.

Every error has one shape: { "success": false, "error": { "code", "message": { "en", "ar" }, "traceId" } }. Branch on error.code, never on the message text. Use the HTTP status for the coarse decision: 400 the request is wrong, 401 the credential is missing or bad, 403 the user lacks access, 404 not found, 409 a conflict. A 500 is not always temporary: many fixed refusals answer 500 with a catalogued code. Log traceId: support finds the call by it.

v2 and v3 lists take a filterCriteria object (limit, skip, order, and a criteria tree) and a free-text search. There are no cursors and no server maximum: always send a limit you chose, page with skip, and order on a stable key with the record id last ("order": ["value.registration_deadline ASC", "id ASC"]), so rows do not slip between pages.

⛏ Lab (26 min) — The careers credential and its door

Section titled “⛏ Lab (26 min) — The careers credential and its door”

Goal. An application user Careers Site, with the base system level and access to one view, Careers feed, that shows only open jobs; its token in your terminal. In production these steps belong to your tenant administrator and you would ask for them; in your sandbox you do them.

Before you start. Signed in as yourself.

The view the site may read

  1. Open Recruitment System › Jobs › Views › New View. Name Careers feed. Source view Entries, filtered by the starter’s query Open jobs. Fields: Job title, Description, Department, Location, Registration deadline.
  2. Entries list with a Table view, and Entries details. No create, edit or archive. Do not pin it.
  3. Leave Access Permission for step 8. Save.

The application user and its token

  1. Open Administration › Organization › Users and select Add User. Name it Careers Site, set User type to Application, and in Application information give the application’s name Careers Site and an Expiry date at the end of your course. Save.
  2. Open your sandbox mailbox: an email holds the new API token, a 64-character string. Copy it.
  3. Open Administration › Access Management › Admin Permissions, the Users tab, and give Careers Site the system level Restricted.
  4. Delete the email. The token now exists only in your terminal.

Open the door

  1. Edit Careers feed: Access Permission Authenticated, Select Users Careers Site. Save and Publish. Open it once as yourself and copy its id from the address bar.

  2. In your terminal, set three variables (the address from your enrolment message):

    Terminal window
    export BASE="https://<your practice space API address>"
    export TOKEN="<the token>"
    export FEED="<the Careers feed view id>"

Screenshot pending The Add User form with User Type Application and the Application information section with its name and expiry date What to notice: there is no token on screen and no scope to choose; the token is emailed once, and everything it may do comes from what you grant this user next.

Check.

  • Careers feed shows only Open jobs, five fields, read-only, for Careers Site only.
  • Careers Site is an application user with an expiry date and the system level Restricted, and no other grant.
  • The token is in your terminal and the email is gone.
  • BASE, TOKEN and FEED are set.
  • Nothing grants Careers Site access to an entity or a module.

Pass condition. The careers credential exists, can reach exactly one view, and has no other access.

If something goes wrong

What you seeWhat to do
No email arrivesThe token is emailed to the administrator who added the user: check the sandbox mailbox of your address. If it is lost, select Regenerate Token on the user; the new one comes to you.
Careers Site is not offered in Select UsersGive it the system level first (step 6).
User Type has no ApplicationYour organization may have renamed the option; the type that makes an application user is what matters. Ask your administrator.
Model answer

The integration’s access is three facts: an application user that cannot sign in and expires with the course; the base system level, without which it would be refused almost everywhere; and one view, Careers feed, open to that user alone and showing open jobs only. There is no entity or module grant, so the site cannot list Jobs directly or reach any other data. The token was shown once, by email, and now lives only where the program will read it.

⛏ Lab (24 min) — First calls: the empty list, the view, paging and an error

Section titled “⛏ Lab (24 min) — First calls: the empty list, the view, paging and an error”

Goal. Prove what the token can and cannot read, read the open jobs through the view, page and search them, and capture an error’s code and trace id.

Before you start. The three variables from the first lab.

  1. The plain list. Ask for Jobs directly:

    Terminal window
    curl -s -G "$BASE/api/v2/entities/jobs/entries" \
    -H "x-app-token: $TOKEN" --data-urlencode 'filterCriteria={"limit":5}' | jq

    It answers {"success": true, "result": []}: the silent empty list. The token’s user may not list Jobs, and the platform does not say so.

  2. Through the view. Ask the same through Careers feed. This is a v3 read, so the answer is the bare payload:

    Terminal window
    curl -s -G "$BASE/api/v1/v/$FEED/v3/entities/jobs/entries" \
    -H "x-app-token: $TOKEN" \
    --data-urlencode 'filterCriteria={"limit":5,"skip":0,"order":["value.registration_deadline ASC","id ASC"]}' \
    | jq '.entries[] | {title: .value.job_title.en, deadline: .value.registration_deadline}'

    Two open jobs. Job title is localized text, so it holds en and ar.

  3. Unwrap by shape. Save this filter as a file unwrap.jq, and use it from now on:

    if type == "object" and .success == true then .result else . end

    Run step 2 again with | jq -f unwrap.jq | jq '.entries | length': it prints 2, and it would print 2 on a release that still wraps v3 reads.

  4. Page. Ask for one job at a time: "limit":1,"skip":0, then "skip":1, then "skip":2. The third page is empty: a page shorter than the limit is the last.

  5. Search. Add --data-urlencode 'search=engineer' to step 2: only Senior Software Engineer remains.

  6. An error. Ask for a view that does not exist and keep the status:

    Terminal window
    curl -s -o err.json -w '%{http_code}\n' -G "$BASE/api/v1/v/no-such-view/v3/entities/jobs/entries" \
    -H "x-app-token: $TOKEN"
    jq '{code: .error.code, msg: .error.message, trace: .error.traceId}' err.json

    Note the status, the code and the trace id: 404 and API_REQUEST_ERROR, from the gateway, which could not find the view.

  7. A bad token. Repeat step 2 with x-app-token: wrong: note the status and the code.

Check.

  • The plain list answered success: true with an empty list.
  • The view-scoped read returned the two open jobs as a bare entries payload.
  • Your unwrap filter gives the same result whether the body is wrapped or not.
  • Paging with a limit of 1 gave one job, a second, then an empty page.
  • You recorded the status, error.code and traceId of the two failures.

Pass condition. You can show, with your own output, that the token reads open jobs only through Careers feed, and you have the code and trace id of two different failures.

If something goes wrong

What you seeWhat to do
Step 2 answers 403The view is not published, or Careers Site is not in its Select Users.
Step 2 answers {"success": true, "result": …}Your platform still wraps v3 reads; your unwrap filter handles it.
jq prints null for the titleLook at one entry whole (jq '.entries[0]') and use the normalized names it shows.
Every call answers 400 with an app-token codeThe token is wrong, expired or archived: check TOKEN has no spaces or quotes inside.
curl cannot connectBASE must be the API address from your enrolment message, with https:// and no trailing /api.
Model answer

The empty list in step 1 is the lesson of the session: the call succeeded, and the platform did not reveal whether data exists, because the user may not list it. The view-scoped call is the supported door, and as a v3 read it returned {"entries": [...]} without success. Paging with limit and skip on a stable order is the only way through a long list, since the server neither caps nor remembers pages. A wrong token answers a 400 whose code names an invalid app token; an unknown view answers an error envelope whose traceId is what you would quote to support.

◇ Worked scenario (1 min) — “The API returns nothing”

Section titled “◇ Worked scenario (1 min) — “The API returns nothing””

The agency writes: “Our integration is live in staging but the jobs list is always empty. Your API is broken.” Diagnose it with them before reading on.

What they call. GET /api/v2/entities/jobs/entries with their staging token. Answer: the plain list, which returns an empty success when the caller may not list.

The decisive test. Read one known job directly by id. If it is refused, the problem is access, not data. It is refused.

The cause. Their staging application user was created without access to Careers feed, and they were not told to read through the view. Both halves of the contract were missing.

The fix and the lesson. Grant the view to the staging user, send them the view id and the path pattern, and add one line to the integration card: “read open jobs only through the view Careers feed; an empty plain list means missing access”. A contract that names the door prevents the ticket.

✓ Practice (6 min) — Check your understanding

Section titled “✓ Practice (6 min) — Check your understanding”
PracticeChoose one answer.

An integration needs to read one view’s records and nothing else. How do you give it access?

  1. Explanation for A

    ✗ Incorrect

    Not this one: Edit on the entity also opens every record and the design in Administration. See reading through a view.

  2. Explanation for B

    ✗ Incorrect

    Not this one: a token has no scopes; everything comes from its application user. See the credential.

  3. Explanation for C

    ✓ Correct

    Correct: the view-scoped path is checked against the view’s own access, and nothing else is granted. See reading through a view.

Check your answer

The correct answer is C. Open the explanation under each option to see why.

PracticeChoose one answer.

A client written for one release parses body.result.entries from a GET on a v3 path. On a newer release it crashes. Why, and what is the durable fix?

  1. Explanation for A

    ✓ Correct

    Correct: unwrapping by shape works on both releases. See the response envelope.

  2. Explanation for B

    ✗ Incorrect

    Not this one: v3 exists; only its successful reads stopped being wrapped. See the response envelope.

  3. Explanation for C

    ✗ Incorrect

    Not this one: an expired token gives an error envelope, not a different success shape. See errors.

Check your answer

The correct answer is A. Open the explanation under each option to see why.

PracticeChoose one answer.

A list call with "limit": 50 and "order": ["value.department ASC"] sometimes shows the same employee on two pages while a colleague is adding records. What fixes it?

  1. Explanation for A

    ✗ Incorrect

    Not this one: fewer pages lower the odds but do not remove the cause, and there is no server maximum to protect you. See paging and searching.

  2. Explanation for B

    ✓ Correct

    Correct: offset paging needs a stable, unique order, or rows slip between pages. See paging and searching.

  3. Explanation for C

    ✗ Incorrect

    Not this one: the platform has no cursors; paging is by limit and skip. See paging and searching.

Check your answer

The correct answer is B. Open the explanation under each option to see why.

PracticeChoose one answer.

A call answers 500 with error.code set to a documented domain code. Your retry loop tries again five times. What should it have done?

  1. Explanation for A

    ✗ Incorrect

    Not this one: many fixed refusals answer 500 with a catalogued code, and retrying repeats them. See errors.

  2. Explanation for B

    ✓ Correct

    Correct: a catalogued code is a deterministic answer, not a temporary failure. See errors.

  3. Explanation for C

    ✗ Incorrect

    Not this one: that is the answer to a 401, not to a domain refusal. See errors.

Check your answer

The correct answer is B. Open the explanation under each option to see why.

PracticeDecide whether the statement is true or false.

An application token stops working if the administrator who created it is deactivated.

  1. Explanation for A

    ✗ Incorrect

    Not this one: the token belongs to its application user, not to the administrator who added it. See the credential.

  2. Explanation for B

    ✓ Correct

    Correct: the token acts as its application user; deactivating or archiving that user is what stops it. See the credential.

Check your answer

The correct answer is B (False). Open the explanation under each option to see why.

You issued a credential to a dedicated user, opened exactly one door, and proved with your own calls what it reaches, how answers are wrapped, how to page, and what failures look like.

Next. In M5-S2 you meet the other credential: OAuth, for programs that act for a person or a visitor, and the lifecycle of every token.