Chilkat Online Tools

SQL Server / Zoom API / List billing invoices

Back to Collection Items

-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    DECLARE @iTmp0 int
    -- Important: Do not use nvarchar(max).  See the warning about using nvarchar(max).
    DECLARE @sTmp0 nvarchar(4000)
    -- This example assumes the Chilkat API to have been previously unlocked.
    -- See Global Unlock Sample for sample code.

    DECLARE @http int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.Http', @http OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    DECLARE @success int

    DECLARE @queryParams int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.JsonObject', @queryParams OUT

    EXEC sp_OAMethod @queryParams, 'UpdateString', @success OUT, 'from', '1989-05-07'
    EXEC sp_OAMethod @queryParams, 'UpdateString', @success OUT, 'to', '1989-05-07'

    -- Adds the "Authorization: Bearer <access_token>" header.
    EXEC sp_OASetProperty @http, 'AuthToken', '<access_token>'

    DECLARE @resp int
    EXEC sp_OAMethod @http, 'QuickRequestParams', @resp OUT, 'GET', 'https://api.zoom.us/v2/accounts/:accountId/billing/invoices', @queryParams
    EXEC sp_OAGetProperty @http, 'LastMethodSuccess', @iTmp0 OUT
    IF @iTmp0 = 0
      BEGIN
        EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @http
        EXEC @hr = sp_OADestroy @queryParams
        RETURN
      END

    DECLARE @sbResponseBody int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.StringBuilder', @sbResponseBody OUT

    EXEC sp_OAMethod @resp, 'GetBodySb', @success OUT, @sbResponseBody

    DECLARE @jResp int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.JsonObject', @jResp OUT

    EXEC sp_OAMethod @jResp, 'LoadSb', @success OUT, @sbResponseBody
    EXEC sp_OASetProperty @jResp, 'EmitCompact', 0


    PRINT 'Response Body:'
    EXEC sp_OAMethod @jResp, 'Emit', @sTmp0 OUT
    PRINT @sTmp0

    DECLARE @respStatusCode int
    EXEC sp_OAGetProperty @resp, 'StatusCode', @respStatusCode OUT

    PRINT 'Response Status Code = ' + @respStatusCode
    IF @respStatusCode >= 400
      BEGIN

        PRINT 'Response Header:'
        EXEC sp_OAGetProperty @resp, 'Header', @sTmp0 OUT
        PRINT @sTmp0

        PRINT 'Failed.'
        EXEC @hr = sp_OADestroy @resp

        EXEC @hr = sp_OADestroy @http
        EXEC @hr = sp_OADestroy @queryParams
        EXEC @hr = sp_OADestroy @sbResponseBody
        EXEC @hr = sp_OADestroy @jResp
        RETURN
      END
    EXEC @hr = sp_OADestroy @resp

    -- Sample JSON response:
    -- (Sample code for parsing the JSON response is shown below)

    -- {
    --   "invoices": [
    --     {
    --       "id": "2c92c12348d07e0580",
    --       "invoice_number": "S8INsdf4534000001",
    --       "total_amount": 2039,
    --       "tax_amount": 0,
    --       "balance": 2039,
    --       "due_date": "2020-08-07",
    --       "invoice_date": "2020-08-07",
    --       "target_date": "2020-08-07",
    --       "status": "Draft"
    --     }
    --   ],
    --   "currency": "USD"
    -- }

    -- Sample code for parsing the JSON response...
    -- Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code

    DECLARE @id nvarchar(4000)

    DECLARE @invoice_number nvarchar(4000)

    DECLARE @total_amount int

    DECLARE @tax_amount int

    DECLARE @balance int

    DECLARE @due_date nvarchar(4000)

    DECLARE @invoice_date nvarchar(4000)

    DECLARE @target_date nvarchar(4000)

    DECLARE @status nvarchar(4000)

    DECLARE @v_currency nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @v_currency OUT, 'currency'
    DECLARE @i int
    SELECT @i = 0
    DECLARE @count_i int
    EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_i OUT, 'invoices'
    WHILE @i < @count_i
      BEGIN
        EXEC sp_OASetProperty @jResp, 'I', @i
        EXEC sp_OAMethod @jResp, 'StringOf', @id OUT, 'invoices[i].id'
        EXEC sp_OAMethod @jResp, 'StringOf', @invoice_number OUT, 'invoices[i].invoice_number'
        EXEC sp_OAMethod @jResp, 'IntOf', @total_amount OUT, 'invoices[i].total_amount'
        EXEC sp_OAMethod @jResp, 'IntOf', @tax_amount OUT, 'invoices[i].tax_amount'
        EXEC sp_OAMethod @jResp, 'IntOf', @balance OUT, 'invoices[i].balance'
        EXEC sp_OAMethod @jResp, 'StringOf', @due_date OUT, 'invoices[i].due_date'
        EXEC sp_OAMethod @jResp, 'StringOf', @invoice_date OUT, 'invoices[i].invoice_date'
        EXEC sp_OAMethod @jResp, 'StringOf', @target_date OUT, 'invoices[i].target_date'
        EXEC sp_OAMethod @jResp, 'StringOf', @status OUT, 'invoices[i].status'
        SELECT @i = @i + 1
      END

    EXEC @hr = sp_OADestroy @http
    EXEC @hr = sp_OADestroy @queryParams
    EXEC @hr = sp_OADestroy @sbResponseBody
    EXEC @hr = sp_OADestroy @jResp


