The Stack Overflow podcast is back! Listen to an interview with our new CEO.

Questions tagged [rest-api]

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

Filter by
Sorted by
Tagged with
0
votes
1answer
37 views

How to order WordPress Rest API data

I am pulling in some data via the Rest API: https://legalsecurityforum.com/wp-json/wp/v2/speaker?include[]=3116&include[]=3249&include[]=3170&include[]=3416&include[]=3181&include[...
1
vote
1answer
59 views

WP Rest API - How to get an empty response if query has no posts

I am using rest_{post_type}_query for some custom query params. It works fine, however, I would like to get an empty response or a "no posts found" message when the query doesn't have the posts ids to ...
0
votes
0answers
79 views

Custom REST API Endpoint not working

I tried to create new custom rest API endpoint inside my theme function.php file. I also tried inside the plugins folder but it's not worked for me. This is how I write the function on function.php ...
0
votes
0answers
50 views

Fetching all users that didn't post with rest api (current version 2)

By default, wordpress only shows you the users who have posted on the site through the /wp-json/wp/v2/users I want to fetch all users whether they have posted or not (using wordpress as a headless ...
0
votes
0answers
29 views

How to connect zapier and wordpress?

I have a site, where users can create accounts and store some data. What I try to reach is to allow users to connect their accounts to zapier, and pass data. In other words, allow a user to specify ...
0
votes
0answers
33 views

404: WordPress Rest API

I have a laravel 5.5 site which is up and running. Further, I have to develop WordPress inside a laravel site. Hence I have setup a WordPress site inside laravel's public folder as follows: ...
0
votes
0answers
25 views

AJAX call recieving a 400 bad request when array lenght is to long

I have a select dropdown where users can choose multiple options that get's sent to a custom Rest-API endpoint and returns values based on their selection(s). The dropdown is dynamically populated ...
0
votes
0answers
65 views

WP REST API Problem Bad Request In PHP curl code

When I run this curl code. It gives me a Bad Request Error from Apache Serve. I give a screenshot of this. Also, Give my code. Please Give me solution Of this. Screenshot : My Code is : $wprest = ...
0
votes
1answer
49 views

How to require files in a custom endpoint

I am working on a custom endpoint to handle ajax media uploads with media_handle_upload(). I have created a custom endpoint with a route that is tested and works, however when I try require the ...
0
votes
1answer
156 views

How can I capture Memberpress user info after signup

I'm currently working on a website where users can purchase subscriptions using memberpress, I want to capture the user data after the signup process is completed and the payment transaction is also ...
0
votes
0answers
80 views

Tax are not showing on order while placing order with REST API

I'm trying to placing order with REST API which will use for android app. I've used wc_create_order() for placing order but I didn't getting tax values as I got in web view. What I want - I need to ...
0
votes
1answer
52 views

Calling a python script from custom wordpress rest api returns null

So, I have a python script that uses machine learning models to predict and print a string. Running the script alone gives desired output and takes around 12 seconds to complete. Now calling the ...
0
votes
1answer
208 views

“error_message”: “Sorry, you cannot list resources.” using WooCommerce API

When requesting the test API, getting the following response: { "errors": [ { "error_code": "", "error_message": "Sorry, you cannot list resources." } ]...
0
votes
0answers
69 views

How to prevent post update using transition_post_status

I am building an application using WP REST API. Ideally, users are able to post only if they have a subscription. Here is how I plan to make things work: Set expire_by user meta when they sign up. ...
0
votes
0answers
25 views

Remove comma in wp-json results

I am using the Wp REST API to filter posts using AJAX. The problem is that when the posts are filtered, a comma is added between them but I am not sure where is it comming from. Here is the code I am ...
0
votes
1answer
24 views

How to get data from a private API and add it to wordpress pages

I got a private API (Cliniko) I want for example the full list of clients to be listed where I want on a page. I know how APIs work, what I don't know is how to implement them in Wordpress. Is there ...
1
vote
1answer
241 views

Add Products to user's ID Woocommerce

I have made an REST API for synchronize user's cart item to web view to android view. I have used CoCart WP plugin Here are some scenarios: If I adding product from website I can get user's cart ...
0
votes
1answer
130 views

Can I define multiple callback methods depending on the call method?

He is my current custom API: add_action( 'rest_api_init', function () { register_rest_route('my-project/v1/form', '/get', array( 'methods' => WP_REST_Server::READABLE, 'callback' => '...
0
votes
0answers
112 views

How to apply 'rest_post_query' filter only when fetching a single post?

I'm working with the Wordpress API. I have modified the default query using rest_post_query to exclude a certain category: add_filter( 'rest_post_query', 'get_posts', 10, 2 ); function get_posts( $...
1
vote
1answer
67 views

Is there a way to identify a user in a custom REST API method? [duplicate]

In a custom REST API method, I would like to identify the user (typically get_current_user_id() then retrieve their data from database (things like they're role and some custom permission). But so ...
4
votes
2answers
3k views

Why is my custom API endpoint not working?

I tried to include this code in my plug-in php files as well as in functions.php. (In the end I would like it to be in the plug-in's php file but I'm not yet sure if possible, that would probably be ...
0
votes
0answers
56 views

GETing data from a gzip compressed API?

I know WP can get JSON API data via a GET request, but does anyone know plugins/ways that I can get and decompress JSON data from a gzip compressed API? I would then output the JSON response to a ...
0
votes
0answers
31 views

Using Wordpress solely as a Backend - dealing with WP_SITEURL

I've built a website in Angular that leverages Wordpress as a backend, specifically using its REST API. I am replacing an existing website, and my client does not intend to change the original ...
0
votes
1answer
81 views

WordPress multisite REST API connection refused with android - redirects to home page when using IP address in Postman

I have built a sub-directory type multisite and installed wp rest api on my localhost. Next step would be to connect the multisite to my android app using the rest api. This is where things go wrong. ...
1
vote
1answer
1k 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 ...
1
vote
2answers
142 views

Wordpress Rest filter for custom taxonomy gets applied to the admin area

I have a custom taxonomy called collection, with advanced custom fields in it. I'm using wordpress API, so since I need to filter the API responses by ACF values, I have this filter in my theme ...
0
votes
0answers
93 views

auth error with react native and wordpress rest api jwt token

I am trying to user wordpress rest api with jwt token and react native but I have issues debugging with postman; jwt/token returns the token, and the user display, etc. jwt/token/validate returns ...
1
vote
0answers
58 views

How do I add meta when creating a post with rest api?

I have this code that inserts a post into WordPress site using Rest API: $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $row->site_url."/wp-json/wp/v2/posts"); curl_setopt($ch, ...
0
votes
2answers
111 views

rest api authentication

So I'm trying to learn the WP Rest API. I want to create a post. I'm using the postman app. I get the 401 error when I try to POST (GET is fine) But I thought being logged onto my WP site would be ...
1
vote
1answer
162 views

Get Block Attributes in JSON REST API

I am trying to make my block attributes show up in the REST API. To start, I've added the rest_api_init hook to whitelist my block for inclusion. add_action( 'rest_api_init', function () { ...
0
votes
0answers
39 views

what make difference between shipping methods for a zone when a create order with woo api

please help ,when i decide to create an order i found that i have to specific shipping_lines "shipping_lines": [ { "method_id": "flat_rate", "method_title": "Flat Rate", "total"...
0
votes
0answers
14 views

Get automatically added content to posts via wo json rest api

I am using advanced ads plugin to show my custom image ads using placements, so these ads get automatically placed within the posts. Now I want use wo json ali in my android app and want to get those ...
0
votes
0answers
102 views

How to set JWT token with PHP on successful login?

I'm creating a decoupled application: the frontend is built with React, the backend uses Wordpress. However, due to some limitations the login and registration frontend pages must use a Wordpress ...
0
votes
1answer
114 views

wrapping 'rest_api_init' in 'is_admin()' function

i'm create custom admin page via add_menu_page, let's imagine that my custom page has url wp-admin/admin.php?page=settings_page then i'm checki is_admin() function via var_dump on my ...
0
votes
0answers
435 views

get token using the 'WordPress REST API with JWT Authentication' plugin

I'm trying to build a Wordpress plugin that is an API which can be queried from remote websites. I want to secure it with JWT web tokens, so I did install the JWT Authentication for WP REST API ...
2
votes
2answers
610 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, ...
1
vote
1answer
226 views

How to search by metadata using REST API

I have a custom post type like this: register_post_type('horario_busao', [ 'labels' => [ 'name' => 'Horário Busões', 'singular_name' => 'Horário Busão' ], 'public'...
0
votes
1answer
63 views

PHP: authenticate for a REST request?

I did create some custom endpoints for a plugin i'm working on, with the REST api. It works quite well, but now I would like to secure those requests : I don't want external users (EDIT: I mean remote ...
0
votes
1answer
99 views

REST : how do you handle the rest_no_route error?

i'm playing with the REST api and when doing some REST requests I got sometimes what I want, and sometimes this response generated by rest_ensure_response() : { "code": "rest_no_route", "data"...
0
votes
0answers
21 views

WP API V2 Filtering URL request second tier

I currently have a WP API URL call that looks like https://siteurl/wp-json/wp/v2/knowledge_base?_embed&knowledge_types=8 The JSON code looks like [ { "knowledge_types": 8, } ] How ...
0
votes
0answers
81 views

How to add new term-meta field in get_the_term array?

I am creating an API which is based on for category posts. In taxonomy category there is one ACF field for image upload. In API i am fetching category values like this: $cat_post = new stdClass(); ...
4
votes
1answer
1k views

How to return Meta data from the REST API?

I added meta box City and Location to my post, but when I calling the endpoint (by WP Rest API) /wp-json/wp/v2/<post_type>/<post_id> it's not returning my meta data. I tried to use ...
3
votes
1answer
258 views

Does pre_get_posts affect REST API responses?

I'm trying to limit the content that is returned via REST API routes to only contain content published by the current logged in user. I'm trying to do this using pre_get_posts which works fine when in ...
0
votes
1answer
160 views

Buddypress update user avatar image via REST

I’m creating a custom back-end API to update a user avatar image via user id. So i send via post REST request this parameters: – user_id : The id of the user; – image: base64 image; – image_name: ...
0
votes
1answer
63 views

phpmailer_init ignored on REST calls

For testing purposes I've set up a mailtrap (dummy SMTP server) to catch all mail in and out of my local site. To do so, I hooked its configuration in the theme's functions.php like this: function ...
0
votes
1answer
18 views

Detect permalinks when passing querystring in REST API requests

Let's say I'm using wp_localize_script to pass base REST url to my script in a Wordpress plugin: wp_register_script( 'my-plugin', plugin_dir_url( __FILE__ ) . '../dist/admin-main.js', [], '0.9.2' ); ...
2
votes
1answer
256 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
2answers
194 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 ...
0
votes
0answers
28 views

woocommerce plugin to query external vendors REST API

All, I am attempting to assist a friend with some research as to how much it efford /cost it would take to start a woocommerce site to sell ATV/Motorcycle parts and accessories. The site would be ...
1
vote
0answers
25 views

Setting/unsetting terms using the Backbone JavaScript client

I'd like to set and delete terms in my custom taxonomy using the WordPress Backbone JavaScript client, which provides access to the REST API in JavaScript. I can't find an example or suggestion in ...