Scripts
Service Id: platform6.scripts
1. Get JSON List of Script Service Item Ids (appKey and name)¶
Header key | Description | Value |
---|---|---|
platform6.request.action |
The action to perform (required) | list.ids |
A valid response will be:
Header key | Description |
---|---|
platform6.response.status |
OK |
platform6.response.value |
JSON List<> List of identifiers |
Example¶
def cm = [ headers: [ 'platform6.request.action': 'list.ids' ] ]
print p6.service.request('platform6.scripts', cm).headers['platform6.response.value']
The response will be:
[
{
"appKey": "",
"name": "AuthTokenCall"
},
{
"appKey": "",
"name": "AWFCall"
},
{
"appKey": "ondiflo",
"name": "_CallCall"
},
{
"appKey": "",
"name": "FormProcessor"
}
]
2. Create a new script if it does not already exist¶
Header key | Description | Value |
---|---|---|
platform6.request.action |
The action to perform (required) | add |
id |
The identifier of the script (required) | |
description |
The description of the script (required) | |
main.content |
The main file of the script | |
platform6.request.user |
The email address of the user sending the message |
The new script will be verified before upsert.
The last author of the modification will be the user who sent the common message.
The content mode will automatically be set to NONE
.
Warning
The identifier and the description must validate the service’s item rules.
A valid response will be:
Header key | Description |
---|---|
platform6.response.status |
true |
Example¶
In this example, the script will add in the pipeline a variable with the key response
and the value Hello world
.
For more information about the method pipeline.put
, read the following page Pipeline.
import groovy.json.JsonOutput
def cm = [
headers: [
'platform6.request.action': 'add',
'id': 'my_new_script',
'description': JsonOutput.toJson([EN: 'A new script', FR: 'Un nouveau script']),
'main.content': 'pipeline.put("response", "Hello world")'
]
]
print p6.service.request('platform6.scripts', cm).headers['platform6.response.status']
The response will be true
if the script is validated and created.
If a script with the same id already exists, it will return false
.
If a field of the input is incorrect, it will throw an exception.
{
"message" : "Unexpected exception adding a new script 'my_new_script': the parameter 'description' is missing.",
"stackTrace" : [
"io.platform6.common.util.P6Exception: Unexpected exception adding a new script 'my_new_script': the parameter 'description' is missing.",
" at io.platform6.core.service.scripts.ScriptsService.notifyRequestMessage(ScriptsService.java:173)",
" at io.platform6.core.impl.servicecomponent.AbstractServiceComponent.onCommonMessage(AbstractServiceComponent.java:688)",
" at io.platform6.core.impl.platform.messagebus.BusQueueController$ServiceQueueRunner.run(BusQueueController.java:183)",
" at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)",
" at java.util.concurrent.FutureTask.run(FutureTask.java:266)",
" at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)",
" at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)",
" at java.lang.Thread.run(Thread.java:748)"
]
}
2. Execute a Script¶
Header key | Description | Value |
---|---|---|
platform6.request.action |
The action to perform (required) | execute |
id |
The identifier of the script (required) | |
platform6.request.user |
The email address of the user sending the message | |
nowait |
Do not wait for execution completion (default: false) | true or false |
The author of the script’s execution will be the user who sent the common message.
Headers of the response
The response common message can contain headers or attachments added by the script.
Example¶
The script’s content of this example is in the example above.
def cm = [
headers: [
'platform6.request.action': 'execute',
'id': 'my_new_script'
]
]
print p6.service.request('platform6.scripts', cm).headers.response
The output will be:
Hello world
3. Test If A Script Service Item Exists Given its Id¶
Header key | Description | Value |
---|---|---|
platform6.request.action |
The action to perform (required) | exists |
id |
Service Item AppKey (required) |
A valid response will be:
Header key | Description |
---|---|
platform6.response.status |
true |
4. Test If A Script Service Item Contains a TEST Resource Given its Id¶
Header key | Description | Value |
---|---|---|
platform6.request.action |
The action to perform (required) | exist.tests |
id |
Service Item AppKey (required) |
A valid response will be:
Header key | Description |
---|---|
platform6.response.status |
true |
5. List the Names of Resources within a Script Service Given its Id¶
Header key | Description | Value |
---|---|---|
platform6.request.action |
The action to perform (required) | list.resources.name |
id |
Service Item AppKey (required) |
A valid response will be:
Header key | Description |
---|---|
platform6.response.status |
true |
platform6.response.value |
List |