Title: Get Points Balance Using API
Last modified: March 29, 2022

---

# Get Points Balance Using API

 *  Resolved [ramya](https://wordpress.org/support/users/ramyasam/)
 * (@ramyasam)
 * [4 years, 2 months ago](https://wordpress.org/support/topic/get-points-balance-using-api/)
 * Hi, How can I get user points using API?
 * I Have two sites on one site I using mycred, How to display the balance on 2nd
   site by fetching the points from site 1.
 * Thanks in advance,

Viewing 7 replies - 1 through 7 (of 7 total)

 *  [A.Tariq](https://wordpress.org/support/users/arsalantariq/)
 * (@arsalantariq)
 * [4 years, 2 months ago](https://wordpress.org/support/topic/get-points-balance-using-api/#post-15510438)
 * Hi [@ramyasam](https://wordpress.org/support/users/ramyasam/),
 * Thank you for contacting us, you can use [myCred Rest API](https://mycred.me/store/mycred-rest-api/)
   plugin to achieve what you are looking for.
 *  Thread Starter [ramya](https://wordpress.org/support/users/ramyasam/)
 * (@ramyasam)
 * [4 years, 2 months ago](https://wordpress.org/support/topic/get-points-balance-using-api/#post-15511480)
 * Yes, I read out the API documentation but there are no clear examples of how 
   to use it and searched online for examples but nothing was found.
 * Please, give some examples
    What I need is 1. check the user if exists if not
   return a message ‘no account founds’ 2. Display the current balance
 *     ```
       function wpb_api(){ 
       $current_user = wp_get_current_user();
       $mail = $current_user->user_email;
   
       $secret_key = '*****kjmsJvT';
       $remote_url = 'https://example.com/api-dev/';
   
       $action     = 'GET';
       $account    = '$mail';
       $point_type = 'mycred_default';
       $host       = get_bloginfo( 'url' );
       $token      = md5( $host . $action . $secret_key );
   
       $request    = array(
       	'method' => 'POST',
       	'body'   => array(
       		'action'  => $action,
       		'account' => $account,
       		'type'    => $point_type,
       		'token'   => $token,
       		'host'    => $host
       	)
       );
       $response = wp_remote_post( $remote_url, $request );
   
       $balance_html = wp_remote_retrieve_body( $response );
   
       echo $balance_html;
   
       } 
   
       add_shortcode('api-test','wpb_api');
       ```
   
 * This shortcode returns the current user balance. This shortcode is correct to
   use or not and how to return the message (check the user if exists if not return
   a message ‘no account founds’)
 *  [A.Tariq](https://wordpress.org/support/users/arsalantariq/)
 * (@arsalantariq)
 * [4 years, 2 months ago](https://wordpress.org/support/topic/get-points-balance-using-api/#post-15517797)
 * [@ramyasam](https://wordpress.org/support/users/ramyasam/),
 * If the user does not exist you will get 0 value. Furthermore, you need to pass
   get in type parameter to get the users balance.
 *  Thread Starter [ramya](https://wordpress.org/support/users/ramyasam/)
 * (@ramyasam)
 * [4 years, 2 months ago](https://wordpress.org/support/topic/get-points-balance-using-api/#post-15518665)
 * HI [@arsalantariq](https://wordpress.org/support/users/arsalantariq/)
 * I cannot understand it any example code available
 *  [A.Tariq](https://wordpress.org/support/users/arsalantariq/)
 * (@arsalantariq)
 * [4 years, 2 months ago](https://wordpress.org/support/topic/get-points-balance-using-api/#post-15526946)
 * [@ramyasam](https://wordpress.org/support/users/ramyasam/),
 * Here’s the reference to the doc: [https://codex.mycred.me/chapter-iv/enhancements/mycred-rest-api/endpoints/](https://codex.mycred.me/chapter-iv/enhancements/mycred-rest-api/endpoints/)
   You will have to pass these parameters when making a request.
 * [Screenshot](https://www.awesomescreenshot.com/image/25210391?key=dd7b713f4c437150168d48061413bc0a):
 *  Thread Starter [ramya](https://wordpress.org/support/users/ramyasam/)
 * (@ramyasam)
 * [4 years, 2 months ago](https://wordpress.org/support/topic/get-points-balance-using-api/#post-15532938)
 * Thanks [@arsalantariq](https://wordpress.org/support/users/arsalantariq/)
 * Any code is available to update user balance/points without a log entry.
 *  [A.Tariq](https://wordpress.org/support/users/arsalantariq/)
 * (@arsalantariq)
 * [4 years, 2 months ago](https://wordpress.org/support/topic/get-points-balance-using-api/#post-15537015)
 * [@ramyasam](https://wordpress.org/support/users/ramyasam/),
 * Below shared code will update the user’s current balance.
 *     ```
       $mycred = mycred( 'mycred_default' );
       $user_id = 1;
       $amount =20;
       $mycred->update_users_balance( $user_id, $amount );
       ```
   

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Get Points Balance Using API’ is closed to new replies.

 * ![](https://ps.w.org/mycred/assets/icon-128x128.gif?rev=3512531)
 * [Points Management System For Gamification, Ranks, Badges, and Loyalty Rewards Program - myCred](https://wordpress.org/plugins/mycred/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/mycred/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/mycred/)
 * [Active Topics](https://wordpress.org/support/plugin/mycred/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/mycred/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/mycred/reviews/)

## Tags

 * [api](https://wordpress.org/support/topic-tag/api/)

 * 7 replies
 * 2 participants
 * Last reply from: [A.Tariq](https://wordpress.org/support/users/arsalantariq/)
 * Last activity: [4 years, 2 months ago](https://wordpress.org/support/topic/get-points-balance-using-api/#post-15537015)
 * Status: resolved