A REST API request to manually trigger pull request rescoping is failing, resulting in an HTTP Status 400 – Bad Request error on Bitbucket Server
プラットフォームについて: Data Center - この記事は、Data Center プラットフォームのアトラシアン製品に適用されます。
このナレッジベース記事は製品の Data Center バージョン用に作成されています。Data Center 固有ではない機能の Data Center ナレッジベースは、製品のサーバー バージョンでも動作する可能性はありますが、テストは行われていません。サーバー*製品のサポートは 2024 年 2 月 15 日に終了しました。サーバー製品を利用している場合は、アトラシアンのサーバー製品のサポート終了のお知らせページにて移行オプションをご確認ください。
*Fisheye および Crucible は除く
要約
A REST API request to manually trigger pull request rescoping is failing, resulting in an HTTP Status 400 – Bad Request error on the Bitbucket Server.
Sample Curl Command or REST API call:
curl -v -u username -X POST -d '{"branches":[]}' -H "Content-Type: application/json" "http://example.com/projects/<PROJECT_KEY>/repos/<REPOSITORY_SLUG>/jobs/rescope-pull-requests"
Error Message after running the above command:
<!doctype html><html lang="en"><head><title>HTTP Status 400 – Bad Request</title><style type="text/css">body {font-family:Tahoma,Arial,sans-serif;} h1, h2, h3, b {color:white;background-color:#525D76;} h1 {font-size:22px;} h2 {font-size:16px;} h3 {font-size:14px;} p {font-size:12px;} a {color:black;} .line {height:1px;background-color:#525D76;border:none;}</style></head><body><h1>HTTP Status 400 – Bad Request</h1><hr class="line" /><p><b>Type</b> Status Report</p><p><b>Description</b> The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing).</p><hr class="line" /></body></html>* Closing connection 0
* schannel: shutting down SSL/TLS connection with bitbucket.hostname.com port 443
環境
Tested on Bitbucket Server 7.21.7
Applied to Bitbucket Server 7.x
原因
This issue generally occurs on Windows platform where ' (single quote) is not advised to use and it should be replaced with " (double quotes).
ソリューション
Issue should be resolved after using " (double quote) in place of ' (single quote) and if there are inner quotes also present then use """
(3x double-quotes).
So the command should be in the following format:
curl -v -u <admin_username>:<admin_password> -X POST -d "{"""branches""":[]}" -H "Content-Type:application/json" "<Bitbucket_BASE_URL>/projects/<Project_Key>/repos/<Repo_Sloug>/jobs/rescope-pull-requests"