I am trying to get all categories by calling Wordpress rest api on in android app. http://demo.wp-api.org/wp-json/wp/v2/categories I can get all categories by calling the above url but I have installed category image plugin so I need to get every category image in addition to default schemas. So I have to make my own custom rest api endpoint. The following is my code.
But Wordpress function get_categories returns null. Anyone let me know what is my wrong point in my code? Why I can't get what I want to get? I tried to call get_posts function in my custom endpoint function but it also returned null. So the main goal of this posting why not working calling Wordpress function get_categories and get_posts in my custom endpoint function?
register_rest_route($this->namespace, '/'.$this->rest_base, array('methods' => 'GET', 'callback' => array($this, 'get_main_categories')));
...
public function get_main_categories($request) {
$data = get_categories();
$data = rest_ensure_response($data);
return $data;
}