如何通过REST API对Bitbucket Server的PR评论添加表情反应?
解决Bitbucket Server PR评论添加表情反应的API参数问题
正确的参数格式
Bitbucket Server REST API中,{emoticon}参数需要传入表情对应的短代码标识符,而非Unicode字符、十六进制值或字面表情。比如:
- 微笑表情对应
:smile: - 点赞表情对应
:thumbsup: - 心碎表情对应
:heartbroken:
这些短代码是Bitbucket内部定义的标准标识,你可以在Bitbucket网页端手动添加表情时,查看表情列表获取对应短代码(点击表情按钮后,每个表情下方会显示对应的短代码)。
PowerShell 实现示例
使用Invoke-RestMethod调用API的正确写法:
# 配置基础参数 $bitbucketServer = "http://你的Bitbucket服务器地址" $projectKey = "项目KEY" $repoSlug = "仓库标识" $prId = 123 # PR的ID $commentId = 456 # 评论的ID $emoticonCode = ":smile:" # 目标表情的短代码 $authInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes("用户名:密码")) # 拼接API请求地址 $apiUrl = "$bitbucketServer/rest/api/1.0/projects/$projectKey/repos/$repoSlug/pull-requests/$prId/comments/$commentId/emoticons/$emoticonCode" # 发送PUT请求(添加表情反应使用PUT方法) Invoke-RestMethod -Uri $apiUrl -Method Put -Headers @{Authorization = "Basic $authInfo"} -ContentType "application/json"
错误原因说明
你之前尝试的Unicode字符、十六进制值等格式不符合API的参数要求,因此返回400 Bad Request。Bitbucket的该API依赖内部的表情短代码映射逻辑,不直接接受Unicode字符类的输入。
内容的提问来源于stack exchange,提问作者jeremywat
相关产品推荐
相关产品推荐

