Use Github Actions to make API get request and save data to repo

4.9k Views Asked by At

I would like to set up a GitHub actions workflow that:

  1. Makes an API request to another site (outside of GitHub), which returns JSON.
  2. Add (commit) that JSON to my repo

I have an action that looks like below. It appears to run correctly, and the log even outputs that the file has been saved. But, the file never appears anywhere in my repo.

I've never set up actions before, so I'm new to some of the terminology around them as well.

Any tips or thoughts on how to get this action or work, or an alternative approach?

name: Refresh Feed
on: [push]
jobs:
  refresh-feed:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2
        with:
          persist-credentials: false
  
      - name: Fetch API Data
        uses: JamesIves/[email protected]
        with:
          ENDPOINT: https://www.loc.gov/maps/?fa=location:cyprus&fo=json&at=results
          RETRY: true
1

There are 1 best solutions below

0
On BEST ANSWER

I mean from the readme of the repo it seems that you just need to run this action with the github token. I just ran the Fetch API Data action and was able to see the new directory created by running an ls on an step after the action.

How to get github token

enter image description here

Then you would need to create a secret and add the env ACCESS_TOKEN

How to create secrets in repo

Action to run

name: Refresh Feed
on: 
  schedule:
    - cron: 10 15 * * 0-6
jobs:
  refresh-feed:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout ️
        uses: actions/checkout@v2
        with:
          persist-credentials: false

      - name: Fetch API Data 
        uses: JamesIves/fetch-api-data-action@releases/v1
        with:
          ENDPOINT: https://www.loc.gov/maps/?fa=location:cyprus&fo=json&at=results
          retry: true
      - name: Build and Deploy 
        uses: JamesIves/github-pages-deploy-action@releases/v3
        with:
          ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }}
          BRANCH: master # Pushes the updates to the master branch.
          FOLDER: fetch-api-data-action # The location of the data.json file saved by the Fetch API Data action.
          TARGET_FOLDER: data # Saves the data into the 'data' directory on the master branch.