Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG

## v8.7.0 (2026-02-25)

- Adds generic `makeApiCall` function

## v8.6.0 (2026-02-20)

- Adds the following functions:
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "easypost/easypost-php",
"description": "EasyPost Shipping API Client Library for PHP",
"version": "8.6.0",
"version": "8.7.0",
"keywords": [
"shipping",
"api",
Expand Down
2 changes: 1 addition & 1 deletion lib/EasyPost/Constant/Constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ abstract class Constants
const BETA_API_VERSION = 'beta';

// Library constants
const LIBRARY_VERSION = '8.6.0';
const LIBRARY_VERSION = '8.7.0';
const SUPPORT_EMAIL = 'support@easypost.com';

// Validation
Expand Down
21 changes: 21 additions & 0 deletions lib/EasyPost/EasyPostClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
use EasyPost\Exception\General\EasyPostException;
use EasyPost\Hook\RequestHook;
use EasyPost\Hook\ResponseHook;
use EasyPost\Http\Requestor;
use EasyPost\Service\AddressService;
use EasyPost\Util\InternalUtil;
use EasyPost\Service\ApiKeyService;
use EasyPost\Service\BaseService;
use EasyPost\Service\BatchService;
Expand Down Expand Up @@ -260,4 +262,23 @@ public function unsubscribeFromResponseHook(callable $function): void
{
$this->responseEvent->removeHandler($function);
}

/**
* Make an API call to the EasyPost API.
*
* This public, generic interface is useful for making arbitrary API calls to the EasyPost API that
* are not yet supported by the client library's services. When possible, the service for your use case
* should be used instead as it provides a more convenient and higher-level interface depending on the endpoint.
*
* @param string $method
* @param string $endpoint
* @param mixed $params
* @return mixed
*/
public function makeApiCall(string $method, string $endpoint, mixed $params = null): mixed
{
$response = Requestor::request($this, $method, $endpoint, $params);

return InternalUtil::convertToEasyPostObject($this, $response);
}
}
31 changes: 31 additions & 0 deletions test/EasyPost/EasyPostClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,22 @@

class EasyPostClientTest extends TestCase
{
/**
* Setup the testing environment for this file.
*/
public static function setUpBeforeClass(): void
{
TestUtil::setupVcrTests();
}

/**
* Cleanup the testing environment once finished.
*/
public static function tearDownAfterClass(): void
{
TestUtil::teardownVcrTests();
}

/**
* Test setting and getting the API key for different EasyPostClients.
*/
Expand Down Expand Up @@ -66,4 +82,19 @@ public function testInvalidServiceProperty(): void
);
}
}

/**
* Test making an API call using the generic makeApiCall method.
*/
public function testMakeApiCall(): void
{
TestUtil::setupCassette('client/makeApiCall.yml');

$client = new EasyPostClient((string)getenv('EASYPOST_TEST_API_KEY'));

$response = $client->makeApiCall('get', '/addresses', ['page_size' => 1]);

$this->assertCount(1, $response['addresses']);
$this->assertEquals('Address', $response['addresses'][0]['object']);
}
}
84 changes: 84 additions & 0 deletions test/cassettes/client/makeApiCall.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading