2017 © Pedro Peláez
 

library connectwise-php-client

SPINEN's PHP Client for ConnectWise.

image

michaelhull/connectwise-php-client

SPINEN's PHP Client for ConnectWise.

  • Monday, May 8, 2017
  • by michaelhull
  • Repository
  • 1 Watchers
  • 0 Stars
  • 6 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 3 Forks
  • 0 Open issues
  • 27 Versions
  • 0 % Grown

The README.md

SPINEN's ConnectWise PHP Client

Latest Stable Version Total Downloads Latest Unstable Version Dependency Status License, (*1)

PHP client for the RestFull ConnectWise API's. This package used to be based on the SOAP API's & had 3 separate repositories, but as of this version there is on this one., (*2)

We are using the "Member Impersonation" model where you setup an integrator username & password with access to the "Member API", which makes all calls to ConnectWise performed under the permission of the user (member id) of the application. We make all of our users in ConnnectWise member id equal to their email user (i.e. joe.doe@spinen.com has member id of joedoe in connectwise) [NOTE: The "." was removed from joe.doe as ConnectWise does not allow dots in the member id]. By following this convention, we can infer the member id from the logged in user's email address in our applications. We have included a trait that you can use on the User model that will preform the logic above., (*3)

We solely use Laravel for our applications, so there is some Laravel specific files that you can use if you are using this client in a Laravel application. We have tried to make sure that you can use the client outside of Laravel, and have some documentation about it below., (*4)

Laravel Configuration and Usage

Configuration

  1. Add the following to config/services.php...
    'connectwise' =>  [
        'company_id' => env('CW_COMPANY_ID'),
        'integrator' => env('CW_INTEGRATOR'),
        'password' => env('CW_PASSWORD'),
        'url' => env('CW_URL'),
    ],
  1. Add the appropriate values to .env...
CW_COMPANY_ID=<company_id>
CW_INTEGRATOR=<integrator username>
CW_PASSWORD=<integrator password>
CW_URL=https://<FQDN to ConnectWise server>
  1. Add the provider to config/app.php
'providers' => [
    # other providers omitted
    Spinen\ConnectWise\Laravel\ServiceProvider::class,
],
  1. [Optional] Add the alias to config/app.php
'aliases' => [
    # other aliases omitted
    'ConnectWise' => Spinen\ConnectWise\Laravel\Facades\ConnectWise::class,
],
  1. Use the ConnectWiseMemberIdFromEmail trait on the User model, which is located at Spinen\ConnectWise\Laravel\ConnectWiseMemberIdFromEmail, if your ConnectWise member_id is a match to your email as described above. If you do not follow that convention, then you can define your own getConnectWiseMemberIdAttribute accessor on the User model or just add a connect_wise_member_id column to your user table that you populate with the appropriate values.

Usage

Here is an example of getting the system information..., (*5)

As of version 3.1.0, the response is either a Laravel collection of models or a single model. You can see the models in src/Models. They all extend Spinen\ConnectWise\Support, so you can see the methods that they provide., (*6)

$ php artisan tinker
Psy Shell v0.8.0 (PHP 7.0.14 — cli) by Justin Hileman
>>> Auth::loginUsingId(1);
PHP warning:  unlink(/Users/jimmy.puckett/git/swaginator.com/storage/framework/sessions/1aMf1yhUe6h4Ij2GRvq5UYab1IqK7GVn1qkyWPY6): No such file or directory in /Users/jimmy.puckett/git/swaginator.com/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php on line 172
=> App\User {#983
     id: "1",
     first_name: "Joe",
     last_name: "Doe",
     email: "joe.doe@domain.tld",
     admin: "0",
     created_at: "2017-01-02 18:30:47",
     updated_at: "2017-01-12 22:22:39",
     logged_in_at: "2017-01-12 22:22:39",
     deleted_at: null,
   }
