{"id":23003732,"url":"https://github.com/stechstudio/laravel-hubspot","last_synced_at":"2026-04-02T14:34:45.500Z","repository":{"id":59643093,"uuid":"535381426","full_name":"stechstudio/laravel-hubspot","owner":"stechstudio","description":null,"archived":false,"fork":false,"pushed_at":"2024-03-12T23:27:34.000Z","size":24673,"stargazers_count":17,"open_issues_count":3,"forks_count":6,"subscribers_count":5,"default_branch":"main","last_synced_at":"2024-04-27T02:02:37.306Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/stechstudio.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-09-11T17:58:35.000Z","updated_at":"2024-04-11T21:23:16.000Z","dependencies_parsed_at":"2024-03-13T00:28:35.539Z","dependency_job_id":"810c63e4-5562-4f92-8c14-c647e03d0eaa","html_url":"https://github.com/stechstudio/laravel-hubspot","commit_stats":{"total_commits":65,"total_committers":2,"mean_commits":32.5,"dds":"0.32307692307692304","last_synced_commit":"09bdc780770f46b753f7042fb3f86e7abd08ca9b"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stechstudio%2Flaravel-hubspot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stechstudio%2Flaravel-hubspot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stechstudio%2Flaravel-hubspot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stechstudio%2Flaravel-hubspot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stechstudio","download_url":"https://codeload.github.com/stechstudio/laravel-hubspot/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":229790943,"owners_count":18124608,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-15T07:15:11.855Z","updated_at":"2026-01-06T21:19:12.838Z","avatar_url":"https://github.com/stechstudio.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# HubSpot CRM SDK for Laravel\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/stechstudio/laravel-hubspot.svg?style=flat-square)](https://packagist.org/packages/stechstudio/laravel-hubspot)\n\n[//]: # ([![Total Downloads]\u0026#40;https://img.shields.io/packagist/dt/stechstudio/laravel-hubspot.svg?style=flat-square\u0026#41;]\u0026#40;https://packagist.org/packages/stechstudio/laravel-hubspot\u0026#41;)\n\nInteract with HubSpot's CRM with an enjoyable, Eloquent-like developer experience.\n\n- Familiar Eloquent CRUD methods `create`, `find`, `update`, and `delete`\n- Associated objects work like relations: `Deal::find(555)-\u003enotes` and `Contact::find(789)-\u003enotes()-\u003ecreate(...)`\n- Retrieving lists of objects feels like a query builder: `Company::where('state','NC')-\u003eorderBy('custom_property')-\u003epaginate(20)`\n- Cursors provide a seamless way to loop through all records: `foreach(Contact::cursor() AS $contact) { ... }`\n\n\u003e **Note**\n\u003e Only the CRM API is currently implemented.\n\n## Installation\n\n### 1) Install the package via composer:\n\n```bash\ncomposer require stechstudio/laravel-hubspot\n```\n\n### 2) Configure HubSpot\n\n[Create a private HubSpot app](https://developers.hubspot.com/docs/api/private-apps#create-a-private-app) and give it appropriate scopes for what you want to do with this SDK.\n\nCopy the provided access token, and add to your Laravel `.env` file:\n\n```bash\nHUBSPOT_ACCESS_TOKEN=XXX-XXX-XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX\n```\n\n## Usage\n\n### Individual CRUD actions\n\n#### Retrieving\n\nYou may retrieve single object records using the `find` method on any object class and providing the ID.\n\n```php\nuse STS\\HubSpot\\Crm\\Contact;\n\n$contact = Contact::find(123);\n```\n\n#### Creating\n\nTo create a new object record, use the `create` method and provide an array of properties.\n\n```php\n$contact = Contact::create([\n    'firstname' =\u003e 'Test',\n    'lastname' =\u003e 'User',\n    'email' =\u003e 'testuser@example.com'\n]);\n```\n\nAlternatively you can create the class first, provide properties one at a time, and then `save`.\n\n```php\n$contact = new Contact;\n$contact-\u003efirstname = 'Test';\n$contact-\u003elastname = 'User';\n$contact-\u003eemail = 'testuser@example.com';\n$contact-\u003esave();\n```\n\n#### Updating\n\nOnce you have retrieved or created an object, update with the `update` method and provide an array of properties to change.\n\n```php\nContact::find(123)-\u003eupdate([\n    'email' =\u003e 'newemail@example.com'\n]);\n```\n\nYou can also change properties individually and then `save`.\n\n```php\n$contact = Contact::find(123);\n$contact-\u003eemail = 'newemail@example.com';\n$contact-\u003esave();\n```\n\n#### Deleting\n\nThis will \"archive\" the object in HubSpot.\n\n```php\nContact::find(123)-\u003edelete();\n```\n\n### Retrieving multiple objects\n\nFetching a collection of objects from an API is different from querying a database directly in that you will always be limited in how many items you can fetch at once. You can't ask HubSpot to return ALL your contacts if you have thousands.\n\nThis package provides three different ways of fetching these results.\n\n#### Paginating\n\nSimilar to a traditional database paginated result, you can paginate through a HubSpot collection of objects.\nYou will receive a `LengthAwarePaginator` just like with Eloquent, which means you can generate links in your UI just like you are used to.\n\n```php\n$contacts = Contact::paginate(20);\n```\n\nBy default, this `paginate` method will look at the `page` query parameter. You can customize the query parameter key by passing a string as the second argument.\n\n#### Cursor iteration\n\nYou can use the `cursor` method to iterate over the entire collection of objects.\nThis uses [lazy collections](https://laravel.com/docs/9.x/collections#lazy-collections) and [generators](https://www.php.net/manual/en/language.generators.overview.php)\nto seamlessly fetch chunks of records from the API as needed, hydrating objects when needed, and providing smooth iteration over a limitless number of objects.\n\n```php\n// This will iterate over ALL your contacts!\nforeach(Contact::cursor() AS $contact) {\n    echo $contact-\u003eid . \"\u003cbr\u003e\";\n}\n```\n\n\u003e **Warning**\n\u003e API rate limiting can be an obstacle when using this approach. Be careful about iterating over huge datasets very quickly, as this will still require quite a few API calls in the background.\n\n#### Manually fetching chunks\n\nOf course, you can grab collections of records with your own manual pagination or chunking logic.\nUse the `take` and `after` methods to specify what you want to grab, and then `get`.\n\n```php\n// This will get 100 contact records, starting at 501\n$contacts = Contact::take(100)-\u003eafter(500)-\u003eget();\n\n// This will get the default 50 records, starting at the first one\n$contacts = Contact::get();\n```\n\n### Searching and filtering\n\nWhen retrieving multiple objects, you will frequently want to filter, search, and order these results.\nYou can use a fluent interface to build up a query before retrieving the results.\n\n#### Adding filters\n\nUse the `where` method to add filters to your query.\nYou can use any of the supported operators for the second argument, see here for the full list: [https://developers.hubspot.com/docs/api/crm/search#filter-search-results](https://developers.hubspot.com/docs/api/crm/search#filter-search-results);\n\nThis package also provides friendly aliases for common operators `=`, `!=`, `\u003e`, `\u003e=`, `\u003c`, `\u003c=`, `exists`, `not exists`, `like`, and `not like`.\n\n```php\nContact::where('lastname','!=','Smith')-\u003eget();\n```\n\nYou can omit the operator argument and `=` will be used.\n\n```php\nContact::where('email', 'johndoe@example.com')-\u003eget();\n```\n\nFor the `BETWEEN` operator, provide the lower and upper bounds as a two-element tuple.\n\n```php\nContact::where('days_to_close', 'BETWEEN', [30, 60])-\u003eget();\n```\n\n\u003e **Note**\n\u003e All filters added are grouped as \"AND\" filters, and applied together. Optional \"OR\" grouping is not yet supported.\n\n#### Searching common properties\n\nHubSpot supports searching through certain object properties very easily. See here for details:\n\n[https://developers.hubspot.com/docs/api/crm/search#search-default-searchable-properties](https://developers.hubspot.com/docs/api/crm/search#search-default-searchable-properties)\n\nSpecify a search parameter with the `search` method:\n\n```php\nContact::search('1234')-\u003eget();\n```\n\n#### Ordering\n\nYou can order the results with any property.\n\n```php\nContact::orderBy('lastname')-\u003eget();\n```\n\nThe default direction is `asc`, you can change this to `desc` if needed.\n\n```php\nContact::orderBy('days_to_close', 'desc')-\u003eget();\n```\n\n### Associations\n\nHubSpot associations are handled similar to Eloquent relationships.\n\n#### Dynamic properties\n\nYou can access associated objects using dynamic properties.\n\n```php\nforeach(Company::find(555)-\u003econtacts AS $contact) {\n    echo $contact-\u003eemail;\n}\n```\n\n#### Association methods\n\nIf you need to add additional constraints, use the association method. You can add any of the filtering, searching, or ordering methods described above.\n\n```php\nCompany::find(555)-\u003econtacts()\n    -\u003ewhere('days_to_close', 'BETWEEN', [30, 60])\n    -\u003esearch('smith')\n    -\u003eget();\n```\n\n#### Eager loading association IDs\n\nNormally, there are three HubSpot API calls to achieve the above result:\n\n1. Fetch the company object\n2. Retrieve all the contact IDs that are associated to this company\n3. Query for contacts that match the IDs\n\nNow we can eliminate the second API call by eager loading the associated contact IDs.\nThis library always eager-loads the IDs for associated companies, contacts, deals, and tickets. It does not eager-load\nIDs for engagements like emails and notes, since those association will tend to be much longer lists.\n\nIf you know in advance that you want to, say, retrieve the notes for a contact, you can specify this up front.\n\n```php\n// This will only be two API calls, not three\nContact::with('notes')-\u003efind(123)-\u003enotes;\n```\n\n#### Creating associated objects\n\nYou can create new records off of the association methods.\n\n```php\nCompany::find(555)-\u003econtacts()-\u003ecreate([\n    'firstname' =\u003e 'Test',\n    'lastname' =\u003e 'User',\n    'email' =\u003e 'testuser@example.com'\n]);\n```\n\nThis will create a new contact, associate it to the company, and return the new contact.\n\nYou can also associate existing objects using `attach`. This method accepts and ID or an object instance.\n\n```php\nCompany::find(555)-\u003econtacts()-\u003eattach(Contact::find(123));\n```\n\nYou can also detach existing objects using `detach`. This method accepts and ID or an object instance.\n\n```php\nCompany::find(555)-\u003econtacts()-\u003edetach(Contact::find(123));\n```\n\n\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstechstudio%2Flaravel-hubspot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstechstudio%2Flaravel-hubspot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstechstudio%2Flaravel-hubspot/lists"}