KBEC-00410 How to determine JSON for REST API for 'Swagger'

Summary

When using the REST API, you may be required to use the request's 'Body' Field to input Parameters into the request. Some of the documentation with the Swagger UI, does not list out the Format of the 'Body'.  To determine the Format, please follow this example:

To determine the JSON Request body for a Put request for 'ResourcePool', you will need to know the XML request from the ectool modifyResourcePool command. 

  1. Run the ectool command with the 'debug' and 'format flags on and set to JSON respectively :

    ectool --server localhost --debug 1 --format json modifyResourcePool <pool> --resourceNames "local" "local2"

    Verify that this send back a response and the resources have been added to the pool
    The JSON format would look like:

    {

      "requests": {

        "-version": "2.2",

        "-timeout": "180",

        "-sessionId": "[PROTECTED]",
    ...
    ...
        "request": {

     

          "-requestId": "1",

          "modifyResourcePool": {

            "resourceName": [

              "local1",

              "hpux-1"

            ],

            "resourcePoolName": "pool1"

          }
       }
      }
    }

  2. You can then remove the whitespace by using another online tool like Remove All WhiteSpace.
    {"resourceName":["local1","hpux-1"],"resourcePoolName":"pool1"}

  3. You can then use this code portion into the request's Body. After entering the request body, you can select the 'Try it out' and it will return a curl command with the request body inserted. The curl command for this example would be:

curl -k -X PUT --header "Content-Type: application/json" --header "Accept: application/json" -d "{\"resourceName\":[\"local1\",\"hpux-1\"],\"resourcePoolName\":\"pool1\"}" "https://admin:changeme@localhost/rest/v1.0/resourcePools/pool1"

 

If you are unable to determine the request body or the fields for the REST API are not responding as intended, please forward the steps you took and any details to support@electric-cloud.com for analysis.

Have more questions? Submit a request

Comments

Powered by Zendesk