The chat responses are generated using Generative AI technology for intuitive search and may not be entirely accurate. They are not intended as professional advice. For full details, including our use rights, privacy practices and potential export control restrictions, please refer to our Generative AI Service Privacy Information. As this is a test version, please let us know if something irritating comes up. Like you get recommended a chocolate fudge ice cream instead of an energy managing application. If that occurs, please use the feedback button in our contact form!
Skip to content

Your own REST endpoints

2612

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, ...}}}

The Release checklist sidebar, whose findings are computed by an endpoint of the application

What an endpoint gives you

CapabilityWhy it matters
One request, any amount of workWalk 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 APIEverything the tracker, project, security and document services offer, including what the REST API does not expose.
Server-side integrationCall external systems from the server, with credentials kept in the user account vault, never in the browser.
Your own contractRequest and response shapes that fit your UI, instead of assembling JSON:API documents in the view.
The user's identityCalls run as the user identified by the REST token. Permissions, workflow rules and audit trails apply as in the UI.

How it fits together

  1. Declare the endpoint in manifest.json: a path, a method (GET or POST) and the script file. Declare endpoints →
  2. Write the script in server-scripts/. It reads parameters from arguments, uses context.scriptContext() to reach Polarion, and evaluates to the response object. Write the server script →
  3. Call it from the view with fetch() at context.appEndpoint + '/<path>', sending context.restToken in the required X-Polarion-REST-Token header. 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

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).