Mention API - Mark a mention as READ

213 views Asked by At

Using the API here: https://dev.mention.com/resources/alert_mentions/#put-accounts-id-alerts-alert-id-mentions-mention-id

From what I understand, if I want to mark a specific "mention" as read, I do something like this:

$browser = new \Buzz\Browser(new \Buzz\Client\Curl);

$params = ['read' => true]; //tried this

$url = "https://api.mention.net/api/accounts/" . $this->getAccountId() . "/alerts/{$alert_id}/mentions/{$mention_id}";


if(!empty($params))
{
    $url .= '?' . http_build_query($params); //i think this isnt needed because i pass $params below to the $browser->put but it was worth a try.
}

$response = $browser->put($url, array(
            "Authorization: Bearer {$this->getAccessToken()}",
            "Accept: application/json",
        ), $params);

if (200 != $response->getStatusCode()) {
    return false;
}

However, when I run the code, it doesn't produce any errors and infact returns a valid response, but the "read" flag is still set to false.

Also tried:

$params = ['read' => 'true']; //tried this
$params = ['read' => 1]; //tried this
1

There are 1 answers

0
Arnaud Le Blanc On BEST ANSWER

The Mention API accepts JSON in request bodies: https://dev.mention.com/#request-format

You can mark a mention as read like this:

$params = ['read' => true];

// params are json encoded
$params = json_encode($params);

$response = $browser->put($url, array(
    "Authorization: Bearer $token",
    "Accept: application/json",
    // the Content-Type header is set to application/json
    "Content-Type: application/json",
), $params);