WordPress notification rest API code

1.2k views Asked by At

Like WordPress give us rest API for comments, posts etc. I want to get notification API code.

developer.wordpress.com gives the documentation for how to use notification API.

https://developer.wordpress.com/docs/api/1/get/notifications/$note_ID/.

To use this API, I need WordPress rest API notification code.

How can I get that code.

WordPress rest API code doesn't have notification code.

https://wordpress.org/plugins/rest-api/

Please help me.

1

There are 1 answers

7
Vasim Shaikh On

You can use following code to get notification id using rest api.

Note : assume id is 1801481297

<?php
$options  = array (
  'http' => 
  array (
    'ignore_errors' => true,
    'header' => 
    array (
      0 => 'authorization: Bearer YOUR_API_TOKEN',
    ),
  ),
);

$context  = stream_context_create( $options );
$response = file_get_contents(
    'https://public-api.wordpress.com/rest/v1/notifications/1801481297',
    false,
    $context
);
$response = json_decode( $response );
?>