Your own REST endpoints¶
An application is not limited to what the browser can do. It can declare its own REST endpoints: HTTP paths under the application's URL that Polarion routes to JavaScript files inside the package. The code runs on the Polarion server, as the user who made the call, with access to the Polarion Java API through the scripting bridge. This is how an application delivers functionality that goes beyond the standard REST API.
POST https://<host>/polarion/apps/com.example.releasechecklist/rest/validate
X-Polarion-REST-Token: <context.restToken>
{"objectId": "test/TEST-514", "objectIds": "[\"test/TEST-514\",\"test/TEST-513\"]"}
→ {"timestamp": "…", "success": true,
"data": {"results": [...], "summary": {"items": 2, "withFindings": 1, ...}}}
What an endpoint gives you¶
| Capability | Why it matters |
|---|---|
| One request, any amount of work | Walk a link tree of 300 items, validate a whole selection, build a report: one round trip instead of hundreds of REST calls from the browser. |
| The full Polarion Java API | Everything the tracker, project, security and document services offer, including what the REST API does not expose. |
| Server-side integration | Call external systems from the server, with credentials kept in the user account vault, never in the browser. |
| Your own contract | Request and response shapes that fit your UI, instead of assembling JSON:API documents in the view. |
| The user's identity | Calls run as the user identified by the REST token. Permissions, workflow rules and audit trails apply as in the UI. |
How it fits together¶
- Declare the endpoint in
manifest.json: a path, a method (GETorPOST) and the script file. Declare endpoints → - Write the script in
server-scripts/. It reads parameters fromarguments, usescontext.scriptContext()to reach Polarion, and evaluates to the response object. Write the server script → - Call it from the view with
fetch()atcontext.appEndpoint + '/<path>', sendingcontext.restTokenin the requiredX-Polarion-REST-Tokenheader. Call endpoints from a view →
Polarion takes care of routing, authentication, parameter parsing, JSON serialization and the response envelope.
Every endpoint request requires a valid X-Polarion-REST-Token header, for both GET and POST. A logged-in browser session or session cookie does not authenticate an endpoint call. Opening an endpoint URL in the address bar does not send the required header; use fetch() or an HTTP client that can set it. See Test and debug.
- com.example.releasechecklist/
- manifest.json "serverScripts": { "endpoints": [ … ] }
- checklist/ the sidebar view
- server-scripts/
- validate.js POST …/rest/validate
- assign-to-me.js POST …/rest/assign-to-me
When to write an endpoint, when to use the REST API¶
Use the Polarion REST API directly from the view when it covers the job: reading and writing single objects, lists with queries, standard relationships. Write an endpoint when you need aggregation, rules, Java-only APIs, server-side secrets, or simply a cleaner contract for your UI. Most real applications do both. REST API or your own endpoints? →
In this section¶
- Declare endpoints: the manifest section, URL scheme, GET versus POST.
- Write the server script: the runtime, the
contextandargumentsobjects, Java interop, results and errors. - Call endpoints from a view: the fetch helper, parameters, envelope handling, TypeScript types.
- Patterns: aggregation, validation, write operations, external systems, caching.
- Test and debug: calling endpoints directly, reading errors, the server log.
- Reference: Endpoint runtime.
Worked examples: Traceability with endpoints (a GET that computes a tree, a POST that writes) and Release checklist (validation and bulk update of a selection).
