PHP code example of xero-apimatic / xero-apimatic-sdk

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

    

xero-apimatic / xero-apimatic-sdk example snippets


use XeroApIsLib\Logging\LoggingConfigurationBuilder;
use XeroApIsLib\Logging\RequestLoggingConfigurationBuilder;
use XeroApIsLib\Logging\ResponseLoggingConfigurationBuilder;
use Psr\Log\LogLevel;
use XeroApIsLib\Environment;
use XeroApIsLib\Authentication\Oauth2CredentialsBuilder;
use XeroApIsLib\Models\OauthScopeOauth2;
use XeroApIsLib\Authentication\BasicAuthCredentialsBuilder;
use XeroApIsLib\XeroApIsClientBuilder;

$client = XeroApIsClientBuilder::init()
    ->oauth2Credentials(
        Oauth2CredentialsBuilder::init(
            'OAuthClientId',
            'OAuthClientSecret',
            'OAuthRedirectUri'
        )
            ->oauthScopes(
                [
                    OauthScopeOauth2::EMAIL,
                    OauthScopeOauth2::OPENID
                ]
            )
    )
    ->basicAuthCredentials(
        BasicAuthCredentialsBuilder::init(
            'Username',
            'Password'
        )
    )
    ->environment(Environment::PRODUCTION)
    ->loggingConfiguration(
        LoggingConfigurationBuilder::init()
            ->level(LogLevel::INFO)
            ->requestConfiguration(RequestLoggingConfigurationBuilder::init()->body(true))
            ->responseConfiguration(ResponseLoggingConfigurationBuilder::init()->headers(true))
    )
    ->build();