|
| 1 | +# GroCRM.php |
| 2 | + |
| 3 | +The Gro CRM SDK allows you to easily connect to the Gro CRM REST API from PHP. |
| 4 | + |
| 5 | +With the Gro CRM SDK you can manage your contacts, tasks, deals, inventory, and much more! |
| 6 | + |
| 7 | +## Getting started |
| 8 | + |
| 9 | +### Installation |
| 10 | + |
| 11 | +The recommended way to install this framework is via [composer](https://getcomposer.org). |
| 12 | + |
| 13 | +```no-highlight |
| 14 | +composer require grocrm/grocrm |
| 15 | +``` |
| 16 | + |
| 17 | +### Getting started |
| 18 | + |
| 19 | +For additional information regarding parameters that are accepted by `fields`, response values that are returned from each method, and more please visit [Gro CRM Documentation](https://www.grocrm.com/developer/docs/). |
| 20 | + |
| 21 | +#### Initialize the Client |
| 22 | + |
| 23 | +```php |
| 24 | +<?php |
| 25 | + |
| 26 | +require "vendor/autoload.php"; |
| 27 | + |
| 28 | +use GroCRM\Client |
| 29 | + |
| 30 | +$client = new Client("gro_crm_api_key"); |
| 31 | +``` |
| 32 | + |
| 33 | +#### Contact Methods |
| 34 | + |
| 35 | +```php |
| 36 | + |
| 37 | +// Return the contacts api class |
| 38 | +$contacts = $client->contacts(); |
| 39 | + |
| 40 | +// Return contact types or a single type with id |
| 41 | +$contactTypes = $contacts->types($id = null); |
| 42 | + |
| 43 | +// Create a contact |
| 44 | +$newContact = $contacts->create(array $fields); |
| 45 | + |
| 46 | +// Return a list of contacts |
| 47 | +$allContacts = $contacts->getAll($page = 1, $per_page = 20, $search = null, $sort = "date", $order = "desc"); |
| 48 | + |
| 49 | +// Return the contact with the specified id |
| 50 | +$contact = $contacts->get($id); |
| 51 | + |
| 52 | +// Return the contacts associated with the specified contact id |
| 53 | +$associatedContacts = $contacts->getAssociatedContacts($id, $page = 1, $per_page = 20, $search = null, $sort = "date", $order = "desc"); |
| 54 | + |
| 55 | +// Return the deals associated with the specified contact id |
| 56 | +$associatedDeals = $contacts->getAssociatedDeals($id, $page = 1, $per_page = 20, $search = null, $sort = "date", $order = "desc"); |
| 57 | + |
| 58 | +// Return the tasks associated with the specified contact id |
| 59 | +$associatedTasks = $contacts->getAssociatedTasks($id, $page = 1, $per_page = 20, $search = null, $sort = "date", $order = "desc"); |
| 60 | + |
| 61 | +// Update the contact with the specified id |
| 62 | +$updatedContact = $contacts->update($id, array $fields); |
| 63 | + |
| 64 | +// Delete the contact with the specified id |
| 65 | +$contacts->delete($id); |
| 66 | +``` |
| 67 | + |
| 68 | +#### Deal Methods |
| 69 | + |
| 70 | +```php |
| 71 | + |
| 72 | +// Return the deals api class |
| 73 | +$deals = $client->deals(); |
| 74 | + |
| 75 | +// Return deal sources or a single source with id |
| 76 | +$dealSources = $deals->sources($id = null); |
| 77 | + |
| 78 | +// Return deal stages or a single stage with id |
| 79 | +$dealStages = $deals->stages($id = null); |
| 80 | + |
| 81 | +// Return deal scores or a single score with id |
| 82 | +$dealScores = $deals->scores($id = null); |
| 83 | + |
| 84 | +// Create a deal |
| 85 | +$newDeal = $deals->create(array $fields); |
| 86 | + |
| 87 | +// Return a list of deals |
| 88 | +$allDeals = $deals->getAll($page = 1, $per_page = 20, $search = null, $sort = "date", $order = "desc"); |
| 89 | + |
| 90 | +// Return the deal with the specified id |
| 91 | +$deal = $deals->get($id); |
| 92 | + |
| 93 | +// Update the deal with the specified id |
| 94 | +$updatedDeal = $deals->update($id, array $fields); |
| 95 | + |
| 96 | +// Delete the deal with the specificed id |
| 97 | +$deals->delete($id) |
| 98 | + |
| 99 | +``` |
| 100 | + |
| 101 | +#### Task Methods |
| 102 | + |
| 103 | +```php |
| 104 | + |
| 105 | +// Return the tasks api class |
| 106 | +$tasks = $client->tasks(); |
| 107 | + |
| 108 | +// Return task statuses or a single status with id |
| 109 | +$taskStatuses = $tasks->statuses($id = null); |
| 110 | + |
| 111 | +// Return task priorities or a single priority with id |
| 112 | +$taskPriorities = $tasks->priorities($id = null); |
| 113 | + |
| 114 | +// Return task scores or a single scores with id |
| 115 | +$taskScores = $tasks->scores($id = null); |
| 116 | + |
| 117 | +// Create a task |
| 118 | +$newTask = $tasks->create(array $fields); |
| 119 | + |
| 120 | +// Return a list of tasks |
| 121 | +$allTasks = $tasks->getAll($page = 1, $per_page = 20, $search = "", $sort = "date", $order = "desc") |
| 122 | + |
| 123 | +// Return the task with the specified id |
| 124 | +$task = $tasks->get($id) |
| 125 | + |
| 126 | +// Update the task with the specified id |
| 127 | +$updatedTask = $tasks->update($id, array $fields) |
| 128 | + |
| 129 | +// Delete the task with the specified id |
| 130 | +$tasks->delete($id) |
| 131 | + |
| 132 | +``` |
| 133 | + |
| 134 | +#### Inventory Methods |
| 135 | + |
| 136 | +```php |
| 137 | + |
| 138 | +// Return the inventory api class |
| 139 | +$inventory = $client->inventory(); |
| 140 | + |
| 141 | +// Return inventory types or a single type with id |
| 142 | +$inventoryTypes = $inventory->types($id = null); |
| 143 | + |
| 144 | +// Create a new inventory item |
| 145 | +$newInventoryItem = $inventory->create(array $fields); |
| 146 | + |
| 147 | +// Return a list of inventory items |
| 148 | +$allInventory = $inventory->getAll($page = 1, $per_page = 20, $search = "", $sort = "date", $order = "desc"); |
| 149 | + |
| 150 | +// Return the inventory item with the specified id |
| 151 | +$inventoryItem = $inventory->get($id); |
| 152 | + |
| 153 | +// Update the inventory item with the specified id |
| 154 | +$updatedInventoryItem = $inventory->update($id, array $fields); |
| 155 | + |
| 156 | +// Delete the inventory item with the specified id |
| 157 | +$inventory->delete($id); |
| 158 | +``` |
| 159 | + |
| 160 | +#### Company Methods |
| 161 | + |
| 162 | +```php |
| 163 | + |
| 164 | +// Return the company api class |
| 165 | +$company = $client->company(); |
| 166 | + |
| 167 | +// Return your companies information |
| 168 | +$companyInfo = $company->get(); |
| 169 | + |
| 170 | +// Update your companies information |
| 171 | +$updatedCompanyInfo = $company->update(array $fields); |
| 172 | + |
| 173 | +``` |
| 174 | + |
| 175 | + |
| 176 | +#### User Methods |
| 177 | + |
| 178 | +```php |
| 179 | + |
| 180 | +// Return the user api class |
| 181 | +$users = $client->users(); |
| 182 | + |
| 183 | +// Return user roles or a single role with id |
| 184 | +$userRoles = $users->roles($id = null); |
| 185 | + |
| 186 | +// Return a list of users |
| 187 | +$allUsers = $users->getAll($page = 1, $per_page = 20, $search = "", $sort = "date", $order = "desc"); |
| 188 | + |
| 189 | +// Return a user with the specified id |
| 190 | +$user = $users->get($id); |
| 191 | + |
| 192 | +// Return the currently authenticated user |
| 193 | +$authenticatedUser = $users->getAuthenticated(); |
| 194 | + |
| 195 | +``` |
| 196 | + |
| 197 | +#### Global Methods |
| 198 | + |
| 199 | +```php |
| 200 | + |
| 201 | +// Return countries or a single country with id |
| 202 | +$countries = $client->getCountries($id = null); |
| 203 | + |
| 204 | +// Return timezones or a single timezone with id |
| 205 | +$timezones = $client->getTimeszones($id = null); |
| 206 | + |
| 207 | +// Return currenciesor a single currency with id |
| 208 | +$currencies = $client->getCurrencies($id = null); |
| 209 | + |
| 210 | +``` |
| 211 | + |
| 212 | +#### Pagination |
| 213 | + |
| 214 | +Any of the methods that return multiple items can use the pager class to paginate through multiple pages of data. |
| 215 | + |
| 216 | +```php |
| 217 | + |
| 218 | +$contactsPage1 = $client->contacts()->getAll(); |
| 219 | +$pager = new GroCRM\API\Pager($client, $contacts); |
| 220 | + |
| 221 | +if ($pager->hasNext()) { |
| 222 | + $contactsPage2 = $pager->getNext(); |
| 223 | +} |
| 224 | + |
| 225 | +``` |
| 226 | + |
| 227 | +#### Exceptions |
| 228 | + |
| 229 | +The Gro CRM SDK uses Guzzle for all network requests, if you attempt a request and the request fails a Guzzle exception will be thrown. For more information about Guzzle exceptions please see the [Guzzle Docs](http://docs.guzzlephp.org/en/latest/quickstart.html#exceptions) |
| 230 | + |
| 231 | +##### Example |
| 232 | + |
| 233 | +```php |
| 234 | + |
| 235 | +try { |
| 236 | + $contacts = $client->contacts()->getAll(); |
| 237 | + var_dump($contacts); |
| 238 | + |
| 239 | +} catch (GuzzleHttp\Exception\ClientException $e) { |
| 240 | + $response = $e->getResponse(); |
| 241 | + $statusCode = $response->getStatusCode(); |
| 242 | + $body = $response->getBody()->getContents(); |
| 243 | + $errors = json_decode($body, true); |
| 244 | + var_dump($errors); |
| 245 | +} |
| 246 | + |
| 247 | +``` |
| 248 | + |
| 249 | +### Need Help? No Problem! |
| 250 | + |
| 251 | +If you need help please contact us at [opensource@grocrm.com](mailto:opensource@grocrm.com?Subject=Gro%20CRM%20PHP%20SDK%20Help) or ask a question on [StackOverflow](http://stackoverflow.com/questions/tagged/grocrm) (Tag 'grocrm') |
| 252 | + |
| 253 | +Found a bug? Please open an [issue](https://github.com/GroCRM/GroCRM.php/issues) |
| 254 | + |
0 commit comments