A modern PHP SDK for the JsonBin.io API. This SDK uses PHP 8.2+ and follows development best practices to provide you with a clean and fluent interface to the JsonBin.io API.
- Requirements
- Installation
- Usage
- Error Handling
- Configuration Options
- PHP 8.2 or higher
- Composer
composer require shevabam/jsonbin-sdk<?php
require 'vendor/autoload.php';
use JsonBinSDK\JsonBinClient;
// Initialize the client with your Master Key
$client = new JsonBinClient('YOUR_API_KEY');// Create a simple bin
$data = ['name' => 'John Doe', 'age' => 30];
$result = $client->bins()->create($data);
// Create a bin with options
$result = $client->bins()->create($data, [
'private' => true,
'name' => 'My test bin',
'collectionId' => 'COLLECTION_ID'
]);$binId = 'BIN_ID';
$bin = $client->bins()->read($binId);$binId = 'BIN_ID';
$updatedData = ['name' => 'Jane Doe', 'age' => 31];
$result = $client->bins()->update($binId, $updatedData);$binId = 'BIN_ID';
$result = $client->bins()->delete($binId);$result = $client->collections()->create('My Collection');$collectionId = 'COLLECTION_ID';
$collection = $client->collections()->read($collectionId);$collectionId = 'COLLECTION_ID';
$result = $client->collections()->update($collectionId, 'New Collection Name');$collectionId = 'COLLECTION_ID';
$result = $client->collections()->delete($collectionId);$collectionId = 'COLLECTION_ID';
$bins = $client->collections()->listBins($collectionId);$bins = $client->collections()->listUncategorizedBins();$collectionId = 'COLLECTION_ID';
$binId = 'BIN_ID';
$result = $client->collections()->addBin($collectionId, $binId);$collectionId = 'COLLECTION_ID';
$binId = 'BIN_ID';
$result = $client->collections()->removeBin($collectionId, $binId);$result = $client->accessKey()->create('My New Access Key 2', [
'read' => true,
'update' => true,
'delete' => true,
'create' => true,
]);$bins = $client->accessKey()->list();$accessKey = 'abc123';
$bins = $client->accessKey()->delete($accessKey);$bins = $client->log()->list();The SDK throws JsonBinSDK\Exception\ApiException when an API error occurs:
use JsonBinSDK\Exception\ApiException;
try {
$bin = $client->bins()->read('non_existent_id');
} catch (ApiException $e) {
echo 'API Error: ' . $e->getMessage();
}You can customize the SDK behavior when creating the client:
$client = new JsonBinClient('YOUR_API_KEY');
$client->getConfig()->setTimeout(60);