最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

users - Get UserInfo from Wordpress

programmeradmin0浏览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 /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

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

Share Improve this question asked Jul 8, 2020 at 2:26 SebSeb 1091 silver badge3 bronze badges 5
  • Maybe a silly question, but did you replace user_id with the user's ID? – Jacob Peattie 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. – Jacob Peattie 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. – Jacob Peattie Commented Jul 8, 2020 at 8:44
Add a comment  | 

1 Answer 1

Reset to default 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

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论