3

I don’t know how to get a specific customer active subscriptions using the Woocommerce API. I have a mobile app which connects to a middle layer, this middle layer needs to provide the list of subscriptions the user has active. I need to know what Woocommerce API endpoint or combination of endpoints I can call to get the user's active subscriptions. Been struggling for days to figure this out. Please help

e.g Using WooCommerce API v1 should return active subscriptions: https://....com/wp-json/wc/v1/subscriptions?customer=1&status=active but it doesn't, a lot of the users have missing active subscriptions.

I have also tried: 1. https://….com/wp-json/wc/v3/memberships/members Though this does return the memberships, it doesn’t provide product ids, etc, with them being null for many of the memberships

“id”: 355,
“customer_id”: 1,
“plan_id”: 430,
“status”: “active”,
“order_id”: null,
“product_id”: null,
“subscription_id”: null,

2. https://….com/wp-json/wc/v3/orders?customer=1 This is also missing subscriptions and other purchases

mujuonly
  • 11,370
  • 5
  • 45
  • 75
cfl
  • 999
  • 1
  • 14
  • 34

3 Answers3

3
/**
 * Register the routes for this class
 *
 * GET /customers/<id>/subscriptions
 *
 * @since 2.0
 * @param array $routes
 * @return array
 */
public function register_routes( $routes ) {
    # GET /customers/<id>/subscriptions
    $routes[ $this->base . '/(?P<id>\d+)/subscriptions' ] = array(
        array( array( $this, 'get_customer_subscriptions' ), WC_API_SERVER::READABLE ),
    );

    return $routes;
}

Your Endpoint should be /customers/<id>/subscriptions - here <id> is customer_id

WCS API function to get all the subscriptions tied to a particular customer.

mujuonly
  • 11,370
  • 5
  • 45
  • 75
  • Thank you, to understand is this something thats already in the code, I can just call it, or did you give the above as an example of what I can add in? Do I just use the same base url as above? – cfl Apr 26 '20 at 07:53
  • @cfl - It's there in the WooCommerce subscriptions API itself.You may just use it – mujuonly Apr 26 '20 at 10:18
  • I get an 404 when calling that, "code": "rest_no_route", "message": "No route was found matching the URL and request method". Im using the same base URL that works with the other calls – cfl Apr 26 '20 at 15:17
  • @cfl Which version of WC Subscription? – mujuonly Apr 26 '20 at 15:20
  • Tried v1 and v3 – cfl Apr 26 '20 at 16:16
  • 1
    Check the Line# 55 /woocommerce-subscriptions/includes/api/legacy/class-wc-api-subscriptions-customers.php – mujuonly Apr 26 '20 at 16:20
  • Awesome thanks, I will try dig to figure that out. A question still remains through, how will the above be different to the https://....com/wp-json/wc/v1/subscriptions?customer=1&status=active – cfl Apr 27 '20 at 10:13
  • It didn't work cause it seems like the wordpress site itself might be setup weirdly, seems like the APIs I call as shown in the issue description is correct. The wordpress site seems to need fixing. Will report back once I figure out – cfl Apr 28 '20 at 13:46
0

You can get active subscriptions using the following way:

/wp-json/wc/v1/subscriptions/<id> //To get particular subscription
/wp-json/wc/v1/subscriptions //To get all subscriptions

You can get more information here: https://prospress.github.io/subscriptions-rest-api-docs/?php#list-all-subscriptions

Let me know if you find it helpful.

Brijesh Dhanani
  • 856
  • 4
  • 12
  • Thank you for your suggestion, but thats what I have already tried, see the issue description. That call is missing subscriptions for some of the users, even though they show active on the actual website. – cfl Apr 23 '20 at 12:05
0

You're probably not looking for this anymore, but I figured I'd clarify the answer since @mujuonly inconveniently left out that it only applies to the Legacy WooCommerce API. Anyway, it's deprecated. but it works for now.

  1. Enable the Legacy API in WooCommerce -> Settings -> Advanced -> Legacy API
  2. Get your access token
  3. Visit https://___.com/wc-api/v3/customers/<customer_id>/subscriptions/

As of right now, I don't see anything like this endpoint supported in the native API. Hopefully it will be added in the near future.

İsmail Y.
  • 3,579
  • 5
  • 21
  • 29
phvntom
  • 1
  • 1