PHP code example of avalara / avalara_sdk

1. Go to this page and download the library: Download avalara/avalara_sdk 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/ */

    

avalara / avalara_sdk example snippets





nfigure HTTP OAUTH2 Access Token and other config options
$config = new \Avalara\SDK\Configuration();
$config->setBearerToken('YOUR_JWT_ACCESS_TOKEN');
$config->setAppName('YOUR_APP_NAME');
$config->setEnvironment('sandbox');
$config->setMachineName('YOUR_MACHINE_NAME');
$config->setAppVersion('YOUR_APP_VERSION');

$client = new \Avalara\SDK\ApiClient($config);

$apiInstance = new Avalara\\SDK\Api\AddressesApi($client);

$x_avalara_client = 'Swagger UI; 22.7.0; Custom; 1.0'; // string | Identifies the software you are using to call this API.  For more information on the client header, see [Client Headers](https://developer.avalara.com/avatax/client-headers/) .
$body = new \Avalara\\SDK\Model\\Avatax\AddressValidationInfo(); // \Avalara\\SDK\Model\\Avatax\AddressValidationInfo | The address to resolve

try {
    $result = $apiInstance->resolveAddressPost($x_avalara_client, $body);
    print_r($result);
} catch (Exception $e) {
    echo 'Exception when calling AddressesApi->resolveAddressPost: ', $e->getMessage(), PHP_EOL;
}



nfigure HTTP OAUTH2 Client Credentials Flow and other config options
$config = new \Avalara\SDK\Configuration();
$config->setClientId('YOUR_CLIENT_ID');
$config->setClientSecret('YOUR_CLIENT_SECRET');
$config->setAppName('YOUR_APP_NAME');
$config->setEnvironment('sandbox');
$config->setMachineName('YOUR_MACHINE_NAME');
$config->setAppVersion('YOUR_APP_VERSION');

$client = new \Avalara\SDK\ApiClient($config);

$apiInstance = new Avalara\\SDK\Api\AddressesApi($client);

$x_avalara_client = 'Swagger UI; 22.7.0; Custom; 1.0'; // string | Identifies the software you are using to call this API.  For more information on the client header, see [Client Headers](https://developer.avalara.com/avatax/client-headers/) .
$body = new \Avalara\\SDK\Model\\Avatax\AddressValidationInfo(); // \Avalara\\SDK\Model\\Avatax\AddressValidationInfo | The address to resolve

try {
    $result = $apiInstance->resolveAddressPost($x_avalara_client, $body);
    print_r($result);
} catch (Exception $e) {
    echo 'Exception when calling AddressesApi->resolveAddressPost: ', $e->getMessage(), PHP_EOL;
}


nfigure HTTP OAUTH2 Device Code Flow and other config options
$config = new \Avalara\SDK\Configuration();
$config->setClientId('YOUR_CLIENT_ID');
$config->setAppName('YOUR_APP_NAME');
$config->setEnvironment('sandbox');
$config->setMachineName('YOUR_MACHINE_NAME');
$config->setAppVersion('YOUR_APP_VERSION');

// Fetch Device Code 
$result = \Avalara\SDK\Auth\OAuthHelper::initiateDeviceAuthorizationFlow('avatax_api', $config);
// User Interaction needs to happen here - some polling logic is needed to wait for offline user to authenticate to verification_uri through browser
$tokenResult = \Avalara\SDK\Auth\OAuthHelper::getAccessTokenForDeviceFlow($result->deviceCode, $config);
// Once user authenticates, tokenResult will contain Bearer token.
$config->setBearerToken($tokenResult->accessToken);

$client = new \Avalara\SDK\ApiClient($config);

$apiInstance = new Avalara\\SDK\Api\AddressesApi($client);

$x_avalara_client = 'Swagger UI; 22.7.0; Custom; 1.0'; // string | Identifies the software you are using to call this API.  For more information on the client header, see [Client Headers](https://developer.avalara.com/avatax/client-headers/) .
$body = new \Avalara\\SDK\Model\\Avatax\AddressValidationInfo(); // \Avalara\\SDK\Model\\Avatax\AddressValidationInfo | The address to resolve

try {
    $result = $apiInstance->resolveAddressPost($x_avalara_client, $body);
    print_r($result);
} catch (Exception $e) {
    echo 'Exception when calling AddressesApi->resolveAddressPost: ', $e->getMessage(), PHP_EOL;
}

use Monolog\Logger;
use Monolog\Handler\StreamHandler;

$config = new \Avalara\SDK\Configuration();
// Configure logger
$logger = new Logger('AddressLogger');
$logger->pushHandler(new StreamHandler(__DIR__ . '/../../app.log', Logger::DEBUG));
// Setup log options , first parameter is logRequestAndResponseBody, which can be true|false. Second parameter is the PSR-3 compatible logger.
$logOptions = new \Avalara\SDK\Utils\LogOptions(true, $logger);
$config->setLogOptions($logOptions);
$client =  new \Avalara\SDK\ApiClient($config);