How to retrieve filtered invoice Via API

haythemhaythem Member Posts: 2

Hi there,

I want to get the invoices from a certain date at the moment I have to get all of them is there a way to add a filter to the call?

this the query im using at the moment :
{"query" : "query { business(id: company_id) { name phone isPersonal invoices { edges { node { internalId createdAt modifiedAt memo customer { internalId firstName lastName email mobile phone fax address{ addressLine1 addressLine2 city postalCode }shippingDetails { name phone address{ addressLine1 addressLine2 city postalCode }} } items{ quantity } }}}}}"}

Tagged:

Comments

  • RobVGRobVG Member Posts: 53 admin

    Hi @haythem,

    To fetch the invoices that have a specific invoice date, you can use the invoiceDateStart and invoiceDateEnd arguments from the invoices field of a Business type. invoiceDateStart filters for invoices dated on or after the provided date. invoiceDateEnd filters for invoices dated before or on the provided date. So used together, you can narrow it down to a single date. Be aware of pagination too.

    Query:

    query ListInvoicesForDate ($businessId: ID!, $page: Int!, $invoiceDate: Date!) {
      business(id: $businessId) {
        id
        name
        invoices(page: $page, pageSize: 20, invoiceDateStart: $invoiceDate, invoiceDateEnd: $invoiceDate) {
          pageInfo {
            currentPage
            totalPages
            totalCount
          }
          edges {
            node {
              id
              invoiceDate
            }
          }
        }
      }
    }
    

    Variables:

    {
      "businessId": "...replace with your id...",
      "page": 1,
      "invoiceDate": "2020-04-14"
    }
    

    Hope that helps :smiley:

    edited April 14, 2020
  • haythemhaythem Member Posts: 2

    Hi @RobVG,

    Thank you for your help,

    It worked :)

    Regards
    Haythem

Sign In or Register to comment.