skip to Main Content

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

3

Answers


  1. 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.

    Login or Signup to reply.
  2. /**
     * 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.

    Login or Signup to reply.
  3. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search