VMware Cloud Community
opoet3
Enthusiast
Enthusiast
Jump to solution

Rest API request body section

Hi

I use this code to create a rest api request to my rest api server

var Pr = Host.createRequest("POST", "/track/all", null).execute();

but i want to set some body parameter to my request how i can do it?

1 Solution

Accepted Solutions
iiliev
VMware Employee
VMware Employee
Jump to solution

The 3rd parameter of createRequest() method is the request body (null in your example).

Not sure what body your /track/all REST API expects, but here is a sample code showing how to pass a string value when starting a workflow having one input parameter of type string:

var content = {

  "parameters": [

  {

    "type": "string",

    "scope": "local",

    "name": "param",

    "value": {

      "string": {

        "value": "some sample string value"

      }

    }

  }

  ]

}

var body = JSON.stringify(content);

var request = host.createRequest("POST", "/workflows/76312d50-3dda-4f09-a6d7-322c652b10a4/executions", body);  // vCO REST API to start a workflow given its ID

request.contentType = "application/json";

var response = req.execute();

System.log("response status -> " + response.statusCode);

View solution in original post

2 Replies
iiliev
VMware Employee
VMware Employee
Jump to solution

The 3rd parameter of createRequest() method is the request body (null in your example).

Not sure what body your /track/all REST API expects, but here is a sample code showing how to pass a string value when starting a workflow having one input parameter of type string:

var content = {

  "parameters": [

  {

    "type": "string",

    "scope": "local",

    "name": "param",

    "value": {

      "string": {

        "value": "some sample string value"

      }

    }

  }

  ]

}

var body = JSON.stringify(content);

var request = host.createRequest("POST", "/workflows/76312d50-3dda-4f09-a6d7-322c652b10a4/executions", body);  // vCO REST API to start a workflow given its ID

request.contentType = "application/json";

var response = req.execute();

System.log("response status -> " + response.statusCode);

opoet3
Enthusiast
Enthusiast
Jump to solution

Thank you.

Reply
0 Kudos