-1

I have a Laravel application which is consuming WooCommerce Subscriptions REST API. I need to find all active subscriptions for a specific user, which I have only the email (not the ID).

Filtering the subscriptions by the status "active" works fine. However, I can't get the filter by user email to work. When I say user, I mean the user who bought the subscription product. This user is a customer and I could try to use the [Customers] endpoint(https://woocommerce.github.io/woocommerce-rest-api-docs/#list-all-customers), I know, but since the product is a "subscription product", WordPress assigns the "Subscriber" role instead of the "Customer" role to that user. That prevents the user to be listed in the Customers endpoint.

I attempted to use the "filter" parameter when listing the subscriptions, but I could not get it to work. Also, I don't mind making two different calls to achieve what I want, but I would rather make one to speed up my application.

So, here are my questions:

  1. Is it possible to use the filter parameter to filter the subscribers by email? If yes, how?

  2. How do I get to retrieve an subscriber information using WooCommerce API? Are there any options?

  3. Is it reliable to use the billing address in the subscriptions (after I retrieve all active ones)? I mean, the user might change his email later, which would not change the billing address (right?), and this would give the wrong result in my application.

  4. Do you see or suggest any other solution to my problem?

Thanks for your help and time.

1 Answers1

1

Well, I studied the APIs I mentioned a little more and I was able to solve my problem. Here is how I did it, since this might be useful to other people...

I found out that WooCommerce was not returning the subscribers through the customers endpoint because the default value for the role option is customer. Once I provided the role option set to all, combined with the email option, I was able to retrieve only the customer/subscriber I needed. Now, in possession of the customer/subscriber id, I was able to get the active subscriptions using the subscriptions endpoint using the customer option alongside with the status option set to active.

I hope this comes useful to someone some day.