S rozhraním CAQapi lze komunikovat pomocí různých programovacích jazyků.
Úplný seznam endpointů hledejte zde
Následující ukázka čte data z objektu https://example.com/CAQapi/LAB/Inspections/, který vrací informace z modulu laboratoř.
private HttpClient client;
private string serverUri = "http://example.com";
private string baseUri = "/CAQapi";
public void CreateClient()
{
client = new HttpClient() { BaseAddress = new Uri(serverUri) };
var base64String = Convert.ToBase64String(Encoding.ASCII.GetBytes($"{AppSettings.Login}:{AppSettings.Password}"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", base64String);
}
public async Task GetData(string path, string parameters)
{
string uri = baseUri + path;
if (!String.IsNullOrEmpty(parameters)) uri += "?" + parameters;
var request = new HttpRequestMessage(HttpMethod.Get, uri);
var resp = await client.SendAsync(request);
if (resp.IsSuccessStatusCode)
{
return await resp.Content.ReadAsStringAsync();
}
else
{
throw new Exception("Error");
}
}
public async Task GetInspection(string number)
{
string uri = "/LAB/Inspections/" + number;
var data = await GetData(uri, null);
return JsonConvert.DeserializeObject(data);
}
public class LabInspectionModel
{
public string Number { get; set; }
public int State { get; set; }
public string LabCode { get; set; }
public string LabName { get; set; }
public string PartNumber { get; set; }
public string PartChange { get; set; }
public string SupplierCode { get; set; }
public string CustomerCode { get; set; }
public string Specification { get; set; }
public string Description { get; set; }
public string SourceName { get; set; }
public string TypeCode { get; set; }
public string TypeName { get; set; }
public int Priority { get; set; }
public double? Amount { get; set; }
public double? Price { get; set; }
public string Currency { get; set; }
public double? InspectTime { get; set; }
public String CreatedBy { get; set; }
public DateTime? CreatedDate { get; set; }
public DateTime? SupplyDate { get; set; }
public String PlannedBy { get; set; }
public DateTime? PlannedStart { get; set; }
public DateTime? PlannedEnd { get; set; }
public String ProcessBy { get; set; }
public string ProcessorCode { get; set; }
public DateTime? ProcessStart { get; set; }
public DateTime? ProcessEnd { get; set; }
public int? ResultValue { get; set; }
public string ResultName { get; set; }
public string Note { get; set; }
}
Následující ukázka čte data z objektu https://example.com/CAQapi/PAL/SystemInfo/, který vrací informace o použité LICenci.
$cfg["api_user"] = 'definujte v Palstat CAQ';
$cfg['api_pass'] = 'definujte v Palstat CAQ';
$cfg['api_site'] = 'https://example.com/CAQapi/';
function api_read($url){
global $cfg;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_USERAGENT, "API Palstat Connector by LH / Curl");
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // TRUE to return the transfer as a string of the return value of curl_exec() instead of outputting it out directly.
curl_setopt($ch, CURLOPT_TIMEOUT, 100); // protect IIS
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, $cfg['api_user'].":".$cfg['api_pass']);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
$response = curl_exec($ch);
if ( $response === false ){ // zachyti connection error
echo 'Curl error: ' . curl_error($ch).' - '.$url;
exit;
}
curl_close($ch);
return $response;
}
//// CTEME LIC INFO
$json = api_read($cfg['api_site'].'PAL/SystemInfo/');
$obj = json_decode($json,true);
$runtime['api']['CustomerName'] = $obj['CustomerName'];
$runtime['api']['DatabaseId'] = $obj['DatabaseId'];
$runtime['api']['CustomerDivisionName'] = $obj['CustomerDivisionName'];
echo "
API OBJECT: PAL/SystemInfo/
CustomerName: ".$runtime['api']['CustomerName']."
DatabaseId: ".$runtime['api']['DatabaseId']."
CustomerDivisionName: ".$runtime['api']['CustomerDivisionName']."
";