获取发票集合
适用于:合作伙伴中心 | 由世纪互联运营的合作伙伴中心 | Microsoft Cloud for US Government 合作伙伴中心
如何检索合作伙伴发票的集合。
先决条件
- 合作伙伴中心身份验证中所述的凭据。 此方案支持使用独立应用和 App+User 凭据进行身份验证。
C#
若要获取所有可用发票的集合,请使用 Invoices 属性获取发票操作的接口,然后调用 Get 或 GetAsync 方法检索集合。
若要获取发票的分页集合,请先调用 BuildIndexedQuery 方法,并向其传递页面大小以创建 IQuery 对象。 接下来,使用 Invoices 属性获取发票操作的接口,然后将 IQuery 对象传递给 Query 或 QueryAsync 方法以发送请求并获取第一页。
接下来,使用 Enumerators 属性获取受支持的资源集合枚举器的集合的接口,然后调用 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'-'MM'-'dd'T'HH':'mm':'ss'Z'"),
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 和 办公室 许可证。 大小和偏移量仅考虑旧发票。 对于所有现代商业购买,页面化和偏移将被忽略。
REST 请求
请求语法
方法 | 请求 URI |
---|---|
GET | {baseURL}/v1/invoices?size={size}&offset={offset} HTTP/1.1 |
URI 参数
创建请求时,请使用以下查询参数。
名称 | 类型 | 必需 | 说明 |
---|---|---|---|
大小 | int | 否 | 响应中要返回的发票资源数。 此参数是可选的。 |
offset | int | 否 | 要返回的第一张发票的从零开始的索引。 |
请求标头
有关详细信息,请参阅合作伙伴中心 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: de894e18-f027-4ac0-8b5a-34f0c222af0c
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: 57eb2ca7-755f-450f-9187-eae1e75a0114
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"
}
}
反馈
https://aka.ms/ContentUserFeedback。
即将发布:在整个 2024 年,我们将逐步淘汰作为内容反馈机制的“GitHub 问题”,并将其取代为新的反馈系统。 有关详细信息,请参阅:提交和查看相关反馈