instanceid
Forum Replies Created
-
Forum: Developing with WordPress
In reply to: Search via api for exact match only?Closing this.
Forum: Developing with WordPress
In reply to: Search via api for exact match only?Hey there,
I appreciate the reply. I got it worked out already. After a bunch of research I was able to make this and it works well.add_action( 'rest_api_init', function () { register_rest_route( 'endpoint/v1', 'email/(?P<stringvar>[^/]+)', array( 'methods' => 'GET', 'callback' => 'user_email', 'permission_callback' => function () { return current_user_can('edit_others_posts'); }, ) ); }); function user_email($data) { // Get user by their email address $user = get_user_by( 'email', $data['stringvar']); $userId = $user->ID; $user_data = [$userId, $data['stringvar']]; wp_reset_postdata(); return rest_ensure_response($user_data); }
I will note that the Oauth1 is a different plugin than the Oauth2 plugin.
I wanted to test, so I installed an OAuth2 server plugin. Strangely, I am able to hit that using Postman and I get a <Response: 200 Ok>. It is hitting /oauth/authorize and /oauth/token, but I do have mixed results when trying to do it using Oauth1 and/oauth1/authorize and /oauth1/token from a python application. It works when using the ‘Requests’ package, but not when using ‘Rauth’ trying to hit the same api urls.
- This reply was modified 6 years, 4 months ago by instanceid.
- This reply was modified 6 years, 4 months ago by instanceid.
- This reply was modified 6 years, 4 months ago by instanceid.
Yes sir, I did, I made sure all the other required things I saw in the documentation were on as well.
It looks like if I turn off the perma links and I make a post request with basic auth, the call goes through, but it just shows my main page come up, I don’t see anything about a token or anything like that it looks like it just does nothing. I turn perma links back on, it goes dead again on the wp-json/aam/v1/authenticate url.
I am hosting on Nginx with Virtualmin, the config isn’t anything super crazy, the main thing is this part:
location ~ \.php$ { try_files $uri =404; fastcgi_pass unix:/var/php-nginx/153843814022189.sock/socket; }
Putting the lines in the config that I posed before made the permal links work for the rest of the site (without them it didn’t, all pages but the main page errored out). The only thing that isn’t working in hitting the API to try and post.
If I try to go directly to the url, I get this.
{"code":"rest_no_route","message":"No route was found matching the URL and request method","data":{"status":404}}
I know for sure the entries are there for the route, as here is a screenshot of them. https://i.imgur.com/vTyFYfI.png
I figured since it said there was no route for method of “data” that it might be normal, but I am not sure.
- This reply was modified 6 years, 4 months ago by instanceid.
- This reply was modified 6 years, 4 months ago by instanceid.