Skip to content
This repository has been archived by the owner on Sep 28, 2020. It is now read-only.

Commit

Permalink
Updated the readme with the changes to the config file and made sure …
Browse files Browse the repository at this point in the history
…all functions are described, did a large code cleanup and implemented errors to be thrown when problems occur
  • Loading branch information
Chris-Pratt-Clystnet committed Jun 14, 2018
1 parent a32917a commit c0714af
Show file tree
Hide file tree
Showing 7 changed files with 448 additions and 224 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea
68 changes: 51 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Vtiger (Laravel 5 Package)
Use the Vtiger webservice (REST) API from within Laravel for operations Create, Retrieve and Update.
Use the Vtiger webservice (REST) API from within Laravel for the following operations.

- Create
- Retrieve
- Update
- Delete
- Query
- Describe

See [Third Party App Integration (REST APIs)](http://community.vtiger.com/help/vtigercrm/developers/third-party-app-integration.html)

Expand All @@ -12,7 +19,7 @@ See [Third Party App Integration (REST APIs)](http://community.vtiger.com/help/v
composer require "clystnet/vtiger ~1.3"
```
> *If you are using Laravel 5.5 you don’t need to do steps 2 and 3.*
> *If you are using Laravel >= 5.5 you don’t need to do steps 2 and 3.*
2. Then in your config/app.php add the following to the providers array:
Expand All @@ -36,42 +43,48 @@ See [Third Party App Integration (REST APIs)](http://community.vtiger.com/help/v
- In Vtiger, create a new or select an existing user.
- Under *User Advanced Options* make note of the *username* and *access key*.
- In your application, edit *config/vtiger.php* and replace the following array values with your CRM username and access key. Also set the url to the webservice.php
|key |value |
|---------|-------------------------------------|
|url |http://www.example.com/webservice.php|
|username |API |
|accesskey|irGsy9HB0YOZdEA |
- In your application, edit *config/vtiger.php* and replace the following array values
- Set the url to the https://{DOMAIN_NAME}/webservice.php
- Set the username and accesskey with your CRM username and access key.
- Set the session drive to either file or reddis
- Set persistconnection to false if you want a fresh login with each request
|key |value |
|-----------------|-------------------------------------|
|url |http://www.example.com/webservice.php|
|username |API |
|accesskey |irGsy9HB0YOZdEA |
|sessiondriver |file |
|persistconnection|true |
> Because I've experienced problems getting the sessionid from the CRM when multiple users are accessing the CRM at the same time, the solution was to store the sessionid into a file within Laravel application.
> Instead of getting the token from the database for each request using the webservice API, a check is made against the expiry time in the file. If the expiry time has expired, a token is requested from the CRM and file is updated with the new token and updated expiry time.
### Usage
In your controller include the Vtiger package
```
```php
use Vtiger;
```

#### Create

To insert a record into the CRM, first create an array of data to insert. Don't forget the added the id of the `assigned_user_id` (i.e. '4x12') otherwise the insert will fail as `assigned_user_id` is a mandatory field.
```
```php
$data = array(
'assigned_user_id' => '',
);
```
To do the actual insert, pass the module name along with the json encoded array to the *create* function.

```
```php
Vtiger::create($MODULE_NAME, json_encode($data));
```

#### Retrieve

To retrieve a record from the CRM, you need the id of the record you want to find (i.e. '4x12').
```
```php
$id = '4x12';

$obj = Vtiger::retrieve($id);
Expand All @@ -83,28 +96,40 @@ var_dump($obj);
#### Update

The easiest way to update a record in the CRM is to retrieve the record first.
```
```php
$id = '4x12';

$obj = Vtiger::retrieve($id);
```

Then update the object with updated data.
```
```php
$obj->result->field_name = 'Your new value';

$update = Vtiger::update($obj->result);
```

#### Delete

To delete a record from the CRM, you need the id of the record you want to delete (i.e. '4x12').
```php
$id = '4x12';

$obj = Vtiger::retrieve($id);

// do someting with the result
var_dump($obj);
```

#### Query

To use the [Query Operation](http://community.vtiger.com/help/vtigercrm/developers/third-party-app-integration.html#query-operation), you first need to create a SQL query.
```
```php
$query = "SELECT * FROM ModuleName;";
```

Then run the query...
```
```php
$obj = Vtiger::query($query);

//loop over result
Expand All @@ -113,13 +138,22 @@ foreach($obj->result as $result) {
}
```

### Describe

To describe modules in the CRM run this with the module name

```php
$moduleDescription = (Vtiger:describe("Contacts"))->result;
```

## Contributing

Please report any issue you find in the issues page. Pull requests are more than welcome.

## Authors

* **Adam Godfrey** - [Clystnet](https://www.clystnet.com)
* **Chris Pratt** - [Clystnet](https://www.clystnet.com)

## License

Expand Down
2 changes: 1 addition & 1 deletion src/Config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// vTiger API constants
return [
'url' => 'path/to/vtiger/webservice',
'url' => 'path/to/vtiger/webservice.php',
'username' => '',
'accesskey' => '',
'sessiondriver' => 'file', //reddis or file
Expand Down
2 changes: 2 additions & 0 deletions src/Facades/Vtiger.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@

class Vtiger extends Facade
{

protected static function getFacadeAccessor()
{
return 'clystnet-vtiger';
}

}
Loading

0 comments on commit c0714af

Please sign in to comment.