Update User Profile API
Call this function to update user’s profile.
Below is the URL to access the API functions:
PUT /CentagateWS/webresources/user/updatebyusername/{admin_username}
Parameters
No | Parameters | Occurrence | Descriptions |
---|---|---|---|
1 | username | Required | The user's username |
2 | firstName | Optional | The user's first name |
3 | lastName | Optional | The user's last name |
4 | address | Optional | The user's address |
5 | Zip | Optional | The user's zip |
6 | city | Optional | The user's city |
7 | State | Optional | The user's state |
8 | statusUser | Optional | The user's status |
9 | Optional | The user's email | |
10 | userCountryId | Optional | The User's country Id |
11 | userTimeZoneId | Optional | The user's Timezone Id |
12 | availApps | Optional | The user's avail apps |
13 | clientId | Optional | The user client Id |
14 | userType | Optional | The user type |
15 | userGroupName | Optional | The user group name |
16 | roles | Optional | The User's Roles Company Admin = 2, User = 3 and Group Admin = 4 |
17 | cenToken | Required | The Hmac Value Calculated Using SHA256 With SecretCode As Key And Plain Text From Admin Username + AuthToken |
Sample Code
As in below there are some examples of source code of access the API functions:
Java
public static void main(String[] args) {
ClientConfig config = new DefaultClientConfig ();
Client client = Client.create ( config );
WebResource service = client.resource ("https://<domain_name>/CentagateWS/webresources");
Gson gson = new Gson();
String authToken = "{authToken}";
String adminUsername = "{adminUsername}";
String secretCode "{secretCode}";
String cenToken = convertHmacSha256(secretCode, adminUsername + authToken);
HashMap<String, String> map = new HashMap<String, String>();
map.put("username", "username");
map.put("firstName", "firstName");
map.put("lastName", "lastName");
map.put("address", "address");
map.put("zip", "zip");
map.put("city", "city");
map.put("state", "state");
map.put("statusUser", "statusUser");
map.put("email", "email");
map.put("userCountryId", "userCountryId");
map.put("userTimeZoneId", "userTimeZoneId");
map.put("availApps", "availApps");
map.put("clientId", "clientId");
map.put("userType", "userType");
map.put("userGroupName", "userGroupName");
map.put("roles", "roles");
map.put("cenToken", cenToken);
ClientResponse response = service.path("user").path("updatebyusername").path(adminUsername).accept(MediaType.APPLICATION_JSON).put(ClientResponse.class, gson.toJson(map));
String retJson = response.getEntity(String.class);
HashMap<String, Object> returnData = (HashMap<String, Object>) gson.fromJson(retJson, HashMap.class);
String code = returnData.get("code").toString();
String message = returnData.get("message").toString();
String object = returnData.get("object").toString();
}
public static String convertHmacSha256(String secretKey, String params) throws NoSuchAlgorithmException,
InvalidKeyException,IllegalStateException, SignatureException, NoSuchProviderException, Exception
{
try
{
final SecretKeySpec secret_key = new SecretKeySpec ( StringUtils.getBytesUtf8 ( secretKey ) , "HmacSHA256" );
final Mac mac = Mac.getInstance ( "HmacSHA256" );
mac.init ( secret_key );
final byte[] bytes = mac.doFinal ( StringUtils.getBytesUtf8 ( params ) );
return Hex.encodeHexString ( bytes );
}
catch ( NoSuchAlgorithmException e )
{
throw new NoSuchAlgorithmException ( e );
}
catch ( InvalidKeyException e )
{
throw new InvalidKeyException ( e );
}
catch ( IllegalStateException e )
{
throw new IllegalStateException ( e );
}
catch ( Exception e )
{
throw new Exception ( e );
}
}
Node Js
const https = require('https')
var crypto = require('crypto');
var username = "<username>";
var firstName = "<firstName>";
var lastName = "<lastName>";
var address = "<address>";
var zip = "<zip>";
var city = "<city>";
var state = "<state>";
var statusUser = "<statusUser>";
var email = "<email>";
var userCountryId = "<userCountryId>";
var userTimeZoneId = "<userTimeZoneId>";
var availApps = "<availApps>";
var clientId = "<clientId>";
var userType = "<userType>";
var userGroupName = "<userGroupName>";
var roles = "<roles>";
var adminUsername = "<adminUsername>";
var authToken = "<authToken>";
var secretCode = "<secretCode>";
var cenTokenText = adminUsername + authToken;
var hash, cenToken;
/* generate cenToken value*/
cenToken = crypto.createHmac(sha256, secretCode);
cenToken.write(cenTokenText);
cenToken.end();
hash = cenToken.read().toString('hex');
const data = JSON.stringify({
username: username,
firstName: firstName,
lastName: lastName,
address: address,
zip: zip,
city: city,
state: state,
statusUser: statusUser,
email: email,
userCountryId: userCountryId,
userTimeZoneId: userTimeZoneId,
availApps: availApps,
clientId: clientId,
userType: userType,
userGroupName: userGroupName,
roles: roles,
cenToken: hash
})
const options = {
hostname: "<domain_name>",
port: 443,
path:'/CentagateWS/webresources/user/updatebyusername/'+adminUsername,
method: 'PUT',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
}
}
const req = https.request(options, res =>{
console.log(`HTTP Status Code: ${res.statusCode}`)
var body = '';
res.on('data', function(d){
body += d;
var parsed = JSON.parse(body);
if (parsed.code == 0){
console.log('Authentication Succeed');
console.log('Response:');
console.log(body);
}
else {
console.log('Authentication Fail, ' +'Message:' + parsed.message);
console.log('Code:' + parsed.code);
}
})
})
req.on('ERROR', error => {
console.error(error)
})
req.write(data)
req.end()
PHP
<?php
$adminUsername = "<adminUsername>";
$url = 'https://<domain_name>/CentagateWS/webresources/user/updatebyusername/'.$adminUsername;
$ch = curl_init($url);
$username = "<username>";
$firstName = "<firstName>";
$lastName = "<lastName>";
$address = "<address>";
$zip = "<zip>";
$city = "<city>";
$state = "<state>";
$statusUser = "<statusUser>";
$email = "<email>";
$userCountryId = "<userCountryId>";
$userTimeZoneId = "<userTimeZoneId>";
$availApps = "<availApps>";
$clientId = "<clientId>";
$userType = "<userType>";
$userGroupName = "<userGroupName>";
$roles = "<roles>";
$secretCode = "<secretCode>";
$authToken = "<authToken>";
$cenToken_text = $adminUsername.$authToken;
$cenToken = hash_hmac('sha256', $cenToken_text, $secretCode); // calculate cenToken value
$jsonData = array (
'username'=> $username,
'firstName'=> $firstName,
'lastName'=> $lastName,
'address'=> $address,
'zip'=> $zip,
'city'=> $city,
'state'=> $state,
'statusUser'=> $statusUser,
'email'=> $email,
'userCountryId'=> $userCountryId,
'userTimeZoneId'=> $userTimeZoneId,
'availApps'=> $availApps,
'clientId'=> $clientId,
'userType'=> $userType,
'userGroupName'=> $userGroupName,
'roles'=> $roles,
'cenToken'=> $cenToken
);
$jsonDataEncoded = json_encode($jsonData);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonDataEncoded);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
$obj = json_decode($result);
if ($obj->{'code'} != 0){
print "Authentication fail";
print "Message: ".$obj->{'message'};
echo " <br>";
print "Code: ".$obj->{'code'};
}
else {
print "Authentication succeed";
echo " <br>";
print "Message: ".$obj->{'message'};
echo " <br>";
print "Code: ".$obj->{'code'};
echo " <br>";
print "Result:" ;
echo " <br>";
print $result;
}
curl_close($ch);
?>
Error Code
Return Code | Details |
---|---|
0 | Success |
10001 | Permission not allowed |
10002 | Invalid Input |
10003 | DB protection error |
10004 | DB error |
10011 | Crypto error |
22002 | User not found |
22029 | User edit pending approval |
22031 | User edit fail |