END
GO

Curl Command

curl -G -d "from=1989-05-07"
	-d "to=1989-05-07"
	-H "Authorization: Bearer <access_token>"
https://api.zoom.us/v2/accounts/:accountId/billing/invoices

Postman Collection Item JSON

{
  "name": "List billing invoices",
  "request": {
    "method": "GET",
    "header": [
    ],
    "url": {
      "raw": "{{baseUrl}}/accounts/:accountId/billing/invoices?from=1989-05-07&to=1989-05-07",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "accounts",
        ":accountId",
        "billing",
        "invoices"
      ],
      "query": [
        {
          "key": "from",
          "value": "1989-05-07",
          "description": "Start date for the invoice query in `yyyy-mm-dd` format. The date range defined by the “from” and “to” parameters should not exceed one year. The range defined should fall within the past three years.\n"
        },
        {
          "key": "to",
          "value": "1989-05-07",
          "description": "End date for the invoice query in `yyyy-mm-dd` format"
        }
      ],
      "variable": [
        {
          "key": "accountId"
        }
      ]
    },
    "description": "List [invoices](https://support.zoom.us/hc/en-us/articles/207276556-Viewing-your-invoice-history#h_6710542f-23cc-4059-9cc7-ff02bec7314e) of a Zoom account.\n\nTo list a regular Zoom account's invoices or a master account's invoices, provide `me` as the value of the `accountId` path parameter. To list a sub account's invoices, provide the account ID of the sub account in the `accountId` path parameter. \n\n**Prerequisites:**\n* Account must be enrolled in Pro or a higher plan.<br>\n\n**Scope**:`billing:master`<br>**[Rate Limit Label](https://marketplace.zoom.us/docs/api-reference/rate-limits#rate-limits):** `Heavy`<br>\n**Additional Rate Limit:** You can make **one** API request per account(`accountId`) every **five** minutes until the daily limit is reached. This API has a daily limit of **6** requests per account(`accountId`)."
  },
  "response": [
    {
      "name": "**HTTP Status Code:** `200`<br>\nAccount billing invoice information returned.",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "description": "Added as a part of security scheme: oauth2",
            "key": "Authorization",
            "value": "<token>"
          }
        ],
        "url": {
          "raw": "{{baseUrl}}/accounts/:accountId/billing/invoices?from=1989-05-07&to=1989-05-07",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "accounts",
            ":accountId",
            "billing",
            "invoices"
          ],
          "query": [
            {
              "key": "from",
              "value": "1989-05-07"
            },
            {
              "key": "to",
              "value": "1989-05-07"
            }
          ],
          "variable": [
            {
              "key": "accountId"
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n \"invoices\": [\n  {\n   \"id\": \"2c92c12348d07e0580\",\n   \"invoice_number\": \"S8INsdf4534000001\",\n   \"total_amount\": 2039,\n   \"tax_amount\": 0,\n   \"balance\": 2039,\n   \"due_date\": \"2020-08-07\",\n   \"invoice_date\": \"2020-08-07\",\n   \"target_date\": \"2020-08-07\",\n   \"status\": \"Draft\"\n  }\n ],\n \"currency\": \"USD\"\n}"
    },
    {
      "name": "**HTTP Status Code:** `400`<br>\n**Error Code:** `200`<br>\nOnly available for Paid account: {subAccountId}.\n**Error Code:** `2001`<br>\nAccount does not exist: {subAccountId}.",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "description": "Added as a part of security scheme: oauth2",
            "key": "Authorization",
            "value": "<token>"
          }
        ],
        "url": {
          "raw": "{{baseUrl}}/accounts/:accountId/billing/invoices?from=1989-05-07&to=1989-05-07",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "accounts",
            ":accountId",
            "billing",
            "invoices"
          ],
          "query": [
            {
              "key": "from",
              "value": "1989-05-07"
            },
            {
              "key": "to",
              "value": "1989-05-07"
            }
          ],
          "variable": [
            {
              "key": "accountId"
            }
          ]
        }
      },
      "status": "Bad Request",
      "code": 400,
      "_postman_previewlanguage": "text",
      "header": [
        {
          "key": "Content-Type",
          "value": "text/plain"
        }
      ],
      "cookie": [
      ],
      "body": ""
    }
  ]
}