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”| Module | M5 — The API and an external client |
| After this session you can | Give an outside program exactly the access it needs, and read the suite’s data with it over HTTP the way every client should. |
| Time | Facilitated: 63 min · On your own: 63 min |
| Before you start | M4-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 deeper | Calling 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”Where a call goes
Section titled “Where a call goes”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 through a view
Section titled “Reading through a view”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.
The silent empty list
Section titled “The silent empty list”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.
Errors
Section titled “Errors”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.
Paging and searching
Section titled “Paging and searching”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
- 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.
- Entries list with a Table view, and Entries details. No create, edit or archive. Do not pin it.
- Leave Access Permission for step 8. Save.
The application user and its token
- 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.
- Open your sandbox mailbox: an email holds the new API token, a 64-character string. Copy it.
- Open Administration › Access Management › Admin Permissions, the Users tab, and give Careers Site the system level Restricted.
- Delete the email. The token now exists only in your terminal.
Open the door
-
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.
-
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,TOKENandFEEDare 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 see | What to do |
|---|---|
| No email arrives | The 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 Users | Give it the system level first (step 6). |
| User Type has no Application | Your 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.
-
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}' | jqIt answers
{"success": true, "result": []}: the silent empty list. The token’s user may not list Jobs, and the platform does not say so. -
Through the view. Ask the same through Careers feed. This is a
v3read, 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
enandar. -
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 . endRun step 2 again with
| jq -f unwrap.jq | jq '.entries | length': it prints 2, and it would print 2 on a release that still wrapsv3reads. -
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. -
Search. Add
--data-urlencode 'search=engineer'to step 2: only Senior Software Engineer remains. -
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.jsonNote the status, the code and the trace id: 404 and
API_REQUEST_ERROR, from the gateway, which could not find the view. -
A bad token. Repeat step 2 with
x-app-token: wrong: note the status and the code.
Check.
- The plain list answered
success: truewith an empty list. - The view-scoped read returned the two open jobs as a bare
entriespayload. - 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.codeandtraceIdof 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 see | What to do |
|---|---|
Step 2 answers 403 | The 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 title | Look at one entry whole (jq '.entries[0]') and use the normalized names it shows. |
Every call answers 400 with an app-token code | The token is wrong, expired or archived: check TOKEN has no spaces or quotes inside. |
curl cannot connect | BASE 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”An integration needs to read one view’s records and nothing else. How do you give it access?
Check your answer
The correct answer is C. Open the explanation under each option to see why.
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?
Check your answer
The correct answer is A. Open the explanation under each option to see why.
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?
Check your answer
The correct answer is B. Open the explanation under each option to see why.
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?
Check your answer
The correct answer is B. Open the explanation under each option to see why.
An application token stops working if the administrator who created it is deactivated.
Check your answer
The correct answer is B (False). Open the explanation under each option to see why.
↺ Recap (1 min) — A proven contract
Section titled “↺ Recap (1 min) — A proven contract”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.