{"id":18695340,"url":"https://github.com/smartthingscommunity/api-app-minimal-example-js","last_synced_at":"2025-07-18T00:07:31.161Z","repository":{"id":42178766,"uuid":"215105931","full_name":"SmartThingsCommunity/api-app-minimal-example-js","owner":"SmartThingsCommunity","description":"Simple API Access integration that allows scenes to be executed","archived":false,"fork":false,"pushed_at":"2024-09-03T15:32:47.000Z","size":590,"stargazers_count":9,"open_issues_count":1,"forks_count":8,"subscribers_count":71,"default_branch":"master","last_synced_at":"2025-04-12T07:37:15.357Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/SmartThingsCommunity.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,"zenodo":null}},"created_at":"2019-10-14T17:32:02.000Z","updated_at":"2025-01-24T02:44:55.000Z","dependencies_parsed_at":"2025-04-12T07:29:47.790Z","dependency_job_id":"410dfa88-2a5a-482e-85cd-249e384780aa","html_url":"https://github.com/SmartThingsCommunity/api-app-minimal-example-js","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/SmartThingsCommunity/api-app-minimal-example-js","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SmartThingsCommunity%2Fapi-app-minimal-example-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SmartThingsCommunity%2Fapi-app-minimal-example-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SmartThingsCommunity%2Fapi-app-minimal-example-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SmartThingsCommunity%2Fapi-app-minimal-example-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SmartThingsCommunity","download_url":"https://codeload.github.com/SmartThingsCommunity/api-app-minimal-example-js/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SmartThingsCommunity%2Fapi-app-minimal-example-js/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265683332,"owners_count":23810832,"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-07T11:14:40.663Z","updated_at":"2025-07-18T00:07:31.139Z","avatar_url":"https://github.com/SmartThingsCommunity.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Simple API Access App Example\n\n## Overview\n\nThis simple NodeJS Express app illustrates how to create an _API Access_ SmartApp that connects to your SmartThings\naccount with OAuth2 and allows you to execute manually run routines (which are called \"scenes\" in the API). \nIt's a very simple app that stores the access and refresh tokens in session state. It uses the \n[express-session](https://www.npmjs.com/package/express-session#compatible-session-stores) in-memory session store, \nso you will lose your session data\nwhen you restart the server, but you can use another \n[compatible session store](https://www.npmjs.com/package/express-session#compatible-session-stores)\nto make the session persist between server\nrestarts. This example uses the \n[@SmartThings/SmartApp](https://www.npmjs.com/package/@smartthings/smartapp) SDK NPM module for making the\nAPI calls to list and execute scenes.\n\n## Files and directories \n\n- public\n  - stylesheets -- stylesheets used by the web pages\n- views\n  - error.ejs -- error page\n  - index.ejs -- initial page with link to connect to SmartThings\n  - scenes.ejs -- page that displays scenes and allows them to be executed\n- server.js -- the Express server and SmartApp\n- .env -- file you create with app client ID and client secret\n\n## Getting Started\n\n### Prerequisites\n- A [SmartThings](https://smartthings.com) account with at least one location and manually run routines created\n\n- The [SmartThings CLI](https://github.com/SmartThingsCommunity/smartthings-cli#readme) installed on your computer\n\n- [Node.js](https://nodejs.org/en/) and [npm](https://www.npmjs.com/) installed on your computer\n\n## Instructions\n\n### 1. Clone [this GitHub repository](https://github.com/SmartThingsCommunity/api-app-minimal-example-js), cd into the directory, and install the Node modules with NPM:\n```$bash\ngit clone https://github.com/SmartThingsCommunity/api-app-minimal-example-js.git\ncd api-app-minimal-example-js\nnpm install\n```\n\n### 2. Register your app with SmartThings using the CLI\n\nStart with the `smartthings apps:create` command to create a new app. You will be prompted for the required\ninformation. The following is an example of the output from the command:\n\n```bash\n~ % smartthings apps:create\n? What kind of app do you want to create? (Currently, only OAuth-In apps are supported.) OAuth-In App\n\nMore information on writing SmartApps can be found at\n  https://developer.smartthings.com/docs/connected-services/smartapp-basics\n\n? Display Name My API App\n? Description Allows scenes to be executed\n? Icon Image URL (optional) \n? Target URL (optional) \n\nMore information on OAuth 2 Scopes can be found at:\n  https://www.oauth.com/oauth2-servers/scope/\n\nTo determine which scopes you need for the application, see documentation for the individual endpoints you will use in your app:\n  https://developer.smartthings.com/docs/api/public/\n\n? Select Scopes. r:locations:*, r:scenes:*, x:scenes:*\n? Add or edit Redirect URIs. Add Redirect URI.\n? Redirect URI (? for help) http://localhost:3000/oauth/callback\n? Add or edit Redirect URIs. Finish editing Redirect URIs.\n? Choose an action. Finish and create OAuth-In SmartApp.\nBasic App Data:\n─────────────────────────────────────────────────────────────────\n Display Name     My API App                                     \n App Id           037bcd6c-xxxx-xxxx-xxxx-xxxxxxxxxxxx           \n App Name         amyapiapp-a8b20801-xxxx-xxxx-xxxx-xxxxxxxxxxxx \n Description      Allows scenes to be executed                   \n Single Instance  true                                           \n Classifications  CONNECTED_SERVICE                              \n App Type         API_ONLY                                       \n─────────────────────────────────────────────────────────────────\n\n\nOAuth Info (you will not be able to see the OAuth info again so please save it now!):\n───────────────────────────────────────────────────────────\n OAuth Client Id      689f9823-xxxx-xxxx-xxxx-xxxxxxxxxxxx \n OAuth Client Secret  3a2c39d8-xxxx-xxxx-xxxx-xxxxxxxxxxxx \n───────────────────────────────────────────────────────────\n````\n\n### 3. Create a `.env` file in the root directory of the project\n\nAdd the `PORT`, `SERVER_URL`, `APP_ID`, `CLIENT_ID`, and `CLIENT_SECRET` properties from the output of the `smartthings apps:create` command. For example:\n\n```$bash\nPORT=3000\nSERVER_URL=http://localhost:3000\nAPP_ID=037bcd6c-xxxx-xxxx-xxxx-xxxxxxxxxxxx\nCLIENT_ID=689f9823-xxxx-xxxx-xxxx-xxxxxxxxxxxx\nCLIENT_SECRET=3a2c39d8-xxxx-xxxx-xxxx-xxxxxxxxxxxx \n```\n\n### 4. Start your server:\n```$bash\nnode server.js\n```\n\n### 5. Connect your app to SmartThings\n\nGo to http://localhost:3000, log in with your SmartThings account credentials, and \nchoose a location. You should see a page with the location name as a header and button for \neach scene in that location. Clicking the button should execute the scene. If you don't see\nany buttons you may need to create some scenes using the SmartThings mobile app.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmartthingscommunity%2Fapi-app-minimal-example-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsmartthingscommunity%2Fapi-app-minimal-example-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmartthingscommunity%2Fapi-app-minimal-example-js/lists"}