Códigos de ejemplo

Importante: La conexión se debe establecer bajo el protocolo TLS 1.2 como mínimo, de lo contrario el servidor denegará la petición.

Login

Ejemplo de consumo al servicio "/authentication/login" para realizar la autenticación de un usuario.

Javascript
var xmlHttpRequest = new XMLHttpRequest();
xmlHttpRequest.onreadystatechange = function()
{
	if (xmlHttpRequest.readyState == XMLHttpRequest.DONE)
	{
		if (xmlHttpRequest.status == 200)
		{
			/* Expected data structure:
				{
					"access_token": "string",
					"token_type": "string",
					"expires_in": "string"
				}
			*/
			var response = JSON.parse( xmlHttpRequest.response );
			var token = response.access_token;
		}
		else
		{
			// handle the error..
		}
	}
};
xmlHttpRequest.open('POST', 'https://webapi.rhpro.com/Admin/authentication/login', true);
xmlHttpRequest.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
xmlHttpRequest.send('username=YOUR_USER&password=YOUR_PASS&grant_type=password'); /* replace YOUR_USER & YOUR_PASS by the real values */
jQuery
$.ajax
({
	url: 'https://webapi.rhpro.com/Admin/authentication/login',
	type: 'POST',
	dataType: 'text',
	data: 'username=YOUR_USER&password=YOUR_PASS&grant_type=password', /* replace YOUR_USER & YOUR_PASS by the real values */
	beforeSend: function (xhr, settings)
	{
		xhr.setRequestHeader( 'Content-Type', 'application/x-www-form-urlencoded' );
	}
})
.done(function (data, textStatus, jqXHR)
{
	/* Expected data structure:
		{
			"access_token": "string",
			"token_type": "string",
			"expires_in": "string"
		}
	*/
	var response = JSON.parse( xmlHttpRequest.response );
	var token = response.access_token;
})
.fail(function (jqXHR, textStatus, errorThrown)
{
	// handle the error..
})
PHP
$username = "YOUR_USER"; // replace by real value
$password = "YOUR_PASS"; // replace by real value

$data_array = array(
	"username"	=> $username,
	"password"  	=> $password,
	"grant_type"	=> "password"
);

$curl = curl_init();

curl_setopt($curl, CURLOPT_URL, "https://webapi.rhpro.com/Admin/authentication/login");
curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type: application/x-www-form-urlencoded"));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data_array);

$response = curl_exec($curl);

curl_close($curl);

/* Expected data structure:
	{
		"access_token": "string",
		"token_type": "string",
		"expires_in": "string"
	}
*/
$decoded_response = json_decode($response);
$token = $decoded_response.access_token;
C#
public class AuthToken
{
	public string Access_Token { get; set; }
	public string Token_Type { get; set; }
	public int Expires_In { get; set; }
}
using (var webClient = new WebClient() { Encoding = Encoding.UTF8 })
{
	webClient.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
	string data = $"username={YOUR_USER}&password={YOUR_PASS}&grant_type=password";
	string responseData = webClient.UploadString("https://webapi.rhpro.com/Admin/authentication/login", data);
	AuthToken authToken = JsonConvert.DeserializeObject[AuthToken](responseData);
	string token = authToken.Access_Token;
}

Obtener listado Tenants asociadas a un usuario

Ejemplo de consumo al servicio "/accounts/tenants" para obtener la lista de bases de datos/tenants a los cuales el usuario provisto (mediante el Token) tiene acceso.

Javascript
var xmlHttpRequest = new XMLHttpRequest();
xmlHttpRequest.onreadystatechange = function()
{
	if (xmlHttpRequest.readyState == XMLHttpRequest.DONE)
	{
		if (xmlHttpRequest.status == 200)
		{
			/* Expected data structure:
				[{
					"Id": "string",
					"ClientName": "string",
					"TenantName": "string",
					"WebApiEnabled": true,
					"EmployeeSecurityStrategy": "string",
					"Version": "string"
				}]
			*/
		}
		else
		{
			// handle the error..
		}
	}
};
xmlHttpRequest.open('GET', 'https://webapi.rhpro.com/Admin/account/tenants', true);
xmlHttpRequest.setRequestHeader( 'Authorization', 'Bearer ACCESS_TOKEN' ); /* replace ACCESS_TOKEN by the real value */
xmlHttpRequest.setRequestHeader( 'X-Api-Version', '1.0-preview.1' );
xmlHttpRequest.send();
jQuery
$.ajax
({
	url: 'https://webapi.rhpro.com/Admin/account/tenants',
	type: 'GET',
	dataType: 'json',
	beforeSend: function (xhr, settings)
	{
		xhr.setRequestHeader( 'Authorization', 'Bearer ACCESS_TOKEN' ); /* replace ACCESS_TOKEN by the real value */
		xhr.setRequestHeader( 'X-Api-Version', '1.0-preview.1' );
	}
})
.done(function (data, textStatus, jqXHR)
{
	/* Expected data structure:
		[{
			"Id": "string",
			"ClientName": "string",
			"TenantName": "string",
			"WebApiEnabled": true,
			"EmployeeSecurityStrategy": "string",
			"Version": "string"
		}]
	*/
})
.fail(function (jqXHR, textStatus, errorThrown)
{
	// handle the error..
})
PHP
$curl = curl_init();