>>> $cw = app('Spinen\ConnectWise\Api\Client');
=> Spinen\ConnectWise\Api\Client {#934}
>>> $info = $cw->get('system/info');
=> Spinen\ConnectWise\Models\System\Info {#1008}
>>> $info->toArray();
=> [
     "version" => "v2016.6.43325",
     "isCloud" => false,
     "serverTimeZone" => "Eastern Standard Time",
   ]
>>> $info->toJson()
=> "{"version":"v2016.6.43325","isCloud":false,"serverTimeZone":"Eastern Standard Time"}"
>>> $info->isCloud
=> false
>>> $info['isCloud'];
=> false

Same call using the facade..., (*7)

$ php artisan tinker
Psy Shell v0.8.0 (PHP 7.0.14 — cli) by Justin Hileman
>>> Auth::loginUsingId(1);
PHP warning:  unlink(/Users/jimmy.puckett/git/swaginator.com/storage/framework/sessions/1aMf1yhUe6h4Ij2GRvq5UYab1IqK7GVn1qkyWPY6): No such file or directory in /Users/jimmy.puckett/git/swaginator.com/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php on line 172
=> App\User {#983
     id: "1",
     first_name: "Joe",
     last_name: "Doe",
     email: "joe.doe@domain.tld",
     admin: "0",
     created_at: "2017-01-02 18:30:47",
     updated_at: "2017-01-12 22:22:39",
     logged_in_at: "2017-01-12 22:22:39",
     deleted_at: null,
   }
>>> ConnectWise::get('system/info');
=> Spinen\ConnectWise\Models\System\Info {#1005}
>>> ConnectWise::get('system/info')->toArray();
=> [
     "version" => "v2016.6.43325",
     "isCloud" => false,
     "serverTimeZone" => "Eastern Standard Time",
   ]
>>> ConnectWise::get('system/info')->toJson();
=> "{"version":"v2016.6.43325","isCloud":false,"serverTimeZone":"Eastern Standard Time"}"
>>> ConnectWise::get('system/info')->isCloud;
=> false
>>> ConnectWise::get('system/info')['isCloud'];
=> false
>>>

Non-Laravel Usage

To use the client outside of Laravel, you just need to new-up the objects..., (*8)

$ php -a
Interactive shell

php > // Autoload classes
php > require 'vendor/autoload.php';
php > // New-up objects
php > $token = new Spinen\ConnectWise\Api\Token();
php > $guzzle = new GuzzleHttp\Client();
php > $resolver = new Spinen\ConnectWise\Support\ModelResolver();
php > $client = new Spinen\ConnectWise\Api\Client($token, $guzzle, $resolver);
php > // Now set your configs
php > $token->setCompanyId('<company_id>')->setMemberId('<member_id>');
php > $client->setIntegrator('<integrator>')->setPassword('<password>')->setUrl('https://<domain.tld>');
php > $info = $client->get('system/info');
php > var_export($info, false);
Spinen\ConnectWise\Models\System\Info::__set_state(array(
   'casts' =>
  array (
    'version' => 'string',
    'isCloud' => 'boolean',
    'serverTimeZone' => 'string',
  ),
   'attributes' =>
  array (
    'version' => 'v2016.6.43325',
    'isCloud' => false,
    'serverTimeZone' => 'Eastern Standard Time',
  ),
))
php > var_export($info->toArray(), false);
array (
  'version' => 'v2016.6.43325',
  'isCloud' => false,
  'serverTimeZone' => 'Eastern Standard Time',
)
php > var_export($info->tojson(), false);
'{"version":"v2016.6.43325","isCloud":false,"serverTimeZone":"Eastern Standard Time"}'
php > var_export($info->isCloud, false);
false
php > var_export($info['isCloud'], false);
false
php >

The Versions

08/05 2017

dev-develop

dev-develop

SPINEN's PHP Client for ConnectWise.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jimmy Puckett

client spinen connectwise

16/01 2017

dev-ssfinney-update-readme

dev-ssfinney-update-readme

SPINEN's PHP Client for ConnectWise.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jimmy Puckett

client spinen connectwise

13/01 2017

dev-master

9999999-dev

SPINEN's PHP Client for ConnectWise.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jimmy Puckett

client spinen connectwise

13/01 2017

3.1.0

3.1.0.0

SPINEN's PHP Client for ConnectWise.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jimmy Puckett

client spinen connectwise

13/01 2017

dev-feature/returnObjects

dev-feature/returnObjects

SPINEN's PHP Client for ConnectWise.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jimmy Puckett

client spinen connectwise

08/01 2017

3.0.0

3.0.0.0

SPINEN's PHP Client for ConnectWise.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jimmy Puckett

client spinen connectwise

08/01 2017

dev-feature/moveToRestFulApi

dev-feature/moveToRestFulApi

SPINEN's PHP Client for ConnectWise.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jimmy Puckett

client spinen connectwise

06/11 2015

2.6.0

2.6.0.0

SPINEN's PHP Client for ConnectWise.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jimmy Puckett

client spinen connectwise

06/11 2015

2.3.2

2.3.2.0

SPINEN's PHP Client for ConnectWise.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jimmy Puckett

client spinen connectwise

17/09 2015

2.3.0

2.3.0.0

PHP Client for ConnectWise using spinen/connectwise-php-library.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jimmy Puckett

client spinen connectwise

17/09 2015

2.3.1

2.3.1.0

PHP Client for ConnectWise using spinen/connectwise-php-library.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jimmy Puckett

client spinen connectwise

04/05 2015

2.2.3

2.2.3.0

PHP Client for ConnectWise using spinen/connectwise-php-library.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jimmy Puckett

client spinen connectwise

02/05 2015

2.2.2

2.2.2.0

PHP Client for ConnectWise using spinen/connectwise-php-library.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jimmy Puckett

client spinen connectwise

26/04 2015

2.2.1

2.2.1.0

PHP Client for ConnectWise using spinen/connectwise-php-library.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jimmy Puckett

client spinen connectwise

25/04 2015

2.2.0

2.2.0.0

PHP Client for ConnectWise using spinen/connectwise-php-library.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jimmy Puckett

client spinen connectwise

18/04 2015

2.1.2

2.1.2.0

PHP Client for ConnectWise using spinen/connectwise-php-library.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jimmy Puckett

client spinen connectwise

18/04 2015

2.1.3

2.1.3.0

PHP Client for ConnectWise using spinen/connectwise-php-library.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jimmy Puckett

client spinen connectwise

18/04 2015

2.1.4

2.1.4.0

PHP Client for ConnectWise using spinen/connectwise-php-library.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jimmy Puckett

client spinen connectwise

18/04 2015

2.1.1

2.1.1.0

PHP Client for ConnectWise using spinen/connectwise-php-library.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jimmy Puckett

client spinen connectwise

18/04 2015

2.1.0

2.1.0.0

PHP Client for ConnectWise using spinen/connectwise-php-library.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jimmy Puckett

client spinen connectwise

15/04 2015

2.0.6

2.0.6.0

PHP Client for ConnectWise using spinen/connectwise-php-library.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jimmy Puckett

client spinen connectwise

14/04 2015

2.0.5

2.0.5.0

PHP Client for ConnectWise using spinen/connectwise-php-library.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jimmy Puckett

client spinen connectwise

13/04 2015

2.0.4

2.0.4.0

PHP Client for ConnectWise using spinen/connectwise-php-library.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jimmy Puckett

client spinen connectwise

12/04 2015

2.0.2

2.0.2.0

PHP Client for ConnectWise using spinen/connectwise-php-library.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jimmy Puckett

client spinen connectwise

12/04 2015

2.0.3

2.0.3.0

PHP Client for ConnectWise using spinen/connectwise-php-library.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jimmy Puckett

client spinen connectwise

12/04 2015

2.0.1

2.0.1.0

PHP Client for ConnectWise using spinen/connectwise-php-library.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jimmy Puckett

client spinen connectwise

12/04 2015

2.0.0

2.0.0.0

PHP Client for ConnectWise using spinen/connectwise-php-library.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jimmy Puckett

client spinen connectwise