Wiki source code of Get the Instance Id
Last modified by Vincent Massol on 2026/06/18 10:59
Show last authors
| author | version | line-number | content |
|---|---|---|---|
| 1 | To get the Instance id, follow these steps: | ||
| 2 | |||
| 3 | * From a [[REST endpoint>>Documentation.UserGuide.Features.XWikiRESTfulAPI]]: | ||
| 4 | *1. Call the ##/instanceId## endpoint. For example:((( | ||
| 5 | {{code language="shell"}} | ||
| 6 | curl -H 'Accept: text/plain' http://<domain>/xwiki/rest/instanceId | ||
| 7 | {{/code}} | ||
| 8 | ))) | ||
| 9 | *1. You'll get a unique id returned as plain text. For example:((( | ||
| 10 | {{code language="none"}} | ||
| 11 | c3421c30-68be-46b4-add5-c28e24099e99 | ||
| 12 | {{/code}} | ||
| 13 | ))) | ||
| 14 | * From Java: | ||
| 15 | *1. Get the ##InstanceIdManager##:((( | ||
| 16 | {{code language="java"}} | ||
| 17 | @Inject | ||
| 18 | private Provider<InstanceIdManager> idManagerProvider; | ||
| 19 | {{/code}} | ||
| 20 | |||
| 21 | Note the usage of a ##Provider##. This is required only when the component in which you're injecting the Instance Id Manager is loaded **before** the XWiki Store has been initialized. | ||
| 22 | ))) | ||
| 23 | *1. Get the id:((( | ||
| 24 | The API is: | ||
| 25 | |||
| 26 | {{code language="java"}} | ||
| 27 | public interface InstanceIdManager | ||
| 28 | { | ||
| 29 | /** | ||
| 30 | * @return the Instance id or null if it isn't set | ||
| 31 | */ | ||
| 32 | InstanceId getInstanceId(); | ||
| 33 | } | ||
| 34 | {{/code}} | ||
| 35 | ))) | ||
| 36 | * From a script in a wiki page. | ||
| 37 | *1. Get the id (example using Velocity):((( | ||
| 38 | {{code}} | ||
| 39 | {{velocity}} | ||
| 40 | $services.instance.getInstanceId() | ||
| 41 | {{/velocity}} | ||
| 42 | {{/code}} | ||
| 43 | ))) |