Get help from other users here.
Moderators: Developer, Contributor
-
acoder2020
- Posts: 65
- Joined: 11 Jan 2024, 19:32
Post
by acoder2020 »
I'm attempting to add notes to a successfully posted Mantis Issue (under bug_id 201)
Failed to add comments to MantisBT for TRAC ticketid 1955. HTTP Code: 400
Response: {"message":"Issue note not specified.","code":11,"localized":"A necessary field \"Note\" was empty. Please recheck your inputs."}
Here is the JSON package sent to {{url}}/api/rest/issues/201/notes
Code: Select all
[
{
"bug_id": 201,
"text": "Condition option fixed\r\n\r\nNow on to the date fields\r\n",
"view_state": "10",
"created_at": "2024-03-13 14:27:47",
"reporter": {
"name": "acoder2020"
}
},
]
The documentation does not mention a "note" field:
https://documenter.getpostman.com/view/ ... a66112c24d
Code: Select all
curl --location -g '{{url}}/api/rest/issues/1/notes' \
--header 'Authorization: {{token}}' \
--header 'Content-Type: application/json' \
--data '{
"text": "test note",
"view_state": {
"name": "public"
}
}'
-
acoder2020
- Posts: 65
- Joined: 11 Jan 2024, 19:32
Post
by acoder2020 »
I've also tried:
Code: Select all
[
{
"bug_id": 210,
"note": {
"text": "changed date label",
"view_state": "10",
"created_at": "2024-03-20 13:59:21",
"reporter": {
"name": "acoder2020"
}
}
},
]
Same error.
-
acoder2020
- Posts: 65
- Joined: 11 Jan 2024, 19:32
Post
by acoder2020 »
The PHP code driving all this. There is something in all of the variables passed. I can copy that debug output if needed.
Code: Select all
$url_issue_notes = "https://example.com/api/rest/issues/$mantis_issue_id/notes";
$q2 = "
SELECT
time,
author,
newvalue
FROM
ticket_change
WHERE
ticket=:trac_ticket_id
AND field='comment'
AND newvalue!=''
ORDER BY
time
";
$stmt2 = $pdo->prepare($q2);
$stmt2->bindParam(':trac_ticket_id', $trac_ticket_id, PDO::PARAM_INT);
$stmt2->execute();
while ($r2 = $stmt->fetch(PDO::FETCH_ASSOC))
{
$comment_time = $r2['time'];
$author = $r2['author'];
$comment = clean_trac_text($r2['newvalue']);
$custom_trac_created_at = convertTimestamp($comment_time);
// Create comment array
$commentData = [
'bug_id' => $mantis_issue_id, // The MantisBT bug ID
'note' => [
'text' => $comment,
'view_state' => '10',
'created_at' => $custom_trac_created_at,
'reporter' => [
'name' => $author
]
]
];
// Add comment data to array
$comments[] = $commentData;
}
if (!empty($comments))
{
// Convert $comments array to JSON
$comments_json = json_encode($comments);
// Initialize cURL session
$ch = curl_init();
// Set cURL options for comments
curl_setopt($ch, CURLOPT_URL, $url_issue_notes);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $comments_json);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
// Execute cURL request for comments
$response_comments = curl_exec($ch);
$httpCode_comments = curl_getinfo($ch, CURLINFO_HTTP_CODE);
// Check for errors in comment submission
if ($httpCode_comments == 200 || $httpCode_comments == 201) {
echo "<p>Comments added successfully to MantisBT under Mantis BugID $mantis_issue_id!</p>";
} else {
echo "<p>Failed to add comments to MantisBT for TRAC ticketid $ticketid. HTTP Code: $httpCode_comments at line " . __LINE__;
echo "<p>Response: " . $response_comments;
exit;
}
As above I've tried formulating the JSON data a lot of different ways, obviously starting with how the official documentation says to do it.
This has me stuck.
-
dregad
- Developer
- Posts: 76
- Joined: 26 Jul 2010, 14:24
Post
by dregad »
Not sure why you posted that issue under CSV plugin project. I moved it to MantisBT