Declare endpoints¶
Endpoints are declared in manifest.json under serverScripts.endpoints. Each entry maps an HTTP method and a path segment to a script file in the server-scripts/ folder of the package.
{
"identifier": "com.example.releasechecklist",
"…": "…",
"serverScripts": {
"endpoints": [
{ "urlPath": "validate", "method": "POST", "script": "validate.js" },
{ "urlPath": "assign-to-me", "method": "POST", "script": "assign-to-me.js" },
{ "urlPath": "stats", "method": "GET", "script": "stats.js" }
]
}
}
| Field | Meaning |
|---|---|
urlPath | Last path segment of the endpoint URL. Letters, digits and hyphens; lower-case by convention. Unique per method. |
method | GET or POST. |
script | File name inside server-scripts/. Keep one script per endpoint. |
The URL¶
Every endpoint lives under the application's endpoint base, which the framework hands to views as context.appEndpoint:
https://<host>/polarion/apps/<identifier>/rest/<urlPath>
For com.example.releasechecklist the three endpoints above are:
POST https://<host>/polarion/apps/com.example.releasechecklist/rest/validate
POST https://<host>/polarion/apps/com.example.releasechecklist/rest/assign-to-me
GET https://<host>/polarion/apps/com.example.releasechecklist/rest/stats?objectId=test
The identifier namespaces your endpoints; two applications can both declare validate without conflict.
GET or POST¶
| GET | POST | |
|---|---|---|
| Parameters | query string (?objectId=test/TEST-514&depth=2) | Flat JSON object in the body ({"objectId": "test/TEST-514", "text": "…"}), Content-Type: application/json |
| Reading them in the script | arguments.getAsString('objectId') | arguments.getAsString('text'); every value must be a string. Send lists and objects JSON-encoded in a string and JSON.parse them in the script. |
| Use for | reads, computations, reports | writes, anything with side effects, requests with structured or long input |
| Cacheable by the browser | yes (add a cache-busting parameter if that is unwanted) | no |
Rules of thumb:
- Reads with a handful of scalar parameters: GET.
- Anything that saves, and anything whose input is long or structured: POST. Encode lists and objects as JSON strings; a body with a nested array or object is rejected with HTTP 500 (Expected a string but was BEGIN_ARRAY).
- Never change data in a GET endpoint. Whether the server rejects a save in a GET script depends on configuration; design as if it did.
The objectId parameter¶
Every endpoint call must carry a parameter named objectId, in the query string for GET and in the body for POST. Polarion rejects a call without it before the script runs, with HTTP 400 and Argument objectId is missing in workflow definition. Use the id of the object the call is about in the form PROJECT/WI-ID (for example drivepilot/DP-477); a project id alone is also accepted. Your script reads it like any other parameter.
GET …/rest/linked-tree?objectId=drivepilot/DP-477&depth=2
POST …/rest/validate {"objectId": "drivepilot/DP-461", "objectIds": "[\"drivepilot/DP-461\",\"drivepilot/DP-527\"]"}
Authentication¶
Every GET and POST call must send a valid REST token in the X-Polarion-REST-Token header. From a view, use context.restToken:
X-Polarion-REST-Token: <context.restToken>
A browser session or session cookie cannot replace this header. Requests without a valid token are rejected before the script runs, even when the caller is logged in to Polarion. The script executes as the user identified by the token; see Security model.
Package layout¶
- <identifier>/
- manifest.json
- <rootDirectory>/ one folder per view
- server-scripts/
- validate.js
- assign-to-me.js
- stats.js
Upload validation checks that every script exists. Scripts are read from the uploaded package; changing them means re-uploading the application, which takes effect immediately.
Versioning your contract¶
Views and endpoints ship together in one package, so they are always in sync; there is no need for URL versioning between them. If other clients (automation, another application) call your endpoints, treat the request and response shapes as a public contract: add fields rather than renaming them, and document them in the application's README as the examples do.