Hi @ramyasam,
Thank you for contacting us, you can use myCred Rest API plugin to achieve what you are looking for.
Thread Starter
ramya
(@ramyasam)
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’)
@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
(@ramyasam)
HI @arsalantariq
I cannot understand it any example code available
@ramyasam,
Here’s the reference to the doc: https://codex.mycred.me/chapter-iv/enhancements/mycred-rest-api/endpoints/ You will have to pass these parameters when making a request.
Screenshot:
Thread Starter
ramya
(@ramyasam)
Thanks @arsalantariq
Any code is available to update user balance/points without a log entry.
@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 );