REST API と PHP/cURL を使用していくつかのカスタム フィールドを更新しようとしています。
下にあるものは昨日「機能した」(と思う)のに、気付かずに何かを編集したのではないかと思っていますが、現在は機能していません。
以下から、さまざまな「方法」を使用してさまざまな応答を取得します。
以下でコメント解除されているため、POST メソッドを使用してこれを取得します。
HTTP 405 - 指定された HTTP メソッドは、要求されたリソース () に対して許可されていません。
POST をコメントアウトして、コメントアウトした PUT メソッドを使用すると、これが得られます。
{"status-code":500,"message":"Read timed out"}
そして、これは PUT と POST を組み合わせて組み合わせたものです。
{"errorMessages":["No content to map to Object due to end of input"]}
私は何が欠けていますか/間違っていますか? 次のコードを使用しています。
<?php
$username = 'username';
$password = 'password';
$url = "https://example.com/rest/api/2/issue/PROJ-827";
$ch = curl_init();
$headers = array(
'Accept: application/json',
'Content-Type: application/json'
);
$test = "This is the content of the custom field.";
$data = <<<JSON
{
"fields": {
"customfield_11334" : ["$test"]
}
}
JSON;
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
// Also tried, with the above two lines commented out...
// curl_setopt($ch, CURLOPT_PUT, 1);
// curl_setopt($ch, CURLOPT_INFILE, $data);
// curl_setopt($ch, CURLOPT_INFILESIZE, strlen($data));
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
$result = curl_exec($ch);
$ch_error = curl_error($ch);
if ($ch_error) {
echo "cURL Error: $ch_error";
} else {
echo $result;
}
curl_close($ch);
?>