Hi,
this should do the job:
var psData = [
{
"id": "302732d8-e2ca-46e8-84c0-e751f4822412",
"name": "Check Network connection_2024-11-18 10:01:24",
"orgId": "61b3f352-844e-4abb-a4e4-806ab029e9a1",
"catalogItemId": "ae8c74fb-2b60-3fb4-b135-762164ba100a",
"blueprintId": "inline-blueprint",
"iconId": "9ac13daa-07f9-3a2d-8205-d0ba24598765",
"createdAt": "2024-11-18T10:01:36.079963Z",
"ownerType": "USER",
"lastUpdatedAt": "2024-11-18T10:02:36.711542Z",
"leaseGracePeriodDays": 1,
"inputs": {
"Porta": 1521,
"project": "4aacd5e9-9174-4088-8d5f-885e04c4478d",
"namespace": "anomalesospese",
"description": null,
"deploymentName": "Check Network connection_2024-11-18 10:01:24",
"_catalogItemName": "Check Network connection",
"bulkRequestCount": 1,
"textField_ed6d2c1a": "2024-11-18 10:01:24"
},
"projectId": "4aacd5e9-9174-4088-8d5f-885e04c4478d",
"resources": [
{
"id": "fddc8c0e-e0e3-443f-8946-fc28a3e3b274",
"name": "workflow",
"type": "vro.workflow",
"properties": {
"outputs": {
"output_network": {
"type": "Array/string",
"value": [
"Cluster ocp1 : Visibilità 1521KO\n ",
"Cluster ocp2 : Visibilità 1521KO\n "
]
},
"__metadata_orgId": {
"type": "string",
"value": "61b3f352-844e-4abb-a4e4-806ab029e9a1"
},
"__metadata_projectId": {
"type": "string",
"value": "4aacd5e9-9174-4088-8d5f-885e04c4478d"
},
"__metadata_requestId": {
"type": "string",
"value": "5c32c110-888b-4756-b21a-32d1d71b9cfe"
},
"__metadata_deploymentId": {
"type": "string",
"value": "302732d8-e2ca-46e8-84c0-e751f4822412"
}
},
"resourceName": "Check Network connection"
},
"createdAt": "2024-11-18T10:01:46.706680Z",
"origin": "DEPLOYED",
"state": "OK"
}
],
"status": "CREATE_SUCCESSFUL"
}
];
for each(psDataItem in psData) {
System.log("value: " + psDataItem.resources[0].properties.outputs.output_network.value);
}
------------------------------
If you find the answer helpful, please click on the RECOMMEND button.
Please visit my blog to get more information:
https://www.clouddepth.com------------------------------
Original Message:
Sent: Nov 18, 2024 05:48 AM
From: SistDip
Subject: Managing response from vroAPI with JSON.parse
Hi all mates,
I have a question for you, I need to extract the value of the output section of some deployments . I got the API from swagger and this is the output:
2024-11-18 11:17:49.468 +01:00INFO__item_stack:/item12024-11-18 11:17:49.498 +01:00INFO[ { "id": "302732d8-e2ca-46e8-84c0-e751f4822412", "name": "Check Network connection_2024-11-18 10:01:24", "orgId": "61b3f352-844e-4abb-a4e4-806ab029e9a1", "catalogItemId": "ae8c74fb-2b60-3fb4-b135-762164ba100a", "blueprintId": "inline-blueprint", "iconId": "9ac13daa-07f9-3a2d-8205-d0ba24598765", "createdAt": "2024-11-18T10:01:36.079963Z", "ownerType": "USER", "lastUpdatedAt": "2024-11-18T10:02:36.711542Z", "leaseGracePeriodDays": 1, "inputs": { "Porta": 1521, "project": "4aacd5e9-9174-4088-8d5f-885e04c4478d", "namespace": "anomalesospese", "description": null, "deploymentName": "Check Network connection_2024-11-18 10:01:24", "_catalogItemName": "Check Network connection", "bulkRequestCount": 1, "textField_ed6d2c1a": "2024-11-18 10:01:24" }, "projectId": "4aacd5e9-9174-4088-8d5f-885e04c4478d", "resources": [ { "id": "fddc8c0e-e0e3-443f-8946-fc28a3e3b274", "name": "workflow", "type": "vro.workflow", "properties": { "outputs": { "output_network": { "type": "Array/string", "value": [ "Cluster ocp1 : Visibilità 1521KO\n ", "Cluster ocp2 : Visibilità 1521KO\n " ] }, "__metadata_orgId": { "type": "string", "value": "61b3f352-844e-4abb-a4e4-806ab029e9a1" }, "__metadata_projectId": { "type": "string", "value": "4aacd5e9-9174-4088-8d5f-885e04c4478d" }, "__metadata_requestId": { "type": "string", "value": "5c32c110-888b-4756-b21a-32d1d71b9cfe" }, "__metadata_deploymentId": { "type": "string", "value": "302732d8-e2ca-46e8-84c0-e751f4822412" } }, "resourceName": "Check Network connection" }, "createdAt": "2024-11-18T10:01:46.706680Z", "origin": "DEPLOYED", "state": "OK" } ], "status": "CREATE_SUCCESSFUL" }]2024-11-18 11:17:49.504 +01:00INFO__item_stack:/item0
My code is :
//Create REST clientvar client = vraHost.createRestClient();//Create REST request object and populate values var request = client.createRequest("GET", "/deployment/api/deployments?search=Check%20Network&expand=resources", null);//Execute REST request and set output to the response variablevar response = client.execute(request);//Check for valid HTTP 2xx response code, otherwise throw error and return response dataif (!(response.statusCode >= 200 && response.statusCode <= 204)) throw "HTTP " + response.statusCode + " - " + response.statusMessage + " : " + response.contentAsString;result = JSON.parse(response.contentAsString);System.log(JSON.stringify(result.content, null, 2));
I need to access "output_networks" section and read value field. How can I access these fields?
I tryed with jsonContent.content.resources[0].properties.outputs.output_networks but it's always "undefined" .
In variable I see that there's more than one "content" :
Is this the problems?
Thanks