Get invoice

KarskipKarskip Member Posts: 3

Hi

I am wanting to create an API to get all invoices for a specific customer.

At the moment I only have the example version which is no good as its all in pages and shows all invoices so I would have to loop through each one on each page which is not good.

I have tried a few different things but it does not seem to work. Does anyone have a running GraphQL example of how I can do this

Thanks.
Chris

Comments

  • PaulCPaulC Member Posts: 186 ✭✭✭

    Hello @Karskip ,

    The example query is the right place to start. Depending upon how many invoices you have, you're going to have to come to terms with paging.

    You can certainly filter invoices by customer. First, you'll need to get the CustomerId you want, then you can modify your query as follows (relative to the documented example):

    1. At line 1, declare another variable, so query($businessId: ID!, $page: Int!, $pageSize: Int!) becomes query($businessId: ID!, $page: Int!, $pageSize: Int!, $customerId: ID!)
    2. At line 5, add the customer filter condition, so invoices(page: $page, pageSize: $pageSize) becomes invoices(page: $page, pageSize: $pageSize, customerId: $customerId)
    3. In your variables, pass the required customerId (add in "customerId": "<CUSTOMER_ID>",).

    Hope that helps.

    edited November 2, 2020
  • KarskipKarskip Member Posts: 3

    You are a star. Simple as that.

    Thank you so much

Sign In or Register to comment.