{"id":18174589,"url":"https://github.com/JamesIves/fetch-api-data-action","last_synced_at":"2025-04-01T15:31:52.832Z","repository":{"id":37820929,"uuid":"245163432","full_name":"JamesIves/fetch-api-data-action","owner":"JamesIves","description":"🚚  GitHub action for handling authenticated API requests, allowing you to save the data from the request into your workspace as an environment variable and a .json file.","archived":false,"fork":false,"pushed_at":"2025-03-10T11:18:21.000Z","size":35535,"stargazers_count":118,"open_issues_count":3,"forks_count":13,"subscribers_count":2,"default_branch":"dev","last_synced_at":"2025-03-19T18:43:05.451Z","etag":null,"topics":["action","actions","api","cicd","continuous-delivery","fetch","github-action","github-actions","github-actions-typescript","hacktoberfest","workflow","workflow-configuration"],"latest_commit_sha":null,"homepage":"https://github.com/marketplace/actions/fetch-api-data","language":"TypeScript","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/JamesIves.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["JamesIves"]}},"created_at":"2020-03-05T12:56:46.000Z","updated_at":"2025-03-13T07:21:07.000Z","dependencies_parsed_at":"2023-11-28T04:24:44.733Z","dependency_job_id":"c810eb6d-0511-4aff-83d6-380607691283","html_url":"https://github.com/JamesIves/fetch-api-data-action","commit_stats":{"total_commits":623,"total_committers":7,"mean_commits":89.0,"dds":0.5810593900481541,"last_synced_commit":"477a7ba13916cb011c00db4b9da88acb34da73d0"},"previous_names":[],"tags_count":30,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JamesIves%2Ffetch-api-data-action","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JamesIves%2Ffetch-api-data-action/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JamesIves%2Ffetch-api-data-action/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JamesIves%2Ffetch-api-data-action/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JamesIves","download_url":"https://codeload.github.com/JamesIves/fetch-api-data-action/tar.gz/refs/heads/dev","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245949640,"owners_count":20698924,"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":["action","actions","api","cicd","continuous-delivery","fetch","github-action","github-actions","github-actions-typescript","hacktoberfest","workflow","workflow-configuration"],"created_at":"2024-11-02T16:03:36.155Z","updated_at":"2025-04-01T15:31:52.818Z","avatar_url":"https://github.com/JamesIves.png","language":"TypeScript","readme":"\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://github.com/marketplace/actions/fetch-api-data\"\u003e\n    \u003cimg width=\"200px\" src=\"https://github.com/JamesIves/fetch-api-data-action/raw/dev/assets/icon.png\"\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\n\u003ch1 align=\"center\"\u003e\n  Fetch API Data Action 📦 🚚\n\u003c/h1\u003e\n\n\u003cp align=\"center\"\u003e\n  This \u003ca href=\"https://github.com/features/actions\"\u003eGitHub Action\u003c/a\u003e will handle authenticated API requests for you, allowing you to save the data from the request into your workspace as an environment variable and a file. Using this action will allow you to save data from these queries on a schedule so they can be used in a static page without exposing your API credentials. You can read more about the inspiration for this action \u003ca href=\"https://jamesiv.es/blog/github/actions/2020/03/07/fetching-authenticated-api-data/\"\u003ehere\u003c/a\u003e. \n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://github.com/JamesIves/fetch-api-data-action/raw/dev/assets/screenshot.png\"\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n  Maintenance of this project is made possible by all the \u003ca href=\"https://github.com/JamesIves/github-pages-deploy-action/graphs/contributors\"\u003econtributors\u003c/a\u003e and \u003ca href=\"https://github.com/sponsors/JamesIves\"\u003esponsors\u003c/a\u003e. If you'd like to sponsor this project and have your avatar or company logo appear below \u003ca href=\"https://github.com/sponsors/JamesIves\"\u003eclick here\u003c/a\u003e. 💖\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n\u003c!-- premium --\u003e\u003ca href=\"https://github.com/github\"\u003e\u003cimg src=\"https://github.com/github.png\" width=\"80px\" alt=\"github\" /\u003e\u003c/a\u003e\u0026nbsp;\u0026nbsp;\u003ca href=\"https://github.com/annegentle\"\u003e\u003cimg src=\"https://github.com/annegentle.png\" width=\"80px\" alt=\"annegentle\" /\u003e\u003c/a\u003e\u0026nbsp;\u0026nbsp;\u003ca href=\"https://github.com/tonjohn\"\u003e\u003cimg src=\"https://github.com/tonjohn.png\" width=\"80px\" alt=\"tonjohn\" /\u003e\u003c/a\u003e\u0026nbsp;\u0026nbsp;\u003c!-- premium --\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n\u003c!-- sponsors --\u003e\u003ca href=\"https://github.com/Chooksta69\"\u003e\u003cimg src=\"https://github.com/Chooksta69.png\" width=\"50px\" alt=\"Chooksta69\" /\u003e\u003c/a\u003e\u0026nbsp;\u0026nbsp;\u003ca href=\"https://github.com/MattWillFlood\"\u003e\u003cimg src=\"https://github.com/MattWillFlood.png\" width=\"50px\" alt=\"MattWillFlood\" /\u003e\u003c/a\u003e\u0026nbsp;\u0026nbsp;\u003ca href=\"https://github.com/jonathan-milan-pollock\"\u003e\u003cimg src=\"https://github.com/jonathan-milan-pollock.png\" width=\"50px\" alt=\"jonathan-milan-pollock\" /\u003e\u003c/a\u003e\u0026nbsp;\u0026nbsp;\u003ca href=\"https://github.com/raoulvdberge\"\u003e\u003cimg src=\"https://github.com/raoulvdberge.png\" width=\"50px\" alt=\"raoulvdberge\" /\u003e\u003c/a\u003e\u0026nbsp;\u0026nbsp;\u003ca href=\"https://github.com/robjtede\"\u003e\u003cimg src=\"https://github.com/robjtede.png\" width=\"50px\" alt=\"robjtede\" /\u003e\u003c/a\u003e\u0026nbsp;\u0026nbsp;\u003ca href=\"https://github.com/hadley\"\u003e\u003cimg src=\"https://github.com/hadley.png\" width=\"50px\" alt=\"hadley\" /\u003e\u003c/a\u003e\u0026nbsp;\u0026nbsp;\u003ca href=\"https://github.com/kevinchalet\"\u003e\u003cimg src=\"https://github.com/kevinchalet.png\" width=\"50px\" alt=\"kevinchalet\" /\u003e\u003c/a\u003e\u0026nbsp;\u0026nbsp;\u003ca href=\"https://github.com/Yousazoe\"\u003e\u003cimg src=\"https://github.com/Yousazoe.png\" width=\"50px\" alt=\"Yousazoe\" /\u003e\u003c/a\u003e\u0026nbsp;\u0026nbsp;\u003ca href=\"https://github.com/planetoftheweb\"\u003e\u003cimg src=\"https://github.com/planetoftheweb.png\" width=\"50px\" alt=\"planetoftheweb\" /\u003e\u003c/a\u003e\u0026nbsp;\u0026nbsp;\u003ca href=\"https://github.com/melton1968\"\u003e\u003cimg src=\"https://github.com/melton1968.png\" width=\"50px\" alt=\"melton1968\" /\u003e\u003c/a\u003e\u0026nbsp;\u0026nbsp;\u003ca href=\"https://github.com/szepeviktor\"\u003e\u003cimg src=\"https://github.com/szepeviktor.png\" width=\"50px\" alt=\"szepeviktor\" /\u003e\u003c/a\u003e\u0026nbsp;\u0026nbsp;\u003ca href=\"https://github.com/sckott\"\u003e\u003cimg src=\"https://github.com/sckott.png\" width=\"50px\" alt=\"sckott\" /\u003e\u003c/a\u003e\u0026nbsp;\u0026nbsp;\u003ca href=\"https://github.com/provinzkraut\"\u003e\u003cimg src=\"https://github.com/provinzkraut.png\" width=\"50px\" alt=\"provinzkraut\" /\u003e\u003c/a\u003e\u0026nbsp;\u0026nbsp;\u003ca href=\"https://github.com/electrovir\"\u003e\u003cimg src=\"https://github.com/electrovir.png\" width=\"50px\" alt=\"electrovir\" /\u003e\u003c/a\u003e\u0026nbsp;\u0026nbsp;\u003ca href=\"https://github.com/Griefed\"\u003e\u003cimg src=\"https://github.com/Griefed.png\" width=\"50px\" alt=\"Griefed\" /\u003e\u003c/a\u003e\u0026nbsp;\u0026nbsp;\u003ca href=\"https://github.com/MontezumaIves\"\u003e\u003cimg src=\"https://github.com/MontezumaIves.png\" width=\"50px\" alt=\"MontezumaIves\" /\u003e\u003c/a\u003e\u0026nbsp;\u0026nbsp;\u003ca href=\"https://github.com/wylie\"\u003e\u003cimg src=\"https://github.com/wylie.png\" width=\"50px\" alt=\"wylie\" /\u003e\u003c/a\u003e\u0026nbsp;\u0026nbsp;\u003ca href=\"https://github.com/pylapp\"\u003e\u003cimg src=\"https://github.com/pylapp.png\" width=\"50px\" alt=\"pylapp\" /\u003e\u003c/a\u003e\u0026nbsp;\u0026nbsp;\u003c!-- sponsors --\u003e\n\u003c/p\u003e\n\n## Getting Started ✈️\n\nYou can include the action in your workflow to trigger on any event that [GitHub actions supports](https://help.github.com/en/articles/events-that-trigger-workflows). You'll need to provide the action with the endpoint you'd like to request along with [any configuration options](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch) as [stringified JSON](https://www.w3schools.com/js/js_json_stringify.asp).\n\n```yml\nname: Refresh Feed\non: [push]\njobs:\n  refresh-feed:\n    runs-on: ubuntu-latest\n    steps:\n      - name: Fetch API Data 📦\n        uses: JamesIves/fetch-api-data-action@v2\n        with:\n          endpoint: https://example.com\n          configuration: '{ \"method\": \"GET\", \"headers\": {\"Authorization\": \"Bearer ${{ secrets.API_TOKEN }}\"} }'\n```\n\nOnce the action has run the requested data will be exported into the `fetch-api-data` environment variable and will also be available as a `.json` file in your workspace located by default in the `fetch-api-data-action/data.json` directory. If you need something other than `.json` file please refer to the `format` parameter.\n\nYou can combine the use of this with the [GitHub Pages Deploy Action](https://github.com/JamesIves/github-pages-deploy-action) to trigger scheduled updates to a feed on your website.\n\n\u003cdetails\u003e\n\u003csummary\u003eYou can view a full example of this here.\u003c/summary\u003e\n\nIn one workflow you can fetch data from an API on a schedule and push it to your `main` branch.\n\n```yml\nname: Refresh Feed\non:\n  schedule:\n    - cron: 10 15 * * 0-6\npermissions:\n  contents: write\njobs:\n  refresh-feed:\n    runs-on: ubuntu-latest\n    steps:\n      - name: Checkout 🛎️\n        uses: actions/checkout@v2\n        with:\n          persist-credentials: false\n\n      - name: Fetch API Data 📦\n        uses: JamesIves/fetch-api-data-action@v2\n        with:\n          endpoint: https://example.com\n          configuration: '{ \"method\": \"GET\", \"headers\": {\"Authorization\": \"Bearer ${{ secrets.API_TOKEN }}\"} }'\n\n      - name: Build and Deploy 🚀\n        uses: JamesIves/github-pages-deploy-action@v4\n        with:\n          branch: main # Pushes the updates to the main branch.\n          folder: fetch-api-data-action # The location of the data.json file saved by the Fetch API Data action.\n          target-folder: data # Saves the data into the 'data' directory on the main branch.\n```\n\nIn another workflow you can then build and deploy your page.\n\n```yml\nname: Build and Deploy\non:\n  schedule:\n    - cron: 10 16 * * 0-6\npermissions:\n  contents: write\njobs:\n  build-and-deploy:\n    runs-on: ubuntu-latest\n    steps:\n      - name: Checkout 🛎️\n        uses: actions/checkout@v2\n        with:\n          persist-credentials: false\n\n      - name: Install 🔧\n        run: |\n          npm install\n          npm run-script build\n\n      - name: Build and Deploy 🚀\n        uses: JamesIves/github-pages-deploy-action@v4\n        with:\n          branch: gh-pages\n          folder: build\n```\n\nIn your project you can import the JSON file and make it part of your build script. This way your site will re-build and deploy whenever refreshed data has been fetched from the server.\n\n\u003c/details\u003e\n\n#### Install as a Node Module 📦\n\nIf you'd like to use the functionality provided by this action in your own action you can either [create a composite action](https://docs.github.com/en/actions/creating-actions/creating-a-composite-action), or you can install it using [yarn](https://yarnpkg.com/) or [npm](https://www.npmjs.com/get-npm) by running the following commands. It's available on both the [npm](https://www.npmjs.com/package/@jamesives/fetch-api-data-action) and [GitHub registry](https://github.com/JamesIves/fetch-api-data-action/packages/229982).\n\n```\nyarn add @jamesives/fetch-api-data-action\n```\n\nIt can then be imported into your project like so.\n\n```javascript\nimport run, {\n  retrieveData,\n  generateExport,\n  ActionInterface\n} from '@jamesives/fetch-api-data-action'\n```\n\nCalling the functions directly will require you to pass in an object containing the variables found in the [configuration section](https://github.com/JamesIves/fetch-api-data-action#configuration-).\n\n```javascript\nimport run from '@jamesives/fetch-api-data-action'\n\nrun({\n  endpoint: 'https://example.com',\n  configuration: JSON.stringify({\n    method: 'GET',\n    headers: {Authorization: `Bearer ${process.env['TOKEN']}`}\n  })\n})\n```\n\n## Configuration 📁\n\nThe `with` portion of the workflow **must** be configured before the action will work. You can add these in the `with` section found in the examples above. Any `secrets` must be referenced using the bracket syntax and stored in the GitHub repositories `Settings/Secrets` menu. You can learn more about setting environment variables with GitHub actions [here](https://help.github.com/en/articles/workflow-syntax-for-github-actions#jobsjob_idstepsenv).\n\n#### Minimal Setup\n\nThe following configuration options should be set.\n\n| Key             | Value Information                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               | Type             | Required |\n| --------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------- | -------- |\n| `endpoint`      | The URL of the endpoint you'd like to retrieve data from. For example: `https://example.com/data`. If no `configuration` is provided then the default request method will be `GET`.                                                                                                                                                                                                                                                                                                                                                                             | `with`           | **Yes**  |\n| `configuration` | Any applicable configuration settings that should be set such as authentication tokens. You can reference secrets using the `${{ secrets.secret_name }}` syntax, or you can reference data returned from the `token-endpoint` request using the triple bracket syntax: `{{{ data.access_token }}}`. For more information refer to the [Token Request part of the readme](https://github.com/JamesIves/fetch-api-data-action#token-request-%EF%B8%8F) and the [Fetch API documentation](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch). | `secrets / with` | **No**   |\n\n#### Optional Choices\n\n| Key                   | Value Information                                                                                                                                                                                                                                                                                                                                                                                                                                              | Type             | Required |\n| --------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------- | -------- |\n| `token-endpoint`      | If the `endpoint` API requires you to make a request to get an access token prior to fetching data you can perform this task by specifying a token endpoint. Any data returned from the token end can be referenced in the `configuration` variable using the triple bracket syntax: `{{{ access_token }}}`. For more information refer to the [Token Request part of the readme](https://github.com/JamesIves/fetch-api-data-action#token-request-%EF%B8%8F); | `with`           | **No**   |\n| `token-configuration` | Any applicable configuration settings that should be set such as authentication tokens. You can reference secrets using the `${{ secrets.secret_name }}` syntax. For more information refer to the [Fetch API documentation](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch).                                                                                                                                                          | `secrets / with` | **No**   |\n| `retry`               | If you're working with an intermittent API you can toggle this option to `true`. Doing so will make the action try the request 3 times at random intervals before failing.                                                                                                                                                                                                                                                                                     | `with`           | **No**   |\n| `save-location`       | By default the save location of the file is `fetch-api-data-action/data.json`, if you'd like to override the directory you can do so by specifying a new one with this variable.                                                                                                                                                                                                                                                                               | `with`           | **No**   |\n| `save-name`           | You can override the name of the exported `.json` file by specifying a new one here. You should _not_ include the file extension in your name.                                                                                                                                                                                                                                                                                                                 |\n| `variable-name`       | Adjusts the name of the environment variable the action generates so long as `set-output` is `true`. Defaults to `fetchApiData`.                                                                                                                                                                                                                                                                                                                               | `with`           | **No**   |\n| `set-output`          | Determines if the returned data should be saved as an environment variable or not. This field defaults to `true`, but depending on your API response length you may need to toggle this. If `true`, an environment variable and action step output named `fetchApiData` will be created.                                                                                                                                                                       | `with`           | **No**   |\n| `format`              | Allows you to modify the extension of the file saved from the API response, for example you can set this field to `json` or `txt`. This field defaults to `json`.                                                                                                                                                                                                                                                                                              | `with`           | **No**   |\n| `encoding`            | Allows you to modify the encoding of the file saved from the API response, for example you can set this field to `utf8` or `hex`. This field defaults to `utf8`. Choose from `ascii`, `utf8`, `utf-8`, `utf16le`, `ucs2`, `ucs-2`, `base64`, `latin1`, `binary` or `hex`.                                                                                                                                                                                      | `with`           | **No**   |\n| `debug`               | If set to `true` the action will log the API responses it receives in the terminal.                                                                                                                                                                                                                                                                                                                                                                            | `with`           | **No**   |\n\n---\n\n### Token Request 🎟️\n\nIf you need to make a request to another endpoint in order to request an access token or something similar you can do so using the `token-endpoint` and `token-configuration` parameters. You can then use the returned token in your `configuration` variable using the triple syntax like so `{{{ tokens.access_token }}}`. You can find an example of this below.\n\n```yml\nname: Refresh Feed\non: [push]\njobs:\n  refresh-feed:\n    runs-on: ubuntu-latest\n    steps:\n      - name: Fetch API Data 📦\n        uses: JamesIves/fetch-api-data-action@v2\n        with:\n          # The token endpoint is requested first. This retrieves the access token for the other endpoint.\n          token-endpoint: https://example.com/auth/token\n          # The configuration contains secrets held in the Settings/Secrets menu of the repository.\n          token-configuration: '{ \"method\": \"POST\", \"body\": {\"client_id\": \"${{ secrets.client_id }}\", \"client_secret\": \"${{ secrets.client_secret }}\"} }'\n          # Once the token endpoint has fetched then this endpoint is requested.\n          endpoint: https://example.com/data\n          # The bearer token here is returned from the TOKEN_ENDPOINT call. The returned data looks like so: {data: {access_token: '123'}}, meaning it can be accessed using the triple bracket syntax.\n          configuration: '{ \"method\": \"GET\", \"headers\": {\"Authorization\": \"Bearer {{{ data.access_token }}}\"} }'\n```\n","funding_links":["https://github.com/sponsors/JamesIves"],"categories":["TypeScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FJamesIves%2Ffetch-api-data-action","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FJamesIves%2Ffetch-api-data-action","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FJamesIves%2Ffetch-api-data-action/lists"}