octokit / request-action

A GitHub Action to send arbitrary requests to GitHub's REST API
https://github.com/marketplace/actions/GitHub-API-Request
MIT License
370 stars 47 forks source link

Having this problem "Bad Credentials" #252

Closed saminBee closed 1 year ago

saminBee commented 1 year ago

What happened?

Warning: Unexpected input(s) 'owner', 'repo', valid inputs are ['route', 'mediaType']
Run octokit/request-action@v[2](https://github.com/***/***/actions/runs/5168372820/jobs/9309914439#step:2:2).x
  with:
    route: GET /repos/{owner}/{repo}/releases/latest
    owner: ***
    repo: ***
    mediaType: {}
  env:
    GITHUB_TOKEN: ***
GET /repos/{owner}/{repo}/releases/latest
> owner: ****
> repo: ******
> mediaType: [object Object]
< [4](https://github.com/***/***/actions/runs/5168372820/jobs/9309914439#step:2:4)01 21[9](https://github.com/***/***/actions/runs/5168372820/jobs/9309914439#step:2:9)ms
Error: Bad credentials

Versions

octokit/request-action@v2.x

Relevant log output

No response

Code of Conduct

gr2m commented 1 year ago

Can you share your workflow file?

saminBee commented 1 year ago
on:
  workflow_dispatch:
    inputs:
      mail:
        description: 'Customer Email'
        required: true

name: "Hishabee E-commerce"
jobs:
  build:
    name: Hishabee E-commerce
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-java@v1
        with:
          java-version: '12.x'
      - uses: subosito/flutter-action@v1
        with:
          channel: 'stable'

      - run: flutter clean
      - run: flutter pub get
      - run: flutter pub run flutter_launcher_icons
      - run: flutter build apk
      - run: flutter build appbundle --release

      - name: Push to Releases
        uses: ncipollo/release-action@v1
        with:
          artifacts: "build/app/outputs/apk/release/*"
          tag: v3.0.${{ github.run_number }}
          token: ${{ secrets.TOKEN }}

      - name: Push to Releases aab
        uses: ncipollo/release-action@v1
        with:
          artifacts: "build/app/outputs/bundle/release/*"
          tag: v2.0.${{ github.run_number }}
          token: ${{ secrets.TOKEN }}

      - uses: octokit/request-action@v2.x
        id: get_latest_release
        with:
          route: GET /repos/{owner}/{repo}/releases/latest
          owner: Hishabee
          repo: hishabee_ecommerce
        env:
          GITHUB_TOKEN: ******
      - run: echo "${{ fromJson(steps.get_latest_release.outputs.data)['assets'][0]['browser_download_url'] }}"

There are also other actions, i hope this is enough to sort the problem @gr2m

saminBee commented 1 year ago

any update? @gr2m

gr2m commented 1 year ago
      - name: Push to Releases aab
        uses: ncipollo/release-action@v1
        with:
          artifacts: "build/app/outputs/bundle/release/*"
          tag: v2.0.${{ github.run_number }}
          token: ${{ secrets.TOKEN }}

Here you set token to secrets.TOKEN

      - uses: octokit/request-action@v2.x
        id: get_latest_release
        with:
          route: GET /repos/{owner}/{repo}/releases/latest
          owner: Hishabee
          repo: hishabee_ecommerce
        env:
          GITHUB_TOKEN: ******

What are you doing here?

Two more questions

  1. What type of token is SECRETS.token?
  2. Is this workflow running in the Hishabee/hishabee_ecommerce repository?
saminBee commented 1 year ago
  1. this token is a GitHub secret token. I am pushing the built aab file into the release bucket list of the repository.
  2. Yes, this workflow is running in HishaBee/hishabee_ecommerce.

I have been running these github actions for about 6+ months, and it was working fine. This action basically helps our customer to get their own ecommerce mobile app by providing their email, we provided 200+ website running this action. But suddenly the action octokit showing 401 error

saminBee commented 1 year ago
  - uses: octokit/request-action@v2.x
    id: get_latest_release
    with:
      route: GET /repos/{owner}/{repo}/releases/latest
      owner: Hishabee
      repo: hishabee_ecommerce
    env:
      GITHUB_TOKEN: ******

in here i am accesing the downloadable url which we will provide to our customer through email

gr2m commented 1 year ago

It's most likely a problem with this line

GITHUB_TOKEN: ******

try to replace it with this

GITHUB_TOKEN: ${{ secrets.TOKEN }}

If you want to use a different token, then add the token to repository secrets and set it to that secret using the ${{ secrets.MY_TOKEN }} syntax

saminBee commented 1 year ago

Thank you so much. Problem solved. I forgot that i have changed my github token for logging in in my new laptops android studio. That is why it was showing Bad Credentials.