RestServices.put

Performs a REST HTTP PUT call supplying any headers and/or parameters required. Returns a RestResponse representing the response. A PUT is used to insert a new resource or update an existing one.

RestResponse contains the following data:

  • HTTP response code - returns a HTTP response code e.g 200 (OK)
  • HTTP response headers - returns list of response headers as key-->value pairs. e.g "WWW-Authenticate", "Bearer"
  • Response body - returns the response body if the response is successful. If there is no response, this value will be null.

Example:

 var user = {};
 user.userId = 1;
 user.title = 'foo';
 user.body = 'bar';
 
 var uri = "http://example.com/rest/users";
 //set any headers
 var headers = {"Content-Type":"application/json", "Accept":"application/json"};
 //set params
 var params = {"userId":fields.filter.value};
 //create authentication 
 var auth = HttpAuthentication.createBasicAuthentication("username", "password");
 var opts = new RestOptions();
 //setting the wait time to establish a connection to the target server to 5 seconds
 opts.setConnectionTimeout(5);
 //set the time to wait for no inactivity from the rest call to 10 seconds
 opts.setSocketTimeout(10);
 var response = services.rest.put(uri, JSON.stringify(user), headers, params, auth, opts);
 if(response.isSuccess())
 {
      var result = JSON.parse(response.getBody());
      if(result)
      {
           //populate response using the JSON object
           displayResult(result);
      }
 }
 
Further documentation.

returns RestResponse

Parameters

java.lang.String  uri,  java.lang.String  body,  java.util.Map  headers,  java.util.Map  parameters,  Authentication authentication,  RestOptions options,