【问题标题】:Jira curl issue create ends with error HTTP 415Jira curl 问题创建以错误 HTTP 415 结束
【发布时间】:2022-10-04 21:44:01
【问题描述】:

我正在尝试通过 curl 在项目中创建问题,但它以 415 错误结束,我不知道为什么,因为我在那里只粘贴文本。

curl -D- -s -u email:api_key -X POST --data "{\"fields\":{\"project\":{\"key\": \"PROBLEM\"},\"summary\": \"REST ye merry gentlemen.\",\"description\": \"Creating of an issue using project keys and issue type names using the REST API\",\"issuetype\": {\"name\": \"Outage\"}}}" https://company.atlassian.net/rest/api/2/issue/ 

输出:

HTTP/2 415 
date: Tue, 27 Sep 2022 11:14:10 GMT
content-type: text/html;charset=UTF-8
server: globaledge-envoy
timing-allow-origin: *
x-arequestid: bbc0506d-8e7c-442f-a180-46632081b6a5
set-cookie: atlassian.xsrf.token=BAHL-ME69-JQ45-BS4O_929b97ddce3a4de2b40abbd3d2817ff133d29cee_lin; path=/; SameSite=None; Secure
x-aaccountid: 62b303db84d73c7201680c55
x-envoy-upstream-service-time: 56
expect-ct: report-uri="https://web-security-reports.services.atlassian.com/expect-ct-report/atlassian-proxy", max-age=86400
strict-transport-security: max-age=63072000; preload
x-content-type-options: nosniff
x-xss-protection: 1; mode=block
atl-traceid: b0b3324454c29763
report-to: {"endpoints": [{"url": "https://dz8aopenkvv6s.cloudfront.net"}], "group": "endpoint-1", "include_subdomains": true, "max_age": 600}
nel: {"failure_fraction": 0.001, "include_subdomains": true, "max_age": 600, "report_to": "endpoint-1"}
vary: Accept-Encoding

我不明白为什么我会收到来自 Jira 的 415 消息。

【问题讨论】:

    标签: json curl terminal jira


    【解决方案1】:

    HTTP 415表示不受支持的媒体类型 (https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/415)。

    基本上,您必须告诉 JIRA 您正在发送 JSON。只需添加:

    -H 'Content-Type: application/json'
    

    到你的 curl 命令。 还有另一个您可能想要使用的注释休息/api/3/问题/代替休息/api/2/问题/

    https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issues/#api-rest-api-3-issue-createmeta-get

    如果您收到一些错误消息,例如:

    Operation value must be an Atlassian Document (see the Atlassian Document Format)
    

    将您的“描述”字段更改为以下内容:

    "description": {
        "type": "doc",
        "version": 1,
        "content": [
            {
                "type": "paragraph",
                "content": [
                    {
                        "type": "text",
                        "text": "Creating of an issue using project keys and issue type names using the REST API"
                    }
                ]
            }
        ]
    }
    

    例如

    curl -i -u nanana@gmail.com:xxxxxx  -H 'Content-Type: application/json' -XPOST --data '{"fields": {"project": {"key": "RW"}, "summary": "REST ye merry gentlemen.", "description": {"type": "doc", "version": 1, "content": [{"type": "paragraph", "content": [{"type": "text", "text": "Creating of an issue using project keys and issue type names using the REST API"} ] } ] }, "issuetype": {"name": "Task"} } }' https://s50600822.atlassian.net/rest/api/3/issue
    
    {"id":"10013","key":"RW-6","self":"https://s50600822.atlassian.net/rest/api/3/issue/10013"}
    

    【讨论】:

      猜你喜欢
      • 2017-10-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多