POST /api/v1/repos/{{organization_name}}/{{repository_name}}/keys 415 response #4100

Closed
opened 2025-11-02 05:37:51 -06:00 by GiteaMirror · 2 comments
Owner

Originally created by @thestepafter on GitHub (Oct 11, 2019).

  • Gitea version (or commit ref):
  • Git version: 2.17.1
  • Operating system: Ubuntu 18.04
  • Database (use [x]):
    • PostgreSQL
    • MySQL
    • MSSQL
    • SQLite
  • Can you reproduce the bug at https://try.gitea.io:
    • Yes (provide example URL)
    • No
    • Not relevant
  • Log gist:
    All I see in the logs are SQL SELECT and UPDATE statements.

I am trying to POST to /api/v1/repos/{{organization_name}}/{{repository_name}}/keys and I am getting a 415 Unsupported Media Type response.

Here is the body of my request:

{
  "key": "ssh-rsa AAAAB3NzaC1yc2EAAAlkjBAAABAQDMJ+BsXCYCTPjCYxpHoqSd984egZYG/8U9Gtr4vFoxlkjlkjGq3CL7WhlkjlkjGXLDAznrPkf+HhB0w/JpkDUmp17eJSdJSxnC642yGks/Gev6srpqPEPY90LnTTdnJO4o+xlOAeY/OBbrkrFbvmTvPQZNqKZYpdVitnlkjeo0wztmzsLIB7iFwfFIkOzJ6qZp7J5uvMIOrhk+e/XUMTnzHaXaBx+6tvlkjk4Ex4LJByHHmin2AJFqfc/qCMPtXkbaAxucQWuvdHYMDh+9e4JBW+GwIuarSCE1/ldqObSvBCmooX2JpR26wN6xD8WLiX2V root@do-ny3-web-01",
  "read_only": 1,
  "title": "Production"
}

Here is the API response from my server and also try.gitea.io.

[
    {
        "classification": "ContentTypeError",
        "message": "Unsupported Content-Type"
    }
]

I also tried setting read_only to true since that is the default value in the docs but the same error occurs and everywhere else in the docs says read_only is a boolean value.

Originally created by @thestepafter on GitHub (Oct 11, 2019). - Gitea version (or commit ref): - Git version: 2.17.1 - Operating system: Ubuntu 18.04 - Database (use `[x]`): - [x] PostgreSQL - [ ] MySQL - [ ] MSSQL - [ ] SQLite - Can you reproduce the bug at https://try.gitea.io: - [x] Yes (provide example URL) - [ ] No - [ ] Not relevant - Log gist: All I see in the logs are SQL SELECT and UPDATE statements. I am trying to POST to /api/v1/repos/{{organization_name}}/{{repository_name}}/keys and I am getting a 415 Unsupported Media Type response. Here is the body of my request: ``` { "key": "ssh-rsa AAAAB3NzaC1yc2EAAAlkjBAAABAQDMJ+BsXCYCTPjCYxpHoqSd984egZYG/8U9Gtr4vFoxlkjlkjGq3CL7WhlkjlkjGXLDAznrPkf+HhB0w/JpkDUmp17eJSdJSxnC642yGks/Gev6srpqPEPY90LnTTdnJO4o+xlOAeY/OBbrkrFbvmTvPQZNqKZYpdVitnlkjeo0wztmzsLIB7iFwfFIkOzJ6qZp7J5uvMIOrhk+e/XUMTnzHaXaBx+6tvlkjk4Ex4LJByHHmin2AJFqfc/qCMPtXkbaAxucQWuvdHYMDh+9e4JBW+GwIuarSCE1/ldqObSvBCmooX2JpR26wN6xD8WLiX2V root@do-ny3-web-01", "read_only": 1, "title": "Production" } ``` Here is the API response from my server and also try.gitea.io. ``` [ { "classification": "ContentTypeError", "message": "Unsupported Content-Type" } ] ``` I also tried setting `read_only` to `true` since that is the default value in the docs but the same error occurs and everywhere else in the docs says `read_only` is a boolean value.
Author
Owner

@guillep2k commented on GitHub (Oct 11, 2019):

What is your Content-Type header is set to?

@guillep2k commented on GitHub (Oct 11, 2019): What is your `Content-Type` header is set to?
Author
Owner

@thestepafter commented on GitHub (Oct 11, 2019):

Uhhh, doesn't look like anything? I am using Postman to test and I don't have a Content-Type set for any of my other successful POSTs not related to deploy keys. What should the Content-Type be?

I just tried application/json for Content-Type and got this message.

[
    {
        "classification": "DeserializationError",
        "message": "json: cannot unmarshal number into Go struct field CreateKeyOption.read_only of type bool"
    }
]

I changed read_only to false from the boolean value of 0 and now the API works.

Thank you for your assistance @guillep2k!

@thestepafter commented on GitHub (Oct 11, 2019): Uhhh, doesn't look like anything? I am using Postman to test and I don't have a `Content-Type` set for any of my other successful POSTs not related to deploy keys. What should the `Content-Type` be? I just tried `application/json` for `Content-Type` and got this message. ``` [ { "classification": "DeserializationError", "message": "json: cannot unmarshal number into Go struct field CreateKeyOption.read_only of type bool" } ] ``` I changed `read_only` to `false` from the boolean value of `0` and now the API works. Thank you for your assistance @guillep2k!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#4100