// JavaScript
async function callPricingFilterApi({
endPoint = "/api/v1/Pricing/Filter",
apiKey,
apiCustomerName,
filter,
orderBy,
token,
baseUrl
}) {
const url = `${baseUrl}${endPoint}`;
const dataToPost = {
EndPoint: endPoint,
APIKey: apiKey,
APICustomerName: apiCustomerName,
Filter: filter,
OrderBy: orderBy
};
const headers = {
"Content-Type": "application/json",
"Authorization": `Bearer ${token}`
};
try {
const response = await fetch(url, {
method: "POST",
headers: headers,
body: JSON.stringify(dataToPost)
});
if (!response.ok) {
throw new Error(`API request failed with status ${response.status}`);
}
const result = await response.json();
return result;
} catch (error) {
console.error("API error:", error);
return null;
}
}
(async () => {
const result = await callPricingFilterApi({
apiKey: "$apikey",
apiCustomerName: "$apiCustomerName",
token: "$apiOAuthToken",
baseUrl: "https://pricingapi.ultico.com.au",
filter: $searchFilter,
orderBy: $orderByFilter);
console.log(result);
})();
// C#
using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
public class ApiCaller
{
private static readonly HttpClient client = new HttpClient();
public async Task<string> CallPricingFilterApiAsync()
{
var url = "https://pricingapi.ultico.com.au/api/v1/Pricing/Filter";
var dataToPost = new
{
EndPoint = "/api/v1/Pricing/Filter",
APIKey = "$apikey",
APICustomerName = "$apiCustomerName",
Filter = $searchFilter,
OrderBy = $orderByFilter
};
string json = JsonConvert.SerializeObject(dataToPost);
var content = new StringContent(json, Encoding.UTF8, "application/json");
// Set Authorization header
client.DefaultRequestHeaders.Clear();
client.DefaultRequestHeaders.Add("Authorization", "Bearer $apiOAuthToken");
var response = await client.PostAsync(url, content);
response.EnsureSuccessStatusCode(); // throws if not 2xx
string responseBody = await response.Content.ReadAsStringAsync();
return responseBody;
}
}
}
<?php
// PHP
$url = "https://pricingapi.ultico.com.au/api/v1/Pricing/Filter";
$dataToPost = [
"EndPoint" => "/api/v1/Pricing/Filter",
"APIKey" => "$apikey",
"APICustomerName" => "$apiCustomerName",
"Filter" => $searchFilter,
"OrderBy" => $orderByFilter
];
$headers = [
"Content-Type: application/json",
"Authorization: Bearer $apiOAuthToken"
];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($dataToPost));
$response = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Request Error: ' . curl_error($ch);
} else {
echo 'Response: ' . $response;
}
curl_close($ch);
?>