0

I am building a website and trying to pull the data from Wordpress using the WP rest api. On wordpress, the WooCommerce plugin has been added so the user contain more info and I have added additional field using a plugin.

First, how can I get all the user info ? incl. WooCommerce (mostly billing/Shipping) and also all the tother fields I have added using CIMY user extrafield. I am coding in react but I do not really care about the react part.

I am more interested to understand, who WP handle it (endpoint) and a simple example with Postman is enough.

I tried http://xx.yyy.zzz.aaa/wp-json/wp/v2/users/user_id and add the authorization token in the header but it's not working. it keep replying:

{
    "code": "rest_no_route",
    "message": "No route was found matching the URL and request method",
    "data": {
        "status": 404
    }
}

Regards

5
  • Maybe a silly question, but did you replace user_id with the user's ID? Commented Jul 8, 2020 at 3:21
  • Yes I did. I just used user_id as example. For example one login is amartin so I replaced user_id by amartin
    – Seb
    Commented Jul 8, 2020 at 5:03
  • That's not the user ID. That's a username. The user ID is a number. You can see it when retrieving users via the API, or looking in the URL when editing a user in WordPress. Commented Jul 8, 2020 at 5:53
  • @JacobPeattie how do i get this ID ? I thought that the jwt token may have it.
    – Seb
    Commented Jul 8, 2020 at 7:29
  • How are you authenticating the user? This plugin shows that the ID is returned on a successful auth, for example. So check the response of the auth request. Commented Jul 8, 2020 at 8:44

1 Answer 1

0

Since you're using a JWT for the current user (that is logged into WordPress), you can use this endpoint:

/wp/v2/users/me

https://developer.wordpress.org/rest-api/reference/users/#retrieve-a-user-2

You can also check the token to see what claims are available at https://jwt.ms

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.