Questions tagged [rest-api]

Questions about the core RESTful HTTP API for accessing WP content and data.

Filter by
Sorted by
Tagged with
3
votes
1answer
7k views

Custom route for WP-API gives “rest_no_route” value

I am following this tutorial to create custom end points to WP-API . I am always getting this error on hitting /wp-json/custom-plugin/v2/get-all-post-ids/ on postman to test : { "...
3
votes
1answer
2k views

WP REST API V2 - Modifying responses

I am trying to modify the response object of a WP REST API (v2) call following this guide: http://v2.wp-api.org/extending/modifying/ I have a post type called Careers and a taxonomy called Regions. ...
3
votes
0answers
86 views

How to authenticate custom API endpoint in WooCommerce

I have created custom API, which is working fine, but I am not able to authenticate it, it returns result without checking for keys I have created consumer key and secret key from admin. How to ...
3
votes
0answers
956 views

x-wp-nonce is not allowed by Access-Control-Allow-Headers in preflight response

I would like my dev server on http://localhost:8080 to work with my wordpress install's rest api, of which the api base url is at http://localhost/wptest2/index.php/wp-json/ I am currently getting the ...
3
votes
0answers
260 views

Wordpress REST API “rest_authentication_errors” doesn't work external queries?

Wordpress REST API "rest_authentication_errors" doesn't work external queries? I was using following experimental codes for experimental purposes. add_filter('rest_authentication_errors', 'auth'); ...
3
votes
0answers
1k views

Understanding SHORTINIT with Wordpress 5

What I am trying to achieve I am looking at using Wordpress decoupled, and most tutorials and guides go into detail on using the Rest API. Recently, I discovered the SHORTINIT option to load a very ...
3
votes
0answers
442 views

WordPress REST API call generates nonce twice on every call

I'm trying to login a user via the REST API, and then retrieve the current user on subsequent requests. As per the documentation, in my plugin, I am creating and retrieving a nonce after a successful ...
3
votes
0answers
938 views

Search WP API using the post title

I'm using the WP REST API v2 to try and search for all posts with the same title, what I'm trying to do is create a sort of head-to-head/previous meetings page for 2 teams. At the moment i can ...
3
votes
0answers
3k views

WordPress REST Upload Media

How to Upload Media via the WP REST API ? I am trying to upload media to http://example.com/wp-json/wp/v2/media using POSTMAN. I tried uploading image using the following headers Content-Type: ...
3
votes
0answers
121 views

How should an old API version be deprecated gracefully?

When researching and reading about the WP REST API utilization I've seen many topics mentioned about how another version should be rolled out but nothing in the documentation regarding a return for a ...
3
votes
0answers
2k views

How to get around WP REST API per page limit without pagination?

So I know that using /wp-json/wp/v2/customposts/?per_page=100&page=2 will allow me to bypass the default of 10 returned at a time. But I am trying to return over 2k custom posts. The only other ...
3
votes
1answer
1k views

Android authentication

I'm using WordPress REST API (Version 2), and I want to authenticate Android native app with my self-hosted WordPress site. How can I perform that using username and password ?
3
votes
0answers
168 views

WP REST API route request explain

Maybe can someone explain or show additional info about "WP REST API route request" from beginning to the end. Main questions, how handle this request in most earlier stage. For example for ajax ...
2
votes
1answer
12k views

Get more than 10 posts in a specific category with the wordpress api

I'm currently building an Ionic app that uses the Wordpress api. I can retrieve posts in a specific category by using the following: // Retrieve filtered data for the categories to show posts. ...
2
votes
1answer
7k views

Process checkout using WC REST API

With a main site using WordPress/WooCommerce, and a remote site serving front end; is it possible to process checkout form using WooCommerce REST API, and receive a redirect URL to the selected ...
2
votes
1answer
5k views

How Do I Add User Custom Field to REST API Response?

I am writing a WordPress theme that adds several custom fields to the user profile using the following function function add_contact_methods( $profile_fields ) { // Add Social Media Fields $...
2
votes
3answers
1k views

Display sub-taxonomies based on SELECTED parent-taxonomy

I have two drop downs. The first one contains list of parent taxonomies from a custom post type. And the second one contains all the sub-taxonomies at a time. But I'm trying to display only those sub-...
2
votes
1answer
939 views

How do I correctly setup an AJAX nonce for WordPress REST API?

Following a link comment here which led me to these docs, I've tried to set up a nonce for user authentication. I added: wp_localize_script( 'wp-api', 'wpApiSettings', array( 'root' => ...
2
votes
1answer
840 views

REST API URL parameters not working with apache server

The title pretty much says it all, if I try eg. /wp-json/wp/v2/posts?id=1, I get all the posts as response. URL parameters are not working as they should. According to the REST API Handbook, the ...
2
votes
1answer
1k views

How to login to WordPress site using basic authentication HTTP headers?

I'm looking to run some of my automated acceptance tests as a logged in user. My acceptance tests are run using Ghost Inspector which can send basic authentication headers. There is a basic ...
2
votes
1answer
402 views

Rest API authentication issue when called from fetch request in bundle.js

I'm able to use the Rest API for calls that don't need auth, but I'm having an auth issue for the routes that require it. Here is part of a .php view template for an admin page: <div id="...
2
votes
2answers
2k views

How to stop WP API endpoint from caching?

I have a simple endpoint. Its GET, I pass it an ID parameter and it uses this ID to make a curl call. The endpoint then responds with a couple pieces of info json_encoded. The issue is that this ...
2
votes
1answer
3k views

Rest API Hook When Post Is Requested

I am aware that I can use the endpoint /wp-json/wp/v2/posts/{id} to fetch a post. I am building an implementation of WordPress that relies completely on the JSON API and its endpoints. It is an ...
2
votes
2answers
1k views

WP REST return value to error function from Request

With WP.SE's help I've learned how to send data from a form to WP_REST but now I'm having an issue with returning a custom error. I can successfully pass information to the WP_REST_Response and I've ...
2
votes
2answers
882 views

data returned from get_post($postId) have different keys than wp-json/wp/v2/posts/{postId}

WordPress Devs. I am new to WordPress and Web development. So far WordPress Rest API v2 works well. I was writing a custom API/route/endpoint for my project using the following function. get_post($...
2
votes
2answers
2k views

How to Pull ALL Posts, Categories, or Tags in WordPress REST API

I have read other posts on this forum and none of which I read are solving my problem. Whenever I do: http://www.example.com/wp-json/wp/v2/posts?filter[posts_per_page]=-1 Or even: http://www.example....
2
votes
1answer
3k views

WP rest api v2 posts filter by 'search' & 'category_name' not working

I am calling the api as http://examples.com/wp-json/wp/v2/posts?filter[category_name]=uncategorize&per_page=30&order=asc&search=hello I am not able to get particular posts from that ...
2
votes
1answer
3k views

How to Authenticate WP REST API with JWT Authentication using Fetch API

My goal is to send user comments with a POST request from a server-side Lambda function to my WordPress API. I'm using Gatsby and Netlify. When someone leaves a comment in the comment form of my ...
2
votes
2answers
909 views

When to check for max_num_pages using Wordpress REST API?

I'm implementing infinite loading using the WP API, so I pull in the new posts via an API request. Because the default API response is fine with me and I only really need to filter the posts returned, ...
2
votes
2answers
4k views

wordpress wp-json prefix issue

I'm using Wordpress 4.9+ which I believe enabled with REST api by default. My permalinks are set to Month and Name And I'm using Foxhound React theme for my site. Now my rest api should be available ...
2
votes
2answers
1k views

register_rest_route regex option for base64 or alternate

What I tested Wordpress Version: 4.9.5 PHP Version: 7.1.7/7.1.4/7.2.0/7.0.3/5.6.20/5.5.38/5.4.45 Web Server: Nginx 1.10.1/Apache 2.4.10 Environment/Host: Flywheel local https://local.getflywheel....
2
votes
1answer
2k views

WordPress REST API validation

I'd like to validate the data sent to my end point. https://www.shawnhooper.ca/2017/02/15/wp-rest-secrets-found-reading-core-code/ This post referenced the undocumented validation options. I have got ...
2
votes
1answer
1k views

Extend WordPress REST API to show slugs for menu items

I'm using React to build the front-end of a site which uses Wordpress for the back-end. In particular, I'm using the Wordpress REST API to pull in and display content. By default, the Wordpress REST ...
2
votes
1answer
5k views

Trying to get an api request getting error 404

I'm trying to get a list of locations from a website called weedmaps. This is the code that I'm using: function call_for_api() { $url='https://api-v2.weedmaps.com/api/v2/listings'; $...
2
votes
1answer
5k views

Upload image to wordpress using REST API

I am developing API for Wordpress using REST-API. Now I am stuck at one point where I am not able to develop the API through which I can upload the image to wordpress using Rest API. I am using ...
2
votes
1answer
1k views

Match REST API post output from custom endpoint

What filters will transform a normal WP_Post object (as returned from get_posts()) to match the post objects returned from native REST API endpoints? I have a custom endpoint which returns a WP_Post ...
2
votes
1answer
7k views

WordPress V2 REST-API: Endpoints 404?

I just installed and activated the latest version of the WP REST API plugin. However, when I attempt to access a REST endpoint, I end up with the Apache 404 page. $ curl -i 'http://example.com/wp-...
2
votes
2answers
6k views

How would I add custom tables/endpoints to the WP REST API?

I have created custom tables for performance reasons for products, carts, and notifications. I want to make these tables and their data available for normal CRUD via the WP REST API v2. How would I ...
2
votes
1answer
209 views

Get loading state of wp data selector

I have a custom block that shows the assigned taxonomy terms for the current post. I'm trying to show a loading spinner while those terms are loading in the background. Let's say I have a selector ...
2
votes
1answer
644 views

Unable to get the info of the user which doesn't have created any post via REST API

I am unable to get the user info from the REST API. The user has not any post created. I have installed the Basic-Auth plugin. Whenever I try to get the user info, I get the following error. Request :...
2
votes
1answer
1k views

Filter post content in REST API

I am trying to allow a plugin to modify the rendered content of posts prior to it being rendered for the WP API, or at least save it as a separate property on that JSON response. For instance, ...
2
votes
1answer
362 views

WordPress Gutenberg get page template value when post updated?

I need to get the page template name when the post is saved. It fails in save_post hook as $_POST('page_template') is not available. Gutenberg saves post via the REST API and uses ...
2
votes
2answers
2k views

WordPress REST API - JSON “Rendered” Content Incorrect

i'm working in android application that use wordpress rest api to get blog from website to , i don't have any knowledge about php or wordpress , but i take some time to learn about it , any way my ...
2
votes
1answer
634 views

ping_status in JSON REST API

What is ping_status in JSON schema of wordpress REST API? And what is it's use cases?. The official documentation is not much explain about it - Posts|REST API Handbook.
2
votes
1answer
2k views

How to get the attached gallery in the rest API?

I just added a gallery to my post and want to access its images through the rest API. In the rest API, I can access the attachments of a post. But those attachments have other images, not in the ...
2
votes
1answer
3k views

Create post with REST API in php with file_get_contents

Actually I have no problems getting posts. I need to create posts with the REST API in php with file_get_contents. This is my code: json_decode( file_get_contents( "http://my-site.com/wp-...
2
votes
1answer
830 views

How get Themes list via REST api?

I wanted to get a list of all WordPress themes installed, together with their meta info (e.g. name, status, author etc) using WordPress REST api. I also wanted to be able to activate any theme via my ...
2
votes
1answer
871 views

How to add custom fields to admin UI and REST API response?

I am new to custom WordPress development and am learning how to use the REST API endpoints to display post content onto a non-WordPress company intranet site. I have successfully been able to consume ...
2
votes
2answers
2k views

Wordpress JSON API returns normal site page in html. How do I get it to give me JSON?

For example, entering http://mywordpresswebsite.example.com/?json=1 into the browser loads the main site html, the same as omitting the json querystring variable: http://mywordpresswebsite.example.com/...
2
votes
1answer
310 views

Headless Wordpress: How to authenticate front end requests?

I am envisioning Wordpress on the back end to work with React.js on the front end like this: Wordpress is installed on http://example.com/api React.js script is loaded into http://example.com/index....

1 2
3
4 5
18