octokit / request-action

A GitHub Action to send arbitrary requests to GitHub's REST API

Home Page:https://github.com/marketplace/actions/GitHub-API-Request

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error: you must specify a custom media type in the 'Accept' header

petertulala opened this issue · comments

Hi. I have the following workflow step:

  createRepoUsingTemplate:
    runs-on: ubuntu-latest
    steps:
      - uses: octokit/request-action@v2.x
        id: create_repo_using_template
        with:
          route: POST /repos/TEMPLATE_OWNER/TEMPLATE_REPO/generate
          owner: OWNER
          name: NAME
          private: true
          accept: 'application/vnd.github.baptiste-preview+json'
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Even though I provided the Accept header as required by the preview notice, the request fails with HTTP code 415 and I'm getting the following error:
Error: If you would like to help us test the Repository Templates API during its preview period, you must specify a custom media type in the 'Accept' header. Please see the docs for full details.

When I manually call the HTTP request, everything works as expected:

POST https://api.github.com/repos/TwoDigits/url-shortener/generate
Accept: application/vnd.github.baptiste-preview+json
Authorization: Basic .....
Content-Type: application/json

{
  "owner": "OWNER",
  "name": "NAME"
}
Response code: 201 (Created); Time: 1861ms; Content length: 6500 bytes

That's not how you can set an accept header, can you try this instead?

          mediaType:
            previews: ["baptiste"]

That's not how you can set an accept header, can you try this instead?

          mediaType:
            previews: ["baptiste"]

I've already tried that. But that ends up with a startup failure:

The workflow is not valid. .github/workflows/createRepo.yml (Line: 35, Col: 13): A mapping was not expected

sorry, I forgot, stupid YAML. We have an example in the docs for a similar case, you need to set object values using a multi-line string, like so

image

Try this

          mediaType: |
            previews:
              - baptiste

@gr2m This works well, thanks!