【问题标题】:500 error when trying to create page using REST API尝试使用 REST API 创建页面时出现 500 错误
【发布时间】:2021-12-23 05:15:33
【问题描述】:

我目前正在使用 Confluence 服务器,当我尝试使用 REST API 创建新页面时,我目前收到 500 错误。我目前正在使用一个 HTML 宏,它使用 Fetch API 发出 GET 和 POST 请求。我目前在发出 GET 请求时没有问题,只有 POST 请求有问题。

我尝试研究错误并看到有人提到他们通过关闭空间中的协作编辑来修复它,但在我的情况下,这不是一个选项。任何人都知道是什么导致了这个错误?

function createPage() { 
    let url = "http://exampledomain:8090/confluence/rest/api/content/"
    fetch(url, {
        method: 'POST',
        headers: {
           'Authorization': 'Basic USER:PASS',
           'Content-Type': 'application/json',
        },
        data: {
            'type': 'page',
            'title': "New Page",
            'ancestors': [{ 'id': 97059352 }], // parent page id
            'space': { 'key': "EXAMPLE_SPACE" },
            'body': {
                'storage': {
                    'value': "<h1>New Page!</h1>",
                    'representation': 'storage',
                }
            },
        }
    })
     .then(response => console.log(response))
     .catch(err => console.log(err.message))
}

【问题讨论】:

  • 您还会发布您收到的错误消息吗?
  • 我还建议通过安装在 Conluence 中的 REST API 浏览器插件解决 REST API 调用问题:marketplace.atlassian.com/apps/1211542/…
  • @CraZ 我收到 500 内部服务器错误,错误响应中的消息为空

标签: confluence confluence-rest-api


【解决方案1】:

我看到无效的数据结构:

                    'representation': 'storage',   <== extra comma
                }
            },                                     <== another extra comma
        }

还要仔细检查您的编程语言是否可以使用单引号 ('),并且它们已正确转换为双引号 (")。 JSON (Jira REST API) 只接受键和字符串值的双引号。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多