{"id":20409,"date":"2025-10-30T09:41:48","date_gmt":"2025-10-30T08:41:48","guid":{"rendered":"https:\/\/www.welaunch.io\/en\/?post_type=faq&p=20409"},"modified":"2025-10-30T09:43:08","modified_gmt":"2025-10-30T08:43:08","slug":"using-the-reward-points-rest-api","status":"publish","type":"faq","link":"https:\/\/www.welaunch.io\/en\/knowledge-base\/faq\/using-the-reward-points-rest-api\/","title":{"rendered":"Using the Reward Points REST API"},"content":{"rendered":"
Add reward points to users via a secure REST endpoint exposed by the plugin.<\/p>\n It exposes a REST endpoint that adds reward points<\/strong> to a WooCommerce user and returns the user\u2019s new total. Only authenticated users who can All parameters are required<\/strong> and validated on the server:<\/p>\n Example JSON body<\/strong><\/p>\n Note:<\/em> Yes. If both<\/em> are true: WordPress is multisite and the plugin setting Otherwise, the meta key is:<\/p>\n This matters if you read totals directly from user meta elsewhere.<\/p>\n<\/section>\n No\u2014this endpoint only adds<\/strong> points (requires Not built-in. If you integrate with external systems, implement client-side idempotency (e.g., a unique operation ID) to avoid duplicate awards.<\/p>\n<\/section>\n (or the multisite-aware key if applicable)<\/span><\/li>\n<\/ol>\n<\/section>\nWhat does this API do?<\/h2>\n
\nInternally it reuses the plugin\u2019s manually_add_user_points()<\/code> logic so totals, logs, and hooks behave like a manual admin add.<\/p>\n<\/section>\nWhat is the endpoint?<\/h2>\n
\n
What permissions are required?<\/h2>\n
manage_woocommerce<\/code><\/strong> may call this endpoint (typically Administrators or Shop Managers). Unauthorized requests are rejected.<\/p>\n<\/section>\nWhat request parameters are required?<\/h2>\n
\n\n
\n \nField<\/th>\n Type<\/th>\n Rules<\/th>\n Purpose<\/th>\n<\/tr>\n<\/thead>\n \n user_id<\/code><\/td>\ninteger<\/td>\n Must exist in WordPress<\/td>\n Which user to credit<\/td>\n<\/tr>\n \n points<\/code><\/td>\ninteger<\/td>\n Must be a positive integer (> 0)<\/td>\n How many points to add<\/td>\n<\/tr>\n \n message<\/code><\/td>\nstring<\/td>\n Sanitized server-side ( sanitize_text_field<\/code>)<\/td>\nShown in the points log\/note<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n {\r\n \"user_id\": 123,\r\n \"points\": 250,\r\n \"message\": \"Customer service gesture for delayed shipment\"\r\n}<\/pre>\n<\/section>\nWhat does a successful response look like?<\/h2>\n
{\r\n \"success\": true,\r\n \"user_id\": 123,\r\n \"points_added\": 250,\r\n \"new_total\": 1420,\r\n \"message\": \"Customer service gesture for delayed shipment\"\r\n}<\/pre>\nnew_total<\/code> is read from user meta after the add completes.<\/p>\n<\/section>\nWhat errors might I see?<\/h2>\n
\n\n
\n \nHTTP<\/th>\n Code<\/th>\n When it happens<\/th>\n<\/tr>\n<\/thead>\n \n 400<\/td>\n invalid_user<\/code><\/td>\nuser_id<\/code> is missing\/invalid or the user doesn\u2019t exist<\/td>\n<\/tr>\n\n 400<\/td>\n invalid_points<\/code><\/td>\npoints<\/code> is <= 0<\/code> or missing<\/td>\n<\/tr>\n\n 401<\/td>\n n\/a<\/td>\n Not authenticated<\/td>\n<\/tr>\n \n 403<\/td>\n n\/a<\/td>\n Authenticated but lacks manage_woocommerce<\/code> capability<\/td>\n<\/tr>\n\n 404<\/td>\n n\/a<\/td>\n Route not registered (plugin disabled or API not enabled)<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/section>\n How do I authenticate?<\/h2>\n
\n
user:application-password<\/code>).<\/li>\ncURL example (Application Passwords)<\/h2>\n
curl -X POST \"https:\/\/example.com\/wp-json\/wc-reward-points\/v1\/add-points\" \\\r\n -u \"admin:YOUR-APP-PASSWORD\" \\\r\n -H \"Content-Type: application\/json\" \\\r\n -d '{\"user_id\":123,\"points\":250,\"message\":\"Promo: Spring bonus\"}'<\/pre>\n<\/section>\nPostman\/Insomnia quick setup<\/h2>\n
\n
Content-Type: application\/json<\/code><\/li>\nPHP example (server-side with Application Passwords)<\/h2>\n
<?php\r\n$url = site_url('\/wp-json\/wc-reward-points\/v1\/add-points');\r\n\r\n$resp = wp_remote_post($url, array(\r\n 'headers' => array(\r\n 'Authorization' => 'Basic ' . base64_encode('admin:YOUR-APP-PASSWORD'),\r\n 'Content-Type' => 'application\/json',\r\n ),\r\n 'body' => wp_json_encode(array(\r\n 'user_id' => 123,\r\n 'points' => 100,\r\n 'message' => 'Welcome bonus',\r\n )),\r\n 'timeout' => 20,\r\n));\r\n\r\nif (is_wp_error($resp)) {\r\n error_log($resp->get_error_message());\r\n} else {\r\n $code = wp_remote_retrieve_response_code($resp);\r\n $body = json_decode(wp_remote_retrieve_body($resp), true);\r\n \/\/ Handle $code \/ $body\r\n}<\/pre>\n<\/section>\nWP Nonce + logged-in cookie example (AJAX from wp-admin)<\/h2>\n
fetch('\/wp-json\/wc-reward-points\/v1\/add-points', {\r\n method: 'POST',\r\n credentials: 'include', \/\/ send auth cookies\r\n headers: { 'Content-Type': 'application\/json' },\r\n body: JSON.stringify({ user_id: 123, points: 50, message: 'Manual adjustment' })\r\n}).then(r => r.json()).then(console.log);<\/pre>\ncurrent_user_can('manage_woocommerce')<\/code>), so cookies + a logged-in admin session are sufficient for auth in this context.<\/div>\n<\/section>\nDoes this work on multisite?<\/h2>\n
multisiteSplitPoints<\/code> is enabled, points are stored under a site-specific meta key:<\/p>\nwoocommerce_reward_points_<BLOG_ID><\/pre>\n
woocommerce_reward_points<\/pre>\n
Why might the route be missing (404)?<\/h2>\n
\n
enable<\/code> is false<\/strong> (routes register only when enabled).<\/li>\n\/wp-json<\/code> or POST requests.<\/li>\nWhat happens internally when I call the API?<\/h2>\n
\n
$_POST['userId']<\/code>, $_POST['points']<\/code>, $_POST['text']<\/code>, and $_POST['action']='woocommerce_reward_points_add_points'<\/code>.<\/li>\nWooCommerce_Reward_Points_Earning<\/code> and calls manually_add_user_points()<\/code>.<\/li>\nCan I use it to deduct<\/em> points?<\/h2>\n
points > 0<\/code>). To deduct, create a separate endpoint or extend this one with a safe decrement workflow.<\/p>\n<\/section>\nIs there rate limiting or idempotency?<\/h2>\n
How can I test quickly?<\/h2>\n
\n
enable = true<\/code>).<\/li>\nmanage_woocommerce<\/code>.<\/li>\nget_user_meta(123, 'woocommerce_reward_points', true);<\/pre>\n
Troubleshooting checklist<\/h2>\n
\n
\/wp-json<\/code>.<\/li>\ninvalid_user<\/code>:<\/strong> user_id<\/code> must be an existing WP user.<\/li>\ninvalid_points<\/code>:<\/strong> Use a positive integer.<\/li>\nSecurity best practices<\/h2>\n
\n
message<\/code>.<\/li>\n