$token = "YOUR_TOKEN"; // replace by real value

curl_setopt($curl, CURLOPT_URL, "https://webapi.rhpro.com/Admin/account/tenants");
curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type: application/json", "Authorization: Bearer ".$token, "X-Api-Version: 1.0-preview.1" ));
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($curl);

curl_close($curl);

/* Expected data structure:
	[{
		"Id": "string",
		"ClientName": "string",
		"TenantName": "string",
		"WebApiEnabled": true,
		"EmployeeSecurityStrategy": "string",
		"Version": "string"
	}]
*/
$decoded_response = json_decode($response);
C#
using (var webClient = new WebClient() { Encoding = Encoding.UTF8 })
{
	webClient.Headers.Add( "Authorization", "Bearer ACCESS_TOKEN" ); /* replace ACCESS_TOKEN by the real value */
	webClient.Headers.Add( "X-Api-Version", "1.0-preview.1" );
	try
	{
		employeeData = webClient.DownloadString("https://webapi.rhpro.com/Admin/account/tenants");
	}
	catch (WebException ex)
	{
		HttpWebResponse httpResponse = ex.Response as HttpWebResponse;
		// Handle the error (switch on httpResponse.StatusCode)
	}
}


Obtener listado de Empleados

Ejemplo de consumo al servicio "/employees" para obtener el listado (paginado) de Empleados de una base de datos provista.

Javascript
var xmlHttpRequest = new XMLHttpRequest();
xmlHttpRequest.onreadystatechange = function()
{
	if (xmlHttpRequest.readyState == XMLHttpRequest.DONE)
	{
		if (xmlHttpRequest.status == 200)
		{
			// handle de returned data..
		}
		else
		{
			// handle the error..
		}
	}
};
xmlHttpRequest.open('GET', 'https://webapi.rhpro.com/WebApi/employees', true);
xmlHttpRequest.setRequestHeader( 'Authorization', 'Bearer ACCESS_TOKEN' ); /* replace ACCESS_TOKEN by the real value */
xmlHttpRequest.setRequestHeader( 'X-Api-Version', '1.0-preview.1' );
xmlHttpRequest.setRequestHeader( 'X-RAET-Tenant-Id', TENANT_ID ); /* replace TENANT_ID by the real value */
xmlHttpRequest.send();
jQuery
$.ajax
({
	url: 'https://webapi.rhpro.com/WebApi/employees',
	type: 'GET',
	dataType: 'json',
	beforeSend: function (xhr, settings)
	{
		xhr.setRequestHeader( 'Authorization', 'Bearer ACCESS_TOKEN' ); /* replace ACCESS_TOKEN by the real value */
		xhr.setRequestHeader( 'X-Api-Version', '1.0-preview.1' );
		xhr.setRequestHeader( 'X-RAET-Tenant-Id', TENANT_ID ); /* replace TENANT_ID by the real value */
	}
})
.done(function (data, textStatus, jqXHR)
{
	// handle de returned data..
})
.fail(function (jqXHR, textStatus, errorThrown)
{
	// handle the error..
})
PHP
$curl = curl_init();

$token = "YOUR_TOKEN"; 		// replace by real value
$tenantId = "TENANT_ID"; 	// replace by real value

curl_setopt($curl, CURLOPT_URL, "https://webapi.rhpro.com/WebApi/employees");
curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type: application/json", "Authorization: Bearer ".$token, "X-Api-Version: 1.0-preview.1", "X-RAET-Tenant-Id: ".$tenantId));
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($curl);

curl_close($curl);

$decoded_response = json_decode($response);
C#
using (var webClient = new WebClient() { Encoding = Encoding.UTF8 })
{
	webClient.Headers.Add( "Authorization", "Bearer ACCESS_TOKEN" ); /* replace ACCESS_TOKEN by the real value */
	webClient.Headers.Add( "X-Api-Version", "1.0-preview.1" );
	webClient.Headers.Add( "X-RAET-Tenant-Id", TENANT_ID ); /* replace TENANT_ID by the real value */
	try
	{
		employeeData = webClient.DownloadString("https://webapi.rhpro.com/WebApi/employees");
	}
	catch (WebException ex)
	{
		HttpWebResponse httpResponse = ex.Response as HttpWebResponse;
		// Handle the error (switch on httpResponse.StatusCode)
	}
}
Ir arriba ↑