Questions tagged [rest-api]

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

378 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
6
votes
3answers
5k views

How do I cache (core) API requests?

I'm am currently trialling the new (as of 2017) core API built into Wordpress. My setup is reasonably simple: +---------+ +------+ +---------+ |Wordpress|<-->|Guzzle|<-->| App ...
5
votes
1answer
648 views

WP-REST API not returning all its endpoints, 404 on documented endpoints

Here's my configuration: WordPress multisite installation on a subdirectory WordPress version is 4.7 Let's say my WordPress site is example.com/mywebsite My WordPress site has published posts The ...
4
votes
1answer
1k views

Creating a post with the REST API, curl and oauth returning 401 error

I'm trying to create a WordPress post using the REST API, OAuth, and cURL. However, I'm running into some trouble. I'm able to create a blank post (no title, slug, etc) using the following code: $...
4
votes
0answers
3k views

WP REST API V2 - Retrieve sub page by full slug (URL/Path)

I'm struggling to see if this is natively supported, or if it's not the best place to implement this functionality - in my app (Laravel) or the same side as the API (WordPress). Retrieving a single ...
4
votes
1answer
459 views

Detect page type by url (Archive, single, page, author,…)

Update:Really short version How do I get $wp_query for a given url which can be anything (single, page archive, custom post type, author, year, month,...)? TL;DR I need a function which can return ...
4
votes
0answers
157 views

Retrieve CSS and JS From the REST API

Does anyone know of a way to get a list of all registered styles and js scripts in-use on a site via the REST API? Essentially was wp_print_styles() does?
4
votes
1answer
453 views

Using the REST API (v2) javascript client on a private namespaced route

I am using the latest version of the REST API plugin in a project and I've added my routes to a separate namespace (as recommended in the documentation). The javascript client included with the API ...
4
votes
0answers
1k views

How to allow users login to WP from external domain and make REST requests

Basically what i want to do is: Use Wordpress as a login system and data storage for web-application on another domain. Make users able to register and perform REST calls from the application. Let ...
3
votes
0answers
329 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
591 views

WP REST API returns blank response if post is too long

I'm working on an iOS app that requires the use of WP Rest API to fetch posts. Everything is working smoothly and I fetch posts by ID using this endpoint: https://example.com/wp-json/wp/v2/posts/...
3
votes
2answers
1k views

Gutenberg custom block plugin with custom image sizes

I am using a custum gutenberg block plugin for wordpress(https://neliosoftware.com/blog/how-to-create-your-first-block-for-gutenberg/) This block is using an image but always choosing the full size ...
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
111 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
164 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
0answers
56 views

Limit REST API output to current logged in user that is also author of the content

https://developer.wordpress.org/rest-api/using-the-rest-api/frequently-asked-questions/#require-authentication-for-all-requests This requires authentication for all reque​sts. add_filter( '...
2
votes
0answers
208 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 ...
2
votes
0answers
116 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'); ...
2
votes
2answers
233 views

Transition from (classical) serialized custom meta field to (gutenberg) rest enabled meta

I have a custom meta box for saving values from two input fields into a single post meta field. The data is saved serialized in the DB: get_post_meta( $post->ID, '_custom_key', true ) will ...
2
votes
0answers
525 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 ...
2
votes
0answers
729 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 ...
2
votes
1answer
186 views

Flush Rewrite Rules on init or rest_api_init?

if I'm using the REST API to create endpoints in my plugin, should I be flushing rewrite rules on init or in rest_api_init? I realize that it should be done on plugin activation/deactivation. However,...
2
votes
0answers
61 views

Rest API and Custom Fields

how can I create a new post post (custom type, with custom fields) on the front end using rest api and an http request? Is this even currently possible to create a new post with custom fields through ...
2
votes
0answers
818 views

WP Rest API max limit include parameter?

I'm using the rest API to get only selected posts though Rest API. I have used include=<ids> parameter. I have send the API request like: http://example.com/wp-json/wp/v2/posts?include=11,12 ...
2
votes
1answer
2k views

404/500 error on /wp-json

I get 500 error on wp-json. if I try to echo get_rest_url() I get example.com/wp-json, which then gives me error 500. I added RewriteCond %{REQUEST_URI} !^/wp-json to my .htaccess, which gave me 404 ...
2
votes
0answers
658 views

create new post using rest API and set featured Image from an external link

I am new to Wordpress. I need to create a new post from the Rest API which has its featured image from an external link. I can successfully create a new post using the rest API plugin, how do I add ...
2
votes
0answers
924 views

Is it possible to update a post meta field through REST API if the format of it when registered is nested?

I am able to get the custom REST API fields using meta key values to be formatted like this: "location": { "lat": "000001", "long": "000002" }, The works fine when I am trying to retrieve ...
2
votes
0answers
256 views

Remote REST request to check login status

There are 2 wp installations, A and B. Is it possible to do a remote rest request from site A to find out if an user is logged into site B? If yes, how? With this information adjustments would be ...
2
votes
1answer
269 views

Is it possible to nest the JSON result of Wordpress REST API?

I have been try to search around if it is possible to have a 'nested' JSON response in adding some custom fields through register_rest_field I have this code: function video_get_post_meta($object, $...
2
votes
0answers
56 views

WP REST- video and audio players

Im build VUE JS based theme, and Im using WP REST v2. And there is a problem, I can't make video and audio playlist working (build-in WP feature). I already added: wp_enqueue_style( 'wp-mediaelement' ...
2
votes
1answer
323 views

Permission Check for REST API Endpoint Runs Twice?

I'm making a plugin using the WP REST API, and everything seems to be working as expected. However, there is behavior I don't understand. The authPermissionCheck() method is executed twice for each ...
2
votes
0answers
182 views

How to filter users on custom meta fields in WP JSON v2?

I am trying to filter users on meta field, say abc is user meta field and value is 123 for user1. I have tried filter parameter with WP query like parameters, but it returns all users. 'search' ...
2
votes
1answer
2k views

Modify WordPress Rest Api Request/Response

I am building an application using WordPress Rest API. I want to make simple calls to the API, such as just /wp-json/wp/v2/posts and let the backend have a systematic way how to handle this and serve ...
2
votes
0answers
357 views

Prevent wp_insert_user from creating duplicate users

I have a custom plugin that automatically creates a new user via wp_insert_user() if the current user does not exist yet. We use data from our remote ldap server to provide the new user's details (...
2
votes
0answers
130 views

Login WordPress website using wp-rest api

I am using WordPress 4.8 and i am new to rest api . I have 2 websites , one is www.example.com and second is www.example.com/site2. That is second website is installed inside the first . In example....
2
votes
0answers
155 views

WP REST API returns incorrect data?

I'm trying to get a page from the API based on its page template however it seems to be returning incorrect data? so I'm unsure whether I am using the API correctly. http://domain.dev/wp-json/wp/v2/...
2
votes
0answers
483 views

How to make a WP REST API query with meta_query in WP4.7?

There is no "filter" parameter in WP REST API WP 4.7 and this call doesn't work: http://domain.tld/wp-json/wp/v2/cpt_name?meta_query[0][key]=cf_name&meta_query[0][value][0]=cf_value1&...
2
votes
1answer
627 views

WP API ignores filter parameter

I'm trying to return a list of posts or media via the Rest API But it seems that when a filter incorrectly specified then a whole page of results is passed back. So a curl command like curl -gv "...
2
votes
0answers
61 views

Keep user’s privileges on accessing contents in JSON response

I use WordPress REST API plugin to fetch WordPress stuff on a mobile app. What Access manager plugin keeps the privileges on REST API responses? I want restrict access to certain posts, categories ...
2
votes
1answer
3k views

How to generate HMAC-SHA1 signature to use with WP REST API and OAuth1

I'm trying to publish a post using WP REST API. I was able to authenticate using OAuth1 using the PAW http client. I was able to publish a post to the site as well (again using PAW). PAW generated ...
2
votes
1answer
1k views

Custom Post Type and API REST is not working

I have created a custom post type called 'customers'. I'm registering step by step as the documentation says. But when I make a call to the rest api, it just returns a 404 response. See the code below:...
1
vote
0answers
31 views

Woocommerce custom endpoints

Currently, I'm an android developer(Java) and trying to add some custom endpoints to my Woocommerce site. I've wasted so much time to understand concepts of WP, but still can't get clear answer. So ...
1
vote
0answers
28 views

Register REST route with a multi-value parameter

I want the UID parameter of this REST route I'm registering to accept both a single value or multiple values (let's say a comma-separated list, like "800,300,100"). Is there some standard way to do ...
1
vote
0answers
24 views

Solve cors problem using rest api or ajax

I'm building an app with nuxt using WP as a CMS, so I have this code in my functions.php to allow any origin (temporary) using the rest api and admin-ajax urls function add_cors_http_header(){ // ...
1
vote
0answers
21 views

Update a post based on results from GET request to another server

I need to use GET requests to retrieve the current status of a device and then update the body of a specific Wordpress post with the text data sent by the external device (for reference, it will use ...
1
vote
0answers
21 views

How to insert Comment metadata via REST API

I am trying to insert comment from my android app , i am using REST API and POST method /wp-json/wp/v2/comments/ The method is working great , but I would like to include metadata when inserting ...
1
vote
0answers
23 views

Woocommerce REST API - updating an order changes custom tax calculations

We have a online woocommerce store that processes two types of orders: shipping and instore pickup. Shipping calculates taxes based on billing address and instore uses the store address (zip). ...
1
vote
0answers
29 views

WP rest api returns 404 only when author param is used

I have a multisite wordpress installation on aws linux, working perfectly fine. The WP Rest api is also working exactly as it should. Except for one single case. /wp-json/wp/v2/posts?author=<some ...
1
vote
0answers
95 views

Blocks Rest API rest_cannot_delete

I'm trying to make a Postman call to the Wordpress API to delete a block. However, I keep getting a 403. This user is used to add and delete pages, tags, and posts just fine using the Application ...