The following examples are just to get you started. Of course, you can use any programming language you want to make the API calls. The examples below are in cURL, JavaScript, Python, PHP and C#.
AllClients API Code Samples - GetContactNotes
curl / bash
curl -X POST https://www.allclients.com/api/2/GetContactNotes.aspx \
-d "accountid=YOUR_ACCOUNT_ID" \
-d "apikey=YOUR_API_KEY" \
-d "contactid=CONTACT_ID" \
-d "response_type=json" \
--ssl-required
javascript
Do not expose your API key in the browser. Only use the API Key on the server side, and render only the results back to the browser.
async function getContactNotes(accountId, apiKey, contactId) {
const url = 'https://www.allclients.com/api/2/GetContactNotes.aspx';
const formData = new FormData();
formData.append('accountid', accountId);
formData.append('apikey', apiKey);
formData.append('contactid', contactId);
formData.append('response_type', 'json');
try {
const response = await fetch(url, {
method: 'POST',
body: formData
});
if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
}
// Parse JSON response
const data = await response.json();
return data;
} catch (error) {
console.error('Error fetching contact notes:', error);
}
}
// Usage
getContactNotes('YOUR_ACCOUNT_ID', 'YOUR_API_KEY', 'CONTACT_ID')
.then(result => {
console.log(result);
});
python
import requests
def get_contact_notes(account_id, api_key, contact_id):
url = 'https://www.allclients.com/api/2/GetContactNotes.aspx'
payload = {
'accountid': account_id,
'apikey': api_key,
'contactid': contact_id,
'response_type': 'json'
}
try:
response = requests.post(url, data=payload)
response.raise_for_status() # Raise exception for 4XX/5XX status codes
# Parse JSON response
data = response.json()
return data
except requests.exceptions.RequestException as e:
print(f"Error making API request: {e}")
return None
except ValueError as e:
print(f"Error parsing JSON response: {e}")
return None
# Usage
account_id = 'YOUR_ACCOUNT_ID'
api_key = 'YOUR_API_KEY'
contact_id = 'CONTACT_ID'
result = get_contact_notes(account_id, api_key, contact_id)
if result is not None:
# Process the JSON result
print(result)
php
$accountId,
'apikey' => $apiKey,
'contactid' => $contactId,
'response_type' => 'json'
];
// Initialize cURL session
$ch = curl_init($url);
// Set cURL options
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
// Execute the request
$response = curl_exec($ch);
// Check for errors
if ($response === false) {
$error = curl_error($ch);
curl_close($ch);
throw new Exception("Error making API request: " . $error);
}
curl_close($ch);
// Parse the JSON response
$data = json_decode($response, true);
if (json_last_error() !== JSON_ERROR_NONE) {
throw new Exception("Error parsing JSON response: " . json_last_error_msg());
}
return $data;
}
// Usage
try {
$accountId = 'YOUR_ACCOUNT_ID';
$apiKey = 'YOUR_API_KEY';
$contactId = 'CONTACT_ID';
$result = getContactNotes($accountId, $apiKey, $contactId);
print_r($result);
} catch (Exception $e) {
echo "Error: " . $e->getMessage();
}
?>
c#
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Text.Json;
using System.Threading.Tasks;
public class AllClientsApi
{
public static async Task GetContactNotes(string accountId, string apiKey, string contactId)
{
// Create HTTP client
using var httpClient = new HttpClient();
// Create form content
var formContent = new FormUrlEncodedContent(new[]
{
new KeyValuePair("accountid", accountId),
new KeyValuePair("apikey", apiKey),
new KeyValuePair("contactid", contactId),
new KeyValuePair("response_type", "json")
});
try
{
// Send POST request
var response = await httpClient.PostAsync(
"https://www.allclients.com/api/2/GetContactNotes.aspx",
formContent);
// Ensure successful response
response.EnsureSuccessStatusCode();
// Read and parse the response content
var content = await response.Content.ReadAsStreamAsync();
return await JsonDocument.ParseAsync(content);
}
catch (HttpRequestException ex)
{
Console.WriteLine($"Error making API request: {ex.Message}");
return null;
}
catch (JsonException ex)
{
Console.WriteLine($"Error parsing JSON response: {ex.Message}");
return null;
}
}
// Usage example
public static async Task Main()
{
var accountId = "YOUR_ACCOUNT_ID";
var apiKey = "YOUR_API_KEY";
var contactId = "CONTACT_ID";
var result = await GetContactNotes(accountId, apiKey, contactId);
if (result != null)
{
Console.WriteLine(JsonSerializer.Serialize(
result,
new JsonSerializerOptions { WriteIndented = true }
));
}
}
}