This example will update the user account information for the account with ID = 53a3de9c-5cd3-4136-b6bf-63915fe71d30.
C# Java JavaScript
using System.Net;
using System.Net.Http;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;
using System.Web.Script.Serialization;
...
using (HttpClient httpClient = new HttpClient())
{
// Get Session Id
string logonUri = "http://localhost:8004/Api/LogOn/";
var logonOptions = new
{
accountName = "admin",
password = "1234",
cultureName = string.Empty,
deleteOtherSessions = true,
isWindowsLogOn = false
};
JavaScriptSerializer serializer = new JavaScriptSerializer();
var requestBodyAsString = serializer.Serialize(logonOptions);
StringContent content =
new StringContent(
requestBodyAsString,
Encoding.UTF8,
"application/json"
);
string jsonString = string.Empty;
using (var response = httpClient.PostAsync(logonUri, content).Result)
{
jsonString =
response.Content.ReadAsStringAsync().Result;
}
var obj = (Dictionary<string,object>) serializer.DeserializeObject(jsonString);
string sessionId = obj["sessionId"].ToString();
string url = "http://localhost:8004/API/Account/53a3de9c-5cd3-4136-b6bf-63915fe71d30/?sessionId=" + sessionId + "";
// Define the request body
HttpContent requestBody = null;
requestBody =
new StringContent(@"
{
""canChangePassword"": true,
""id"": ""53a3de9c-5cd3-4136-b6bf-63915fe71d30"",
""name"": ""user1"",
""displayName"": ""userx"",
""emailAddress"": ""user1@dundas.com"",
""accountType"": ""LocalUser"",
""isEnabled"": true,
""createdTime"": ""2015-03-10T16:58:10.573Z"",
""seatKind"": ""StandardUser"",
""grantedApplicationPrivilegeIds"": [
],
""deniedApplicationPrivilegeIds"": [
],
""customAttributes"": [
],
""__classType"": ""dundas.account.Account""
}
",Encoding.UTF8,"application/json");
using (var response = httpClient.PutAsync(url, requestBody).Result)
{
if(response.StatusCode == HttpStatusCode.OK)
{
Console.WriteLine("Success");
}
}
}
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;
import org.apache.http.entity.StringEntity;
import org.json.JSONObject;
...
HttpClient httpClient = HttpClientBuilder.create().build();
String url = "http://localhost:8004";
// Get Session Id
String logonUri = url + "Api/LogOn/"
HttpPost httpPost = new HttpPost(logonUri);
StringEntity stringEntity =
new StringEntity("{
+ "\"accountName\":\"admin\","
+ "\"password":\"1234\","
+ "\"cultureName\":\"\","
+ "\"deleteOtherSessions\":false,"
+ "\"isWindowsLogOn\":false"
+ "}"
);
stringEntity.setContentType("application/json");
httpPost.setEntity(stringEntity);
HttpResponse httpResponse = httpClient.execute(httpPost);
String jsonString = EntityUtils.toString(httpResponse.getEntity());
JSONObject jsonObj = new JSONObject(jsonString);
String sessionId = jsonObj.getString("sessionId")
String requestUrl = "http://localhost:8004/API/Account/53a3de9c-5cd3-4136-b6bf-63915fe71d30/?sessionId=" + sessionId + "";
// Define the Request Method.
HttpPut requstMethod = new HttpPut(requestUrl);
// Define the Request Body.
StringEntity input =
new StringEntity(
"{"
+ "\"canChangePassword\": true,"
+ "\"id\": \"53a3de9c-5cd3-4136-b6bf-63915fe71d30\","
+ "\"name\": \"user1\","
+ "\"displayName\": \"userx\","
+ "\"emailAddress\": \"user1@dundas.com\","
+ "\"accountType\": \"LocalUser\","
+ "\"isEnabled\": true,"
+ "\"createdTime\": \"2015-03-10T16:58:10.573Z\","
+ "\"seatKind\": \"StandardUser\","
+ "\"grantedApplicationPrivilegeIds\": ["
+ " "
+ "],"
+ "\"deniedApplicationPrivilegeIds\": ["
+ " "
+ "],"
+ "\"customAttributes\": ["
+ " "
+ "],"
+ "\"__classType\": \"dundas.account.Account\""
+ "}"
);
input.setContentType("application/json");
requstMethod.setEntity(input);
HttpResponse response =
httpClient.execute(requstMethod);
if(response.getStatusLine().getStatusCode() == 200)
{
System.out.println("Success");
}
var baseUrl = 'http://localhost:8005';
var logonOptions =
{
accountName: 'admin',
password: '1234',
cultureName: 'en-us',
deleteOtherSessions: false,
isWindowsLogOn: false
};
$.ajax({
type: 'POST',
url: baseUrl + '/Api/LogOn/',
data: logonOptions,
success: function(logOnResultData) {
var sessionId = logOnResultData.sessionId;
var dataObject =
{
"canChangePassword": true,
"id": "53a3de9c-5cd3-4136-b6bf-63915fe71d30",
"name": "user1",
"displayName": "userx",
"emailAddress": "user1@dundas.com",
"accountType": "LocalUser",
"isEnabled": true,
"createdTime": "2015-03-10T16:58:10.573Z",
"seatKind": "StandardUser",
"grantedApplicationPrivilegeIds": [
],
"deniedApplicationPrivilegeIds": [
],
"customAttributes": [
],
"__classType": "dundas.account.Account"
};
$.ajax({
type: "PUT",
url: baseUrl + "/API/Account/53a3de9c-5cd3-4136-b6bf-63915fe71d30/?sessionId=" + sessionId + "",
data: dataObject,
success: function(data) {
// data = A Dundas.BI.WebApi.Models
// AccountData object containing the
// account data.
},
error: function(data) { alert('failed' + data); }
});
}
});