Giter Site home page Giter Site logo

JSON in body of request about request-action HOT 5 OPEN

octokit avatar octokit commented on May 24, 2024 1
JSON in body of request

from request-action.

Comments (5)

timrogers avatar timrogers commented on May 24, 2024 1

@dcarbone 👋🏻 Would you be up for making a PR to improve the documentation? I'm sure other people will run into issues like this.

from request-action.

dsoegijono avatar dsoegijono commented on May 24, 2024

Try putting it in with directly instead of body:

steps:
      - uses: octokit/[email protected]
        with:
          route: POST /repos/${{ github.repository }}/labels
          name: React ${{ github.event.ref }}
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

I ran into the same issue for another endpoint. I think the documentation is not very clear on how to pass payload.

from request-action.

dcarbone avatar dcarbone commented on May 24, 2024

For anybody else who comes across this, if you wish to make a request with a JSON body containing nested values it must be done something like this:

    steps:
      - name: 'Construct Github Environment create / update request'
        id: gh_env_req
        run: |
          _reviewers_json="$(cat <<EOF
          [ { "type": "Team", "id": 0 } ]
          EOF
          )"
          
          echo "::set-output name=reviewers_json::${_reviewers_json}"

      - name: Create / Update Github environment
        uses: octokit/[email protected]
        with:
          route: 'PUT /repos/{repo_path}/environments/{env_name}'
          repo_path: '${{ github.repository }}'
          env_name: my-env
          reviewers: '${{ steps.gh_env_req.outputs.reviewers_json }}'

If your request is static, you should probably be able to define the json contents of the nested field directly into the with: block, but for my specific use-case the json is actually constructed with the output of a subsequent api call to get the ID of the reviewer's team, thus necessitating an additional step.

The heredoc syntax and spaces between json tokens are purely for readability and are not required.

from request-action.

dcarbone avatar dcarbone commented on May 24, 2024

Sure, i'll work on one in a bit.

from request-action.

Nomango avatar Nomango commented on May 24, 2024

Constructing a JSON body in with can be challenging. But I have found a simpler way to invoke the GitHub API. actions/github-script looks pretty good.

    steps:
      - id: get_release_notes
        uses: actions/github-script@v7
        with:
          # see syntax on https://octokit.github.io/rest.js/v20
          script: |
            const { data } = await github.rest.repos.generateReleaseNotes({
              owner: '${{ github.repository_owner }}',
              repo: '${{ github.event.repository.name }}',
              tag_name: 'v1.0.0',
            });
            core.setOutput('data', data);

      - name: Show release note
        run: 'echo "${{ fromJSON(steps.get_release_notes.outputs.data).body }}"'

from request-action.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.