Skip to main content
2 of 3
edited tags
Brock Adams
  • 13k
  • 5
  • 39
  • 64

How to quickly retag a question from the API?

I'm playing with the write API, and I'd like to simply retag a question. This is the code I have so far:

$editURL = 'https://api.stackexchange.com/2.2/questions/' . $question->{"question_id"} . '/edit';
echo 'https://api.stackexchange.com/2.2/questions/' . $question->{"question_id"} . '/edit';
$editData = array('site' => 'stackoverflow', 'preview' => 'true', 'id' => $question->{"question_id"}, 'key' => "6Z09liTt4uTQU*a4DYOXVQ((", 'access_token' => $access_token, 'title' => $question->{"title"}, 'body' => $question->body_markdown, 'tags' => $taglist, 'comment' => 'rm [' . $tag . '] tag');
print_r($editData);
$options = array(
    'http' => array(
        'header'  => "Content-type: application/x-www-form-urlencoded, Accept-Encoding: gzip;q=0, compress;q=0\r\n",
        'method'  => 'POST',
        'content' => http_build_query($editData),
        'ignore_errors' => true,
    ),
);
$context = stream_context_create($options);
print_r(gzdecode(file_get_contents($editURL, false, $context)));

When I turn preview to false, it works and retags the question. However, it also adds in some HTML entities (like encoding stuff, &quote and whatnot) to the title and body. Is there a way to not bother with passing the existing title and markdown and just editing the tags?

user18962