I solved my problem.
This got me on the right track:
https://developer.wordpress.org/rest-api/using-the-rest-api/authentication/
You can just make an api call via frontend and jquery.
$.ajax( {
url: '<?php echo esc_url_raw( rest_url()) ?>' + 'your/endpoint',
method: 'GET',
beforeSend: function ( xhr ) {
xhr.setRequestHeader( 'X-WP-Nonce', '<?php echo wp_create_nonce( 'wp_rest')?>' );
}
} ).done( function ( response ) {
console.log( response );
} );
If you want to outsource the script in an separate file you have to use wp_localize_script
to pass the url base address and the nonce.
Related Posts:
- How to: Make JWT-authenticated requests to the WordPress API
- WordPress Rest API: How do we validate with our custom API key?
- How to Authenticate WP REST API with JWT Authentication using Fetch API
- authentication issue with rest api – rest_cannot_create
- Can I authenticate with both WooCommerce consumer key and JWT?
- WP REST API: check if user is logged in
- How to login to WordPress site using basic authentication HTTP headers?
- Can we access the REST request parameters from within the permission_callback to enforce a 401 by returning false?
- WordPress REST API “rest_authentication_errors” doesn’t work external queries?
- Can’t GET draft posts via REST API from headless frontend
- Create Session with JWT
- WP REST API GET Requests require authentication
- current_user_can(‘administrator’) returns false when I’m logged in
- Authenticating with REST API
- Make authorization mandatory on custom routes
- WP REST API – Nonce passes wp_verify_nonce even after logout
- How to force JWT auth for default GET endpoints of WordPress rest api?
- REST API: best place to set current user for JWT auth?
- WordPress + REST API v2 and private pages Load by slug
- REST API authentication for a plugin
- PHP: authenticate for a REST request?
- Rest API basic auth not working
- Rest API: wp_verify_nonce() fails despite receiving correct nonce value
- Getting 401 from ajax using an application password
- How to connect android app with WordPress website?
- WordPress REST API calls that depend on the WordPress User
- WordPress HTTP API NTLM Authentication
- Advanced Access Manager: RESTful endpoint to refresh token
- Best Authetication between REST API and Mobile App
- Log in user using WordPress REST API
- Secure WordPress API, how?
- wp_nonce vs jwt
- register/login api
- How can I secure my custom rest api endpoint or add under a already existing rest group
- Register rest field authentication with REST API
- REST API Integration without user account?
- WP REST API with Basic Auth at target website
- Cant POST with REST API on WordPress
- REST API – Authentication/Logon security
- custom REST endpoints and application passwords
- wordpress rest api authentication failed
- How to use OAuth authentication with REST API via CURL commands?
- WordPress REST API validation
- Adding WordPress API Endpoint With Multiple Parameters
- WordPress REST API call generates nonce twice on every call
- Match REST API post output from custom endpoint
- How to change user avatar using REST API?
- x-wp-nonce is not allowed by Access-Control-Allow-Headers in preflight response
- How to get around WP REST API per page limit without pagination?
- Build on same WordPress or different install?
- Testing custom API endpoint with class dependency
- Not all featured image sizes available in Rest API
- 403 Forbidden with gutenberg
- Detect if REST API is running
- Using pre_get_posts, how to target the REST API, only?
- Save/update post_meta with Gutenberg from the panel
- Set featured image using URL with wp rest api
- How to block all REST API endpoint except which I wrote custom?
- Authentication with internal WP_REST_Request and rest_do_request()
- Confused about AngularJS and WordPress
- Post API tax_relation field doesn’t work
- Cannot DIsplay a Snackbar Notice on Button Click – Notice is undefined
- How to post an unserialized array via wordpress rest API as meta data
- Custom Post Type and Custom REST API Endpoint result in Gutenberg editor not working
- rest_sanitize_value_from_schema doesn’t sanitize string
- Erratic OAuth 1.0 Signature Mismatch Errors
- WordPress Rest API custom endpoint for RSS feed
- How to add a custom REST field to limit data when fetching?
- WordPress JSON data to and from database to be shown on rest point
- “No Access-Control-Allow-Origin header is present” even though it is in the entry file
- How can I authenticate user credentials against a WordPress instance?
- rest api request including meta_query filter
- Filter DELETE REST API calls
- REST API: wp_get_current_user not working on second call
- How to send the body in wp_remote_post as “raw”?
- REST API and filtering by meta value
- Custom Endpoints not working
- Is there a way I can fetch the WordPress Developer Code References with an API?
- Pull in ALL posts from the last two weeks using Rest API
- Extending REST API responses
- 403 error when publishing a post in wordpress. Error => Publishing failed. The response is not a valid JSON response
- Cannot use WordPress Application Passwords: “code”: “rest_no_route” “status”:404 for /wp-json/wp/v2/users/me/application-passwords
- How to add Relations of a CCT from JetEngine via WordPress Rest API
- WP REST API returns empty posts despite entries in wp_posts
- How to add taxonomy to a post using WP REST API?
- The REST API encountered an error in wordpress?
- Do something when publish a post in Gutenberg with hook rest_after_insert_post
- Uploading picture via REST API
- How to modify the HTML output of Gutenberg block? (Youtube)
- Can I use REST API if the site is protected with .htpasswd
- Calling a python script from custom wordpress rest api returns null
- Autotrader API Integration
- Accessing secure endpoint with X-WP-Nonce?
- Return all custom taxonomy terms for post in REST API v2? Currently limited to 10 terms
- WP Rest API V2 OR Operator in URL
- Call to undefined function upload_is_user_over_quota()
- Rest api request throttling
- Properly process a custom WP REST API request (Authenticate, Authorize + Validate)?
- Script tag in string in wordpress rest api body to create post
- Customizer Changeset, Sidebar and Rest API Custom Endpoints