recurly/recurly-client-java

Please add missing site_id parameter for methods: listAccountSubscription() and listAccountTransactions()

RomanRadko opened this issue · 6 comments

Description

According to the latest documentation for listAccountSubscriptions() method: https://developers.recurly.com/api/v2019-10-10/index.html#operation/list_account_subscriptions
site_id parameter is missing.
The same issue with listAccountTransactions(), listAccountCreditPayments() and listAccountInvoices() methods.

To Reproduce

Run listAccountSubscriptions() and see that there is no data in pager even for right account_id.

Expected behavior

Subscriptions list should be present.

Your Environment

lib version: 3.3.0
java version: 1.8

bhelx commented

@RomanRadko the clients use a different set of routes that aren't publicly documented. For each route in the V3 API, there is an equivalent route without the /sites/{site_id} prefix. These routes use the API key to infer the site id (as the API key is unique to the site). The clients use these routes and thus side id is not required since it's derivable from the Client and API key.

In order to call the API on different sites, create 1 client per site. Example:

final Client devSite = new Client(devApiKey);
final Client prodSite = new Client(prodApiKey);

With regards to records not being present, are you sure you are using the right API key? Could you share some code? We cannot seem to reproduce this problem.

Hi @bhelx , thank you for a quick answer. Ok, I see your point related to the site_id. Yes, I created one client per site, and here is the code I am using to get subscription of the specified account:

    //Here is a way to check subscription status for the client
    @SuppressLint("CheckResult")
    private fun testListAccountSubscriptions() {
        val params = QueryParams()
        params.setLimit(200)
        Single.fromCallable {
            Client(PRIVATE_API_KEY).listAccountSubscriptions("code-account111", params)
        }
            .observeOn(Schedulers.io())
            .subscribeOn(AndroidSchedulers.mainThread())
            .subscribe({
                Log.d(TAG, "Result :: $it")
            },
                {
                    Log.e(TAG, "Error :: $it")
                    Toast.makeText(this, "Failed to load.", Toast.LENGTH_LONG)
                        .show()
                })
    }

As the result I see empty pager with no data in:
image
I did a double check on the console, and for this account I definately have one subscription.

bhelx commented

@RomanRadko Thanks for all the detail. I'm not so familiar with RXJava, but I think there are a couple facts that might help you here:

First, all the list* methods do not actually make any HTTP requests. They return immediately with a Pager. The Pager is like a reference, or a query, to some records on our server. to actually get those records, you must iterate over the pager. It will call the server as many times as it needs while still presenting you with an Iterator interface. See the pagination docs to see what i mean: https://github.com/recurly/recurly-client-java#pagination . I'm not sure how to make this work in for you in RX. Perhaps there is some way to make an observerable from the iterator?

Second, a small detail, make sure you are reusing the client as much as possible. Creating a client opens up a connection to our server. Although it's simpler to create a new client every time, re-using them as much as possible will help with performance.

Let me know if that helps, if not we can try to dig deeper into what is going on.

Hey @bhelx , I am found the mistake I made. I was thinking list* methods doing a requests 🤦‍♂ So, all works like it should, and there is no any bug, sorry for confusing.
Yeah, I did new api Client creation just for an example, so in my test app I will reuse it as much as possible.
This issue should be closed. Thanks for the support 👍

bhelx commented

Good to know, any time!