Authenticating with REST API

You don’t need plugins for authentication unless you’re making a cross domain request, and to get the nonce, you just create it as you would any other nonce. As the handbook states: For developers making manual Ajax requests, the nonce will need to be passed with each request. The API uses nonces with the action … Read more

Updating link on page via REST api

The problem is with your POST request, where the content property should be a plain string and not an object. You should also send just the data that you want to change. When updating a Page (i.e. a post of the type page), you should provide a JSON-encoded or URL-encoded string containing one or more … Read more

Is there anyway to format my EndPoint URL in WordPress?

You don’t. Query args are not part of the route URL. Your endpoint URL is: https://iotkidsiq.com/wp-json/zaindob/v1/sync_order So needs to be registered as: register_rest_route( ‘zaindob/v1’, ‘/sync_order’, array( ‘methods’ => ‘GET’, ‘callback’ => ‘updatetable’, ) ); key and msisdn are arguments that are sent to your endpoint. To define these use set the args property of the … Read more

pagination in WP rest api

define(‘API_ENDPOINT_VERSION’, 1); //flush the rewrite rules on plugin activation function apiendpoint_activate() { flush_rewrite_rules(); } register_activation_hook(__FILE__, ‘apiendpoint_activate’); function apiendpoint_register_endpoints() { register_rest_route( ‘api/v1’, ‘/post’, [ ‘methods’ => ‘GET’, ‘callback’ => ‘api_get_post’, ] ); } add_action(‘rest_api_init’, ‘apiendpoint_register_endpoints’); function api_get_post($request) { $ar = array(‘post_type’ => ‘posts’, ‘posts_per_page’ => 15, ‘orderby’ => ‘date’, ‘order’ => ‘DESC’, ‘paged’ => ($_REQUEST[‘paged’] ? … Read more

Get all PDF files from page with WordPress API

You would get the PDFs by querying mime_type=application/pdf So, based on your example your full URL would be: https://www.domain.com/wp-json/wp/v2/media?parent=1267&mime_type=application/pdf However, it is possible when using the parent=ID parameter, you will see ALL the PDFs, not just the attachments specific to that post. This happens when the PDFs were uploaded to the media library, but not … Read more

How do you format the set_body option for WP_Rest_Request?

WP_Rest_Request is not a way to make outgoing calls to remote REST APIs, it’s a data object core uses to pass around information about an incoming request. It’s basically something you recieved, it isn’t something you can send. If you poke your sites REST API with a request, WordPress creates and populates a WP_Rest_Request object … Read more

WP REST API GET Requests require authentication

I’ve been working on a similar issue today. Here’s what I’ve done: add_filter(‘rest_dispatch_request’, function($dispatch_result, $request, $route, $handler) { if (!is_user_logged_in()) { $dispatch_result = new WP_Error( ‘rest_not_logged_in’, __( ‘You are not currently logged in.’ ), array( ‘status’ => 401 ) ); } return $dispatch_result; }, 10, 4); You may want to use the $handler to determine … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)