PHP API Client for Mythradon¶
This guide provides a PHP module that helps developers interact with the Mythradon REST API. It supports standard HTTP methods and includes optional HMAC-based authentication.
Getting Started¶
To use the API client, you'll need the following:
-
Your API_KEY (required)
-
Your SECRET_KEY (optional, for HMAC authentication)
-
Your Mythradon instance URL
Download Mythradon PHP API Client¶
Download the Mythradon PHP API Client Library and unzip the contents into an appropriate folder.
The zip file consists of the following:
| File | Description |
|---|---|
| MythradonApiTest.php | Use this test script to verify that your platform instance can successfully connect to and use the REST API. |
| Client.php | Handles authenticated HTTP requests to the Mythradon API using cURL. |
| Header.php | Represents a single HTTP header (name/value pair). |
| Loader.php | Manually loads all core components of the MythradonApi namespace (for environments without PSR-4). |
| Response.php | Represents the HTTP response returned by the API, including headers, status code, and body. |
| ResponseError.php | Exception class thrown when an API request fails (non-2xx response). |
File Structure¶
MythradonApiTest.php
MythradonApi/
├── Client.php
├── Header.php
├── Loader.php
├── Response.php
├── ResponseError.php
MythradonApiTest.php – Test Script for Mythradon PHP API Client¶
This script provides a basic test of the MythradonApi\Client class to verify connectivity and functionality with a Mythradon API instance. It demonstrates how to:
- Authenticates with the API using either an API key or HMAC credentials.
- Create a new contact via a
POSTrequest. - Update that contact with a new last name using a
PUTrequest. - Handle and log errors if the API responds with a failure.
Configuration¶
At the top of the script, you'll need to define your connection details:
The script supports two types of authentication:
-
API Key only: - Calls
setApiKey()if only$apiKeyis provided. -
HMAC Authentication: - Calls both
setApiKey()andsetSecretKey()if both values are provided.
If neither is provided, it throws a RuntimeException.
To use HMAC, both $apiKey and $secretKey must be provided.
Examples¶
Create Contact¶
This creates a new Contact entity, optionally skipping duplicate checking with a custom header.
Update Contact¶
Updates the newly created contact with an updated last name.
Error Handling¶
Captures and prints errors returned by the API for easy debugging.
File Structure Context¶
This test script expects that the Mythradon SDK classes are accessible via:
Ensure your autoloader is set up correctly for testing.
Usage¶
Run the script in your terminal:
Features¶
-
Simple wrapper for RESTful requests
-
Supports
GET,POST,PUT,PATCH,DELETE, andOPTIONS -
Compatible with API Key and HMAC authentication
-
Handles errors and parses JSON responses
-
Optional support for custom ports and timeouts
Notes¶
-
The
idfield of each record is required for operations like update or delete. -
Use the Metadata API or Entity Manager to explore available entity names and attributes.
-
This module is intended for server-side use with PHP.
See also¶
API Client Examples:
- JavaScript API Client
- Mythradon Marketing
- Mythradon Sales
- Mythradon Service
- Mythradon System Administration
- Mythradon Tools