{"id":20961727,"url":"https://github.com/heimrichhannot/contao-api-bundle","last_synced_at":"2025-05-14T07:30:58.149Z","repository":{"id":62515419,"uuid":"148169055","full_name":"heimrichhannot/contao-api-bundle","owner":"heimrichhannot","description":"API to access (restricted) contao privacy module from 3rd-party applications","archived":false,"fork":false,"pushed_at":"2023-07-18T06:52:20.000Z","size":164,"stargazers_count":5,"open_issues_count":3,"forks_count":12,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-19T06:05:18.472Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/heimrichhannot.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-09-10T14:34:52.000Z","updated_at":"2022-11-28T09:08:31.000Z","dependencies_parsed_at":"2023-01-22T15:45:27.140Z","dependency_job_id":null,"html_url":"https://github.com/heimrichhannot/contao-api-bundle","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heimrichhannot%2Fcontao-api-bundle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heimrichhannot%2Fcontao-api-bundle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heimrichhannot%2Fcontao-api-bundle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heimrichhannot%2Fcontao-api-bundle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/heimrichhannot","download_url":"https://codeload.github.com/heimrichhannot/contao-api-bundle/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254094827,"owners_count":22013648,"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-11-19T02:16:01.028Z","updated_at":"2025-05-14T07:30:57.102Z","avatar_url":"https://github.com/heimrichhannot.png","language":"PHP","readme":"# Contao api bundle\n\n[![](https://img.shields.io/packagist/v/heimrichhannot/contao-api-bundle.svg)](https://packagist.org/packages/heimrichhannot/contao-api-bundle)\n[![](https://img.shields.io/packagist/dt/heimrichhannot/contao-api-bundle.svg)](https://packagist.org/packages/heimrichhannot/contao-api-bundle/stats)\n[![](https://img.shields.io/travis/heimrichhannot/contao-api-bundle/master.svg)](https://travis-ci.org/heimrichhannot/contao-api-bundle/)\n[![](https://img.shields.io/coveralls/heimrichhannot/contao-api-bundle/master.svg)](https://coveralls.io/github/heimrichhannot/contao-api-bundle)\n\nA generic API with restricted access to provide access to 3rd party applications.\n\n## Login `/api/login/member` or `api/login/user`\n\nLogin is done via symfony `guard` authenticator in combination with contao members `tl_member` or users `tl_user`.\nAfter successful login a volatile token (default: `24 hours`) will be returned that is used for any api and must be provided within request headers `Authorization: Bearer {{token}}`;\n\n```\n# test login (with contao front end member)\ncurl --user username:password -H \"Content-Type: application/json\" -X POST http://domain.tld/api/login/member\n\n# example response on success\n{\n    \"token\": \"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VybmXtZSI6ImRpZ2l0YWxlc0BoZWltcmljaA1oYW5ub3QuZGUiLCJpYXQiOjE1MzY4NTYwMDMsImV4cCI6MTUzNjk0MjQwM30.trp-1NgYgXGfHYdE3dlQ8awE8aXUWL-RfBQyfWm2Hz0\"\n}\n\n# test login (with contao back end member)\ncurl --user username:password -H \"Content-Type: application/json\" -X POST http://domain.tld/api/login/user\n\n# example response on success\n{\n    \"token\": \"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VybmXtZSI6ImRpZ2l0YWxlc0BoZWltcmljaA1oYW5ub3QuZGUiLCJpYXQiOjE1MzY4NTYwMDMsImV4cCI6MTUzNjk0MjQwM30.trp-1NgYgXGfHYdE3dlQ8awE8aXUWL-RfBQyfWm2Hz0\"\n}\n```\n\n## Create an app with an custom api key \n\nVisit your contao backend at `http://domain.tld/contao?do=api_apps` and create your first app.\nAccess can be restricted for member or user groups. Admin users `tl_user` will have access to every api by default.\nFor each request beside the login routes you must provide the generated API `key` as `GET` Parameter.\n\n## Resource /api/resource/{resource_alias}\n\nTo add your custom resource, simply add an service within your bundles or app `services.yml`:\n\n```\nservices:\n\tmy.api.resource.my_resource:\n\t\tclass: MyApi\\Resource\\MyResource\n\t\targuments:\n              - \"my_resource\"\n\t\ttags:\n\t\t- { name: huh.api.resource, alias: my_resource}\n```\n\nAnd register your resource configuration within your bundles or app `config.yml`:\n\n```\nhuh:\n  api:\n    resources:\n      - {name: my_resource, type: entity_resource, modelClass: \"MyResourceModel\", verboseName: my_resource}\n```\n\nTo get your `config.yml` loaded properly, your `Plugin` class must implement the interface `Contao\\ManagerPlugin\\Config\\ExtensionPluginInterface`:\n\n```\nnamespace MyApi\\ContaoManager;\n\nuse Contao\\ManagerPlugin\\Config\\ContainerBuilder;\nuse Contao\\ManagerPlugin\\Config\\ExtensionPluginInterface;\nuse HeimrichHannot\\UtilsBundle\\Container\\ContainerUtil;\n\nclass Plugin implements ExtensionPluginInterface\n{\n\n    /**\n     * {@inheritdoc}\n     */\n    public function getExtensionConfig($extensionName, array $extensionConfigs, ContainerBuilder $container)\n    {\n        return ContainerUtil::mergeConfigFile(\n            'huh_api',\n            $extensionName,\n            $extensionConfigs,\n            __DIR__.'/../Resources/config/config.yml'\n        );\n    }\n```\n\n**Do not forget to clear the symfony cache afterwards!**\n\nNow you are able to access your resource through `/api/resource/my_resource`.\n\n```\n# test access to my_resource (provide your token from user or member login and your api key)\ncurl --header \"Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VybmXtZSI6ImRpZ2l0YWxlc0BoZWltcmljaA1oYW5ub3QuZGUiLCJpYXQiOjE1MzY4NTYwMDMsImV4cCI6MTUzNjk0MjQwM30.trp-1NgYgXGfHYdE3dlQ8awE8aXUWL-RfBQyfWm2Hz0\" -H \"Content-Type: application/json\" -X GET http://domain.tld/api/resource/my_resource?key=\u003capi-key\u003e\n```\n\nNow you are able to access crud functionality by using the related `HTTP method`:\n\n| Path | HTTP-Method | Resource-Method (Mapping) |\n|---|---|---|\n| /api/resource/my_resource | POST | create() new resource |\n| /api/resource/my_resource/23  | PUT | update() existing resource with id 23 |\n| /api/resource/my_resource  | GET | list() all resources  |\n| /api/resource/my_resource/23  | GET | show() existing resource with id 23 |\n| /api/resource/my_resource/23  | DELETE | delete() existing resource with id 23 |\n\n```\n# test create() new resource\ncurl --header \"Authorization: Bearer \u003clogin-token\u003e\" -H \"Content-Type: application/json\" -X POST -d \"{\"title\":\"My test title\", \"published\":true}\" http://domain.tld/api/resource/my_resource?key=\u003capi-key\u003e\n```\n\n``` \n# test update() existing resource\ncurl --header \"Authorization: Bearer \u003clogin-token\u003e\" -H \"Content-Type: application/json\" -X PUT -d \"{\"title\":\"My new test title\", \"published\":false}\" http://domain.tld/api/resource/my_resource/23?key=\u003capi-key\u003e\n```\n\n```\n# test list() all resources\ncurl --header \"Authorization: Bearer \u003clogin-token\u003e\" -H \"Content-Type: application/json\" -X GET http://domain.tld/api/resource/my_resource?key=\u003capi-key\u003e\n```\n\n```\n# test show() existing resource\ncurl --header \"Authorization: Bearer \u003clogin-token\u003e\" -H \"Content-Type: application/json\" -X GET http://domain.tld/api/resource/my_resource/23?key=\u003capi-key\u003e\n```\n\n```\n# test delete() existing resource\ncurl --header \"Authorization: Bearer \u003clogin-token\u003e\" -H \"Content-Type: application/json\" -X DELETE http://domain.tld/api/resource/my_resource/23?key=\u003capi-key\u003e\n```\n\n### Available Resources\n\n#### Service: huh.api.resource.member \n\nSkeleton resource that provides simple crud functionality with contao member (tl_member) entity \n\n| Path | HTTP-Method | Resource-Method (Mapping) | Additional GET Parameters\n|---|---|---|---|\n| /api/resource/member | POST | create() new member | - |\n| /api/resource/member/23  | PUT | update() existing member with id 23 |- |\n| /api/resource/member  | GET | list() all member  | limit, offset |\n| /api/resource/member/23  | GET | show() existing member with id 23 | - |\n| /api/resource/member/23  | DELETE | delete() existing member with id 23 | - |\n\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fheimrichhannot%2Fcontao-api-bundle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fheimrichhannot%2Fcontao-api-bundle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fheimrichhannot%2Fcontao-api-bundle/lists"}