1. Go to this page and download the library: Download iajson/client library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
iajson / client example snippets
use IaJson\Client\IaJsonClient;
// Discover a site's ia.json and create a client
$client = IaJsonClient::discover('techstore.example.com');
// Call a public endpoint (no authentication needed)
$results = $client->call('search_products', ['q' => 'wireless headphones']);
// Inspect the site
$site = $client->getSite();
echo $site['name']; // "TechStore"
echo $site['type']; // "ecommerce"
use IaJson\Client\Discovery;
$discovery = new Discovery();
$spec = $discovery->fetch('example.com');
// $spec is the full parsed ia.json array
echo $spec['version']; // "1.0.0"
echo $spec['api']['base_url']; // "https://example.com/api/v1"
$client = IaJsonClient::discover('techstore.example.com');
// Get all endpoints
$all = $client->getEndpoints();
// Get only public endpoints
$public = $client->getEndpoints('public');
// Get protected endpoints ({
$results = $client->call('search_products', ['q' => 'laptop']);
}
// Get rate limit info
$rateLimit = $client->getRateLimit(); // e.g., "1000/hour"
$client = IaJsonClient::discover('techstore.example.com');
// Step 1: Register your agent
$response = $client->register([
'name' => 'My AI Assistant',
'domain' => 'myai.example.com',
'webhook_url' => 'https://myai.example.com/ia/verify',
'contact' => '[email protected]',
'description' => 'AI shopping assistant',
]);
// Step 2: Your webhook receives a verification_code from the site.
// Step 3: Submit the verification code:
$credentials = $client->verify('vc_abc123def456');
// The client now has credentials set automatically.
// You can also store and re-use them:
echo $credentials['api_key']; // "ia_live_..."
echo $credentials['secret']; // "sec_..."
$client = IaJsonClient::discover('techstore.example.com');
$client->setCredentials('ia_live_abc123', 'sec_xyz789');
// Now you can call protected endpoints
$inventory = $client->call('get_inventory');
$client = IaJsonClient::discover('techstore.example.com');
$client->setCredentials('ia_live_abc123', 'sec_xyz789');
// Get the OAuth helper
$oauth = $client->getOAuth(
clientId: 'your_client_id',
clientSecret: 'your_client_secret',
);
// Step 1: Get the authorization URL for the user to visit
$result = $oauth->getAuthorizationUrl(
redirectUri: 'https://myai.example.com/callback',
scopes: ['cart:read', 'cart:write', 'orders:write'],
state: 'random_csrf_token',
);
echo $result['url']; // Redirect user here
// If PKCE is
public function index(Request $request)
{
$apiKey = $request->attributes->get('iajson_api_key');
// Use $apiKey to identify which agent is making the request
}