{"id":18298728,"url":"https://github.com/fusionauth/fusionauth-php-client","last_synced_at":"2025-08-04T06:15:30.736Z","repository":{"id":41142893,"uuid":"146031298","full_name":"FusionAuth/fusionauth-php-client","owner":"FusionAuth","description":"PHP client library for FusionAuth","archived":false,"fork":false,"pushed_at":"2025-03-31T22:28:11.000Z","size":565,"stargazers_count":22,"open_issues_count":8,"forks_count":11,"subscribers_count":11,"default_branch":"develop","last_synced_at":"2025-04-01T16:56:44.198Z","etag":null,"topics":["api-client","fusionauth","fusionauth-client","php","php-client","rest-client"],"latest_commit_sha":null,"homepage":"https://fusionauth.io","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/FusionAuth.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-08-24T19:21:26.000Z","updated_at":"2025-03-27T20:48:03.000Z","dependencies_parsed_at":"2024-04-25T23:50:27.127Z","dependency_job_id":"77acc8bb-a448-4437-b88d-66e0b27f5a43","html_url":"https://github.com/FusionAuth/fusionauth-php-client","commit_stats":{"total_commits":268,"total_committers":13,"mean_commits":"20.615384615384617","dds":0.3097014925373134,"last_synced_commit":"92c14181ff519b30022483b9328a7adb4edf0d1e"},"previous_names":[],"tags_count":180,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FusionAuth%2Ffusionauth-php-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FusionAuth%2Ffusionauth-php-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FusionAuth%2Ffusionauth-php-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FusionAuth%2Ffusionauth-php-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/FusionAuth","download_url":"https://codeload.github.com/FusionAuth/fusionauth-php-client/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247345850,"owners_count":20924102,"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":["api-client","fusionauth","fusionauth-client","php","php-client","rest-client"],"created_at":"2024-11-05T15:06:50.317Z","updated_at":"2025-04-05T14:03:48.345Z","avatar_url":"https://github.com/FusionAuth.png","language":"PHP","readme":"# FusionAuth PHP Client ![semver 2.0.0 compliant](http://img.shields.io/badge/semver-2.0.0-brightgreen.svg?style=flat-square)\n\n## Intro\n\n\u003c!--\ntag::forDocSite[]\n--\u003e\n\nIf you're integrating FusionAuth with a PHP application, this library will speed up your development time. Please also make sure to check our [SDK Usage Suggestions  page](https://fusionauth.io/docs/sdks/#usage-suggestions).\n\nFor additional information and documentation on FusionAuth refer to [https://fusionauth.io](https://fusionauth.io).\n\n## Install\n\nThe most preferred way to use the client library is to install the [`fusionauth/fusionauth-client`](https://packagist.org/packages/fusionauth/fusionauth-client) package via Composer by running the command below at your project root folder.\n\n```bash\ncomposer require fusionauth/fusionauth-client\n```\n\nThen, include the `composer` autoloader in your PHP files.\n\n```php\nrequire __DIR__ . '/vendor/autoload.php';\n```\n\n## Examples\n\n### Set Up\n\nFirst, you have to make sure you have a running FusionAuth instance. If you don't have one already, the easiest way to install FusionAuth is [via Docker](https://fusionauth.io/docs/get-started/download-and-install/docker), but there are [other ways](https://fusionauth.io/docs/get-started/download-and-install). By default, it'll be running on `localhost:9011`.\n\nThen, you have to [create an API Key](https://fusionauth.io/docs/apis/authentication#managing-api-keys) in the admin UI to allow calling API endpoints.\n\nYou are now ready to use this library!\n\n### Error Handling\n\nAfter every request is made, you need to check for any errors and handle them. To avoid cluttering things up, we'll omit the error handling in the next examples, but you should do something like the following.\n\n```php\n// $result is the response of one of the endpoint invocations from the examples below\n\nif (!$result-\u003ewasSuccessful()) {\n    echo \"Error!\" . PHP_EOL;\n    echo \"Got HTTP {$result-\u003estatus}\" . PHP_EOL;\n    if (isset($result-\u003eerrorResponse-\u003efieldErrors)) {\n        echo \"There are some errors with the payload:\" . PHP_EOL;\n        var_dump($result-\u003eerrorResponse-\u003efieldErrors);\n    }\n    if (isset($result-\u003eerrorResponse-\u003egeneralErrors)) {\n        echo \"There are some general errors:\" . PHP_EOL;\n        var_dump($result-\u003eerrorResponse-\u003egeneralErrors);\n    }\n}\n```\n\n### Create the Client\n\nTo make requests to the API, first you need to create a `FusionAuthClient` instance with [the API Key created](https://fusionauth.io/docs/apis/authentication#managing-api-keys) and the server address where FusionAuth is running.\n\n```php\n$client = new FusionAuth\\FusionAuthClient(\n    apiKey: \"\u003cpaste the API Key you generated here\u003e\",\n    baseURL: \"http://localhost:9011\", // or change this to whatever address FusionAuth is running on\n);\n```\n\n### Create an Application\n\nTo create an [Application](https://fusionauth.io/docs/get-started/core-concepts/applications), use the `createApplication()` method.\n\n```php\n$result = $client-\u003ecreateApplication(\n    applicationId: null, // Leave this empty to automatically generate the UUID\n    request: [\n        'application' =\u003e [\n            'name' =\u003e 'ChangeBank',\n        ],\n    ],\n);\n\n// Handle errors as shown in the beginning of the Examples section\n\n// Otherwise parse the successful response\nvar_dump($result-\u003esuccessResponse-\u003eapplication);\n```\n\n[Check the API docs for this endpoint](https://fusionauth.io/docs/apis/applications#create-an-application)\n\n### Adding Roles to an Existing Application\n\nTo add [roles to an Application](https://fusionauth.io/docs/get-started/core-concepts/applications#roles), use `createApplicationRole()`.  \n\n```php\n$result = $client-\u003ecreateApplicationRole(\n    applicationId: 'd564255e-f767-466b-860d-6dcb63afe4cc', // Existing Application Id\n    roleId: null, // Leave this empty to automatically generate the UUID\n    request: [\n        'role' =\u003e [\n            'name' =\u003e 'customer',\n            'description' =\u003e 'Default role for regular customers',\n            'isDefault' =\u003e true,\n        ],\n    ],\n);\n\n// Handle errors as shown in the beginning of the Examples section\n\n// Otherwise parse the successful response\nvar_dump($result-\u003esuccessResponse-\u003erole);\n```\n\n[Check the API docs for this endpoint](https://fusionauth.io/docs/apis/applications#create-an-application-role)\n\n### Retrieve Application Details\n\nTo fetch details about an [Application](https://fusionauth.io/docs/get-started/core-concepts/applications), use `retrieveApplication()`. \n\n```php\n$result = $client-\u003eretrieveApplication(\n    applicationId: 'd564255e-f767-466b-860d-6dcb63afe4cc',\n);\n\n// Handle errors as shown in the beginning of the Examples section\n\n// Otherwise parse the successful response\nvar_dump($result-\u003esuccessResponse-\u003eapplication);\n```\n\n[Check the API docs for this endpoint](https://fusionauth.io/docs/apis/applications#retrieve-an-application)\n\n### Delete an Application\n\nTo delete an [Application](https://fusionauth.io/docs/get-started/core-concepts/applications), use `deleteApplication()`.\n\n```php\n$result = $client-\u003edeleteApplication(\n    applicationId: 'd564255e-f767-466b-860d-6dcb63afe4cc',\n);\n\n// Handle errors as shown in the beginning of the Examples section\n\n// Otherwise parse the successful response\n// Note that $result-\u003esuccessResponse will be empty\n```\n\n[Check the API docs for this endpoint](https://fusionauth.io/docs/apis/applications#delete-an-application)\n\n### Lock a User\n\nTo [prevent a User from logging in](https://fusionauth.io/docs/get-started/core-concepts/users), use `deactivateUser()`. \n\n```php\n$result = $client-\u003edeactivateUser(\n    'fa0bc822-793e-45ee-a7f4-04bfb6a28199',\n);\n\n// Handle errors as shown in the beginning of the Examples section\n\n// Otherwise parse the successful response\n```\n\n[Check the API docs for this endpoint](https://fusionauth.io/docs/apis/users#delete-a-user)\n\n### Registering a User\n\nTo [register a User in an Application](https://fusionauth.io/docs/get-started/core-concepts/users#registrations), use `register()`.\n\nThe code below also adds a `customer` role and a custom `appBackgroundColor` property to the User Registration.\n\n```php\n$result = $client-\u003eregister(\n    userId: 'fa0bc822-793e-45ee-a7f4-04bfb6a28199',\n    request: [\n        'registration' =\u003e [\n            'applicationId' =\u003e 'd564255e-f767-466b-860d-6dcb63afe4cc',\n            'roles' =\u003e [\n                'customer',\n            ],\n            'data' =\u003e [\n                'appBackgroundColor' =\u003e '#096324',\n            ],\n        ],    \n    ],\n);\n\n// Handle errors as shown in the beginning of the Examples section\n\n// Otherwise parse the successful response\n```\n\n[Check the API docs for this endpoint](https://fusionauth.io/docs/apis/registrations#create-a-user-registration-for-an-existing-user)\n\n\u003c!--\nend::forDocSite[]\n--\u003e\n\n## Questions and support\n\nIf you find any bugs in this library, [please open an issue](https://github.com/FusionAuth/fusionauth-php-client/issues). Note that changes to the `FusionAuthClient` class have to be done on the [FusionAuth Client Builder repository](https://github.com/FusionAuth/fusionauth-client-builder/blob/master/src/main/client/php.client.ftl), which is responsible for generating that file.\n\nBut if you have a question or support issue, we'd love to hear from you.\n\nIf you have a paid plan with support included, please [open a ticket in your account portal](https://account.fusionauth.io/account/support/). Learn more about [paid plan here](https://fusionauth.io/pricing).\n\nOtherwise, please [post your question in the community forum](https://fusionauth.io/community/forum/).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/FusionAuth/fusionauth-php-client.\n\nNote: if you want to change the `FusionAuthClient` class, you have to do it on the [FusionAuth Client Builder repository](https://github.com/FusionAuth/fusionauth-client-builder/blob/master/src/main/client/php.client.ftl), which is responsible for generating all client libraries we support.\n\n## License\n\nThis code is available as open source under the terms of the [Apache v2.0 License](https://opensource.org/blog/license/apache-2-0).\n\n\n## Upgrade Policy\n\nThis library is built automatically to keep track of the FusionAuth API, and may also receive updates with bug fixes, security patches, tests, code samples, or documentation changes.\n\nThese releases may also update dependencies, language engines, and operating systems, as we\\'ll follow the deprecation and sunsetting policies of the underlying technologies that it uses.\n\nThis means that after a dependency (e.g. language, framework, or operating system) is deprecated by its maintainer, this library will also be deprecated by us, and will eventually be updated to use a newer version.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffusionauth%2Ffusionauth-php-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffusionauth%2Ffusionauth-php-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffusionauth%2Ffusionauth-php-client/lists"}