共用方式為


取得發票集合

適用於:合作夥伴中心 |由 21Vianet 營運的合作夥伴中心 |美國政府Microsoft雲端合作夥伴中心

如何取得合作夥伴發票的集合。

先決條件

  • 合作夥伴中心驗證中所述的憑證。 此案例支援使用獨立應用程式和 App+使用者認證進行驗證。

C#

若要取得所有可用發票的集合,請使用 Invoices 屬性來取得發票作業的介面,然後呼叫 getGetAsync 方法來擷取集合。

若要取得發票分頁集合,請先呼叫 BuildIndexedQuery 方法,並將頁面大小傳遞給它,以建立 IQuery 物件。 接下來,使用 Invoices 屬性來取得發票作業的介面,然後將 IQuery 物件傳遞至 QueryQueryAsync 方法來傳送要求並取得第一頁。

接下來,使用 列舉器 屬性來取得支援之資源集合列舉器的介面,然後呼叫 Invoices.Create,以建立列舉器來遍歷發票集合。 最後,使用列舉器來擷取和使用發票的每個頁面,如下列程式碼範例所示。 每次呼叫 Next 方法時,都會根據頁面大小傳送下一頁發票的要求。

// IAggregatePartner partnerOperations;
// int invoicePageSize;

// Is this an unpaged or paged request?
bool isUnpaged = (this.invoicePageSize <= 0);

// If the scenario is unpaged, get all the invoices, otherwise get the first page.
var invoicesPage = (isUnpaged)
                 ? partnerOperations.Invoices.Get()
                 : partnerOperations.Invoices.Query(QueryFactory.Instance.BuildIndexedQuery(this.invoicePageSize));

// Create an invoice enumerator for traversing the invoice pages.
var invoicesEnumerator = partnerOperations.Enumerators.Invoices.Create(invoicesPage);
int lineCounter = 1;

while (invoicesEnumerator.HasValue)
{
    // Print the current invoice results page.
    var invoices = invoicesEnumerator.Current.Items;

    foreach (var i in invoices)
    {
        Console.WriteLine(String.Format("{0,3}. {1}  {2}  {3,16:C2}",
            lineCounter++,
            i.Id,
            i.InvoiceDate.ToString("yyyy&#39;-&#39;MM&#39;-&#39;dd&#39;T&#39;HH&#39;:&#39;mm&#39;:&#39;ss&#39;Z&#39;"),
            i.TotalCharges));
    }

    Console.WriteLine();
    Console.Write("Press any key to retrieve the next invoices page");
    Console.ReadKey();

    // Get the next page of invoices.
    invoicesEnumerator.Next();
}

如需稍微不同的範例,請參閱 範例主控台測試應用程式專案:合作夥伴中心 SDK 範例 類別:GetPagedInvoices.cs

注意

相同的 API 用於所有現代商業購買,以及 145p 和 Office 授權。 只有在處理舊版發票時,才會考慮大小和位移。 對於所有現代商業交易,頁面大小 & 偏移將會被忽略。

REST 要求

要求語法

方法 要求 URI
GET {baseURL}/v1/invoices/size={size}&offset={offset} HTTP/1.1
獲取 {baseURL}/v1/invoices?size={size}&offset={offset}&filter={“LeftFilter”:{“Field”:{field},“Value”:{value},“Operator”:{operator}},“RightFilter”:{“Field”:{field},“Value”:{value},“Operator”:{operator}},“Operator”:{operator}} HTTP/1.1

URI 參數

建立要求時,請使用下列查詢參數。

名字 類型 必填 描述
大小 整數 (int) 回應中要傳回的發票資源數目。 這個參數是選擇性的。
抵消 整數 要傳回之第一張發票之以零起始的索引。
過濾器 字串 以文字為基礎的自定義篩選準則,以減少回應中的發票資源。 使用此條件來防止逾時錯誤。 請參閱 如何使用篩選條件

如何使用篩選條件

篩選條件的範例:

/v1/invoices?size=10&offset=0&filter={"LeftFilter":{"Field":"InvoiceDate","Value":"01/01/2023","Operator":"greater_than_or_equals"},"RightFilter":{"Field":"InvoiceDate","Value":"12/31/2023","Operator":"less_than_or_equals"},"Operator":"and"}

若要有效地篩選您的數據,請了解篩選準則的三個主要元件:

  • LeftFilter: 指定篩選表達式左側的欄位、值和運算符,以設定初始條件。
  • 欄位:要用來篩選的屬性
  • 值:屬性的值

例如,"LeftFilter": {"Field":"InvoiceDate","Value":"01/01/2023","Operator":"greater_than_or_equals"} 篩選 2023 年 1 月 1 日或之後的發票。

  • RightFilter: 定義篩選表示式右側的欄位、值和運算符,以完成條件。

例如,"RightFilter":{"Field":"InvoiceDate","Value":"12/31/2023","Operator":"less_than_or_equals"} 篩選 2023 年 12 月 31 日或之前的發票。

  • 操作符: 用邏輯運算符號連接左右篩選條件。 使用「和」或「或」來結合準則。

例如,"Operator": "and" 確保篩選包含符合這兩個條件的發票。

針對單一篩選條件,輸入功能變數名稱、值和運算符,而不需要 “LeftFilter” 或 “RightFilter” 建構。

這種方法可協助您精確且有效率地篩選數據。

要求標頭

如需詳細資訊,請參閱 合作夥伴中心 REST 標頭

請求主體

沒有

要求範例

GET https://api.partnercenter.microsoft.com/v1/invoices?size=200&offset=0 HTTP/1.1
Authorization: Bearer <token>
Accept: application/json
MS-RequestId: e88d014d-ab70-41de-90a0-f7fd1797267d
MS-CorrelationId: aaaa0000-bb11-2222-33cc-444444dddddd
X-Locale: en-US
MS-PartnerCenter-Application: Partner Center .NET SDK Samples
Host: api.partnercenter.microsoft.com

重要

自 2023 年 6 月起,最新的合作夥伴中心 .NET SDK 3.4.0 版現已封存。 您可以從 GitHub下載 SDK 版本,以及包含實用資訊的 自述檔

鼓勵合作夥伴繼續使用 合作夥伴中心 REST API

REST 回應

如果成功,響應主體會包含 發票 資源的集合。

回應成功和錯誤碼

每個回應都有一個 HTTP 狀態代碼,指出成功或失敗和其他偵錯資訊。 使用網路追蹤工具來讀取此程式代碼、錯誤類型和其他參數。 如需完整清單,請參閱 合作夥伴中心 REST 錯誤碼。

回應範例

HTTP/1.1 200 OK
Content-Length: 256
Content-Type: application/json; charset=utf-8
MS-CorrelationId: bbbb1111-cc22-3333-44dd-555555eeeeee
MS-RequestId: a45e6643-1caf-4429-8f90-07c03d85bc2b
Date: Thu, 24 Mar 2016 05:21:01 GMT
{
    "totalCount": 2,
    "items": [
        {
            "id": "D02005YFHI",
            "invoiceDate": "2017-01-21T00:00:00Z",
            "totalCharges": 24606.35,
            "paidAmount": 1000,
            "currencyCode": "GBP",
            "currencySymbol": "£",
            "pdfDownloadLink": "/invoices/D02005YFHI/documents/statement",
            "taxReceipts": [
                {
                    "id": "123456",
                    "taxReceiptPdfDownloadLink": "/invoices/D02005YFHI/receipts/123456/documents/statement"
                }
            ],
            "invoiceDetails": [
                {
                    "invoiceLineItemType": "billing_line_items",
                    "billingProvider": "office",
                    "links": {
                        "self": {
                            "uri": "/invoices/Recurring-D02005YFHI/lineitems/Office/BillingLineItems",
                            "method": "GET",
                            "headers": []
                        }
                    },
                    "attributes": {
                        "objectType": "InvoiceDetail"
                    }
                }
            ],
            "documentType": "invoice",
            "invoiceType": "Recurring",
            "links": {
                "self": {
                    "uri": "/invoices/Recurring-D02005YFHI",
                    "method": "GET",
                    "headers": []
                }
            },
            "attributes": {
                "objectType": "Invoice"
            }
        },
        {
            "id": "G000024130",
            "invoiceDate": "2018-02-08T01:22:47.603895Z",
            "totalCharges": 586366,
            "paidAmount": 0,
            "currencyCode": "CHF",
            "currencySymbol": "CHF",
            "pdfDownloadLink": "/invoices/G000024130/documents/statement",
            "taxReceipts": [
                {
                    "id": "234567",
                    "taxReceiptPdfDownloadLink": "/invoices/G000024130/receipts/234567/documents/statement"
                }
            ],
            "invoiceDetails": [
                {
                    "invoiceLineItemType": "billing_line_items",
                    "billingProvider": "one_time",
                    "links": {
                        "self": {
                            "uri": "/invoices/OneTime-G000024130/lineitems/OneTime/BillingLineItems",
                            "method": "GET",
                            "headers": []
                        }
                    },
                    "attributes": {
                        "objectType": "InvoiceDetail"
                    }
                }
            ],
            "amendments": [
                {
                    "id": "G000024131",
                    "invoiceDate": "2018-02-08T18:44:37.5381456Z",
                    "totalCharges": 107661.12,
                    "paidAmount": 0,
                    "currencyCode": "CHF",
                    "currencySymbol": "CHF",
                    "invoiceDetails": [
                        {
                            "invoiceLineItemType": "billing_line_items",
                            "billingProvider": "one_time",
                            "attributes": {
                                "objectType": "InvoiceDetail"
                            }
                        }
                    ],
                    "documentType": "adjustment_note",
                    "amendsOf": "G000024130",
                    "invoiceType": "OneTime",
                    "attributes": {
                        "objectType": "Invoice"
                    }
                }
            ],
            "documentType": "void_note",
            "invoiceType": "OneTime",
            "links": {
                "self": {
                    "uri": "/invoices/OneTime-G000024130",
                    "method": "GET",
                    "headers": []
                }
            },
            "attributes": {
                "objectType": "Invoice"
            }
        }
    ],
    "links": {
        "self": {
            "uri": "/invoices?size=2&offset=0",
            "method": "GET",
            "headers": []
        },
        "next": {
            "uri": "/invoices?size=2&offset=2",
            "method": "GET",
            "headers": []
        }
    },
    "attributes": {
        "objectType": "Collection"
    }
}