Happy Business Starts Here

Savvy Scholar

Indicate whether a subscription has been invoiced or not via API

Hi,

 

Is there a way to tell via API whether a subscription has been invoiced or not?

 

I was thinking of the InvoiceOwnerId field but it doesn't work because this field is automatically populated when I'm attaching the subscription to an account.

 

Thanks

1 REPLY 1
Highlighted
Zuora Alumni

Re: Indicate whether a subscription has been invoiced or not via API

Hi @gbarak!

 

As you probably figured out, there isn't a direct way to retrieve this this information. I have tested this out and maybe you can give it a try and see whether it suits your needs. It is a little bit clunky, requiring total of 3 API calls.

 

Basically, query a joint object of "Subscription", "InvoiceItem" and "Account", the end result is a list of subcription IDs if these subscriptions have invoiceItem IDs associated with them, meaning invoice had been generated. You can reference the joint object "InvoiceItem" if you're interested querying other fields of the joint objects.

 

 

Call #1

 

Create an "Export" object via "Export ZOQL", you can see in the query, we start by querying a particular account, the object we're interested in would be "Invoice Item". Documentation to the endpoint below is here.

 

POST 

endpoint: 

https://rest.apisandbox.zuora.com/v1/action/create

 

Request body: 

 

{
  "objects": [
    {
		"Format": "csv",
		"Query": "select Subscription.Id from InvoiceItem where Account.Id = '8f4552ccc597e11cec53f19b085b849b'"
    }
  ],
  "type": "Export"
}

Response:

 

 

[
    {
        "Success": true,
        "Id": "2c92c0f963da67f80163db4e7fa2553d"
    }
]

 

 

Call #2

 

Query for the "FileId" from Call #1 above, documentation to this endpoint is here.

 

POST

endpoint: https://rest.apisandbox.zuora.com/v1/action/query

 

Request body:

{
  "queryString": "select FileId from Export where Id =  '2c92c0f963da67f80163db4e7fa2553d'"
}

Response:

{
    "records": [
        {
            "FileId": "2c92c08663da68b40163db4e80980d17",
            "Id": "2c92c0f963da67f80163db4e7fa2553d"
        }
    ],
    "size": 1,
    "done": true
}

Call #3

 

Retrieve results by providing "FileId" from Call #2, documentation to endpoint is here. If there are no IDs in the response, that means no invoice been generated. You can further query the subscripitions in the account to find out exactly which subscriptions do not have invoice generated.

 

GET

endpoint: https://rest.apisandbox.zuora.com/v1/files/2c92c08663da68b40163db4e80980d17

 

Response:

Subscription.Id
8f4552cca6fc880d090ef2f202bd2f38
8f4552cca6fc880d090ef2f202bd2f38
8f4552cca6fc880d090ef2f202bd2f38
8f4552cca6fc880d090ef2f202bd2f38
8f4552cce0408f934c5f21724d7cdff6
8f4552cce0408f934c5f21724d7cdff6
8f4552cce0408f934c5f21724d7cdff6
8f4552cce0408f934c5f21724d7cdff6
8f4552cce0408f934c5f21724d7cdff6
8f4552cce0408f934c5f21724d7cdff6
8f4552cce0408f934c5f21724d7cdff6
8f4552cce0408f934c5f21724d7cdff6
8f4552cce0408f934c5f21724d7cdff6
8f4552cce0408f934c5f21724d7cdff6
8f4552cce0408f934c5f21724d7cdff6
8f4552cc03fe909ac7099986688108bd
8f4552cc03fe909ac7099986688108bd
8f4552cc03fe909ac7099986688108bd
8f4552cc03fe909ac7099986688108bd
8f4552cc03fe909ac7099986688108bd
8f4552cc03fe909ac7099986688108bd

 

Hope this helps, thank you!

 

 

 

 



If you found my answer helpful, please give me a kudo ↑
Help others find answers faster by accepting my post as a solution √

Tags (3)