{"id":16362502,"url":"https://github.com/colorfield/civicrm_tools","last_synced_at":"2026-04-20T14:03:38.320Z","repository":{"id":150261336,"uuid":"130717742","full_name":"colorfield/civicrm_tools","owner":"colorfield","description":"CiviCRM API wrapper and helpers for Drupal 8","archived":false,"fork":false,"pushed_at":"2020-08-12T08:13:45.000Z","size":27,"stargazers_count":0,"open_issues_count":1,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-07T13:37:40.070Z","etag":null,"topics":["civicrm","civicrm-api-wrapper","drupal","drupal-8"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/colorfield.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2018-04-23T15:26:58.000Z","updated_at":"2018-10-16T08:34:19.000Z","dependencies_parsed_at":null,"dependency_job_id":"6a52d093-7687-4ea0-849e-3ad1ab473d31","html_url":"https://github.com/colorfield/civicrm_tools","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/colorfield/civicrm_tools","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/colorfield%2Fcivicrm_tools","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/colorfield%2Fcivicrm_tools/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/colorfield%2Fcivicrm_tools/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/colorfield%2Fcivicrm_tools/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/colorfield","download_url":"https://codeload.github.com/colorfield/civicrm_tools/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/colorfield%2Fcivicrm_tools/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32050454,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-20T11:35:06.609Z","status":"ssl_error","status_checked_at":"2026-04-20T11:34:48.899Z","response_time":94,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["civicrm","civicrm-api-wrapper","drupal","drupal-8"],"created_at":"2024-10-11T02:24:27.688Z","updated_at":"2026-04-20T14:03:38.281Z","avatar_url":"https://github.com/colorfield.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CiviCRM Tools\n\nCiviCRM API wrapper for Drupal 8.\nThe wrapper is currently being extended by syntactic sugar and REST helpers.\n\nThe API code is originally extracted from the \n[CiviCRM Entity](http://drupal.org/project/civicrm_entity) module.\nIt has started as a separation of concern and is subject to evolve by  \n- implementing other methods like _clone_, _getTokens_, _getSingle_, ...\n- defining API version (currently v3)\n- providing pagination helpers\n- providing syntactic sugar over the API for complex relations\n- providing default exception handlers.\n\n## Dependencies\n\n[CiviCRM Core](https://github.com/civicrm/civicrm-core/tree/5.6) \nand [CiviCRM Drupal 8](https://github.com/civicrm/civicrm-drupal-8/tree/5.7) module.\n\nDue to the current development of CiviCRM for Drupal, these packages are \nnot currently required by Composer so you have to install them manually with your\npreferred setup.\n\nHere is [one possible setup](https://colorfield.be/blog/install-civicrm-56x-drupal-86x)\nthat has been used during the development of this module.\n\n## API Documentation\n\nThe API is available as a Drupal service.\n\n```\n// Prefer dependency injection.\n$civiCrmApi = \\Drupal::service('civicrm_tools.api');\n```\n\n### Get \n\n```\n$params = [\n  'email' =\u003e 'donald@example.com',\n];\n$result = $civiCrmApi-\u003eget('Contact', $params);\n```\n\n### Create\n\n```\n$params = [\n  'first_name' =\u003e 'Elijah',\n  'last_name' =\u003e 'Baley',\n  'contact_type' =\u003e 'Individual',\n]\n$result = $civiCrmApi-\u003ecreate('Contact', $params);\n```\n\n### Delete\n\n```\n$params = [\n  'id' =\u003e 42,\n];\n$result = $civiCrmApi-\u003edelete('Contact', $params);\n```\n\n## Syntactic sugar\n\nSome other services are on their way.\n\n### Contact\n\n```\n// Prefer dependency injection.\n$civiCrmContact = \\Drupal::service('civicrm_tools.contact');\n// Smart group id and optinal parameters\n$civiCrmContact-\u003egetFromSmartGroup(42, []);\n$civiCrmContact-\u003egetFromGroups([1,2]);\n// User id and domain id\n$civiCrmContact-\u003egetFromUserId(1, 1);\n// Domain id\n$civiCrmContact-\u003egetFromLoggedInUser(1);\n// Contact id and domain id\n$civiCrmContact-\u003egetUserFromContactId(1, 1);\n```\n\n### Group\n\n```\n// Prefer dependency injection.\n$civiCrmGroup = \\Drupal::service('civicrm_tools.group');\n// Contact id, load: get the full group array or only the group id\n$civiCrmGroup-\u003egetGroupsFromContact(1, TRUE);\n```\n\n### Database\n\nPrerequisite: add the CiviCRM database reference in your Drupal _settings.php_\n\n```\n$databases['civicrm']['default'] = array (\n  'database' =\u003e 'civicrm_db_name',\n  'username' =\u003e 'civicrm_db_user',\n  'password' =\u003e 'civicrm_db_password',\n  'prefix' =\u003e '',\n  'host' =\u003e '127.0.0.1',\n  'port' =\u003e '3306',\n  'namespace' =\u003e 'Drupal\\\\Core\\\\Database\\\\Driver\\\\mysql',\n  'driver' =\u003e 'mysql',\n);\n```\n\nThen\n\n```\n// Prefer dependency injection.\n$civiCrmDatabase = \\Drupal::service('civicrm_tools.database');\n$query = 'SELECT * FROM {civicrm_log}';\n$result = $civiCrmDatabase-\u003eexecute($query);\n```\n\nOr\n\n```\n// Switch to a custom CiviCRM database.\nDatabase::setActiveConnection('civicrm');\n$db = Database::getConnection();\n$query = $db-\u003equery(\"SELECT group_id FROM {civicrm_group_contact} WHERE contact_id = :contact_id AND status = :status\", [\n  ':contact_id' =\u003e $contact_id,\n  ':status' =\u003e 'Added',\n]);\n$queryResult = $query-\u003efetchAll();\n// Switch back to the default database (Drupal).\nDatabase::setActiveConnection();\n```\n\n\n## Expose CiviCRM and Drupal related entities via REST\n\nThe _CiviCRM Tools REST_ sub module aims to provide several endpoints for \nCiviCRM and Drupal entities.\nIt could also make use of entity Normalizer, ... to provide fields for JSON API, and core REST.\n\nCurrently, the only available endpoint gets Drupal users by CiviCRM group.\n\nPossible use cases:\n\n- a callback for a Single Sign On application, that provides a set of permissions based on the CiviCRM Group.\n- a decoupled application\n- ...\n\n### Get Drupal users by CiviCRM group\n\n**/api/civicrm_tools/users/group/{group_id}**\n\nAuthenticate with BasicAuth.\nThe authenticated user needs the permission to view user profiles.\n\nUsage\n\n```\ncurl --include --request GET --user admin:admin --header 'Content-type: application/json' http://example.com/api/civicrm_tools/users/group/42\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcolorfield%2Fcivicrm_tools","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcolorfield%2Fcivicrm_tools","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcolorfield%2Fcivicrm_tools/lists"}