Office 脚本界面错误Excel 网页版

问题描述

我正在尝试从 Web 上的 Excel 调用外部 API (https://api.fortnox.se/3/customers/2)。

我正在调用的 Web API 会返回一个 jason 数据结构,例如此处“检索客户”会话下的“响应”:https://developer.fortnox.se/documentation/resources/customers/

响应数据结构:

{
    "Customer": {
        "@url": "https://api.fortnox.se/3/customers/102","Active": true,"Address1": "Halltorpsgatan","Address2": null,"City": "KLIPPAN","Comments": null,"CostCenter": null,"Country": "Sverige","CountryCode": "SE","Currency": "SEK","CustomerNumber": "102","DefaultDeliveryTypes": {
            "Invoice": "PRINT","Offer": "PRINT","Order": "PRINT"
        },"DefaultTemplates": {
            "CashInvoice": "DEFAULTTEMPLATE","Invoice": "DEFAULTTEMPLATE","Offer": "DEFAULTTEMPLATE","Order": "DEFAULTTEMPLATE"
        },"DeliveryAddress1": null,"DeliveryAddress2": null,"DeliveryCity": null,"DeliveryCountry": null,"DeliveryCountryCode": null,"DeliveryFax": null,"DeliveryName": null,"DeliveryPhone1": null,"DeliveryPhone2": null,"DeliveryZipCode": null,"Email": "[email protected]","EmailInvoice": "[email protected]","EmailInvoiceBCC": "","EmailInvoiceCC": "","EmailOffer": "[email protected]","EmailOfferBCC": "","EmailOfferCC": "","EmailOrder": "[email protected]","EmailOrderBCC": "","EmailOrderCC": "","Fax": null,"GLN": null,"GLNDelivery": null,"InvoiceAdministrationFee": null,"InvoiceDiscount": null,"InvoiceFreight": null,"InvoiceRemark": "","Name": "Anders Svensson","OrganisationNumber": "","OurReference": "","Phone1": "0435-9249236","Phone2": null,"PriceList": "A","Project": "","SalesAccount": null,"ShowPriceVATIncluded": false,"TermsOfDelivery": "","TermsOfPayment": "","Type": "PRIVATE","VATNumber": "","VATType": "SEVAT","VisitingAddress": null,"VisitingCity": null,"VisitingCountry": null,"VisitingCountryCode": null,"VisitingZipCode": null,"WWW": "","WayOfDelivery": "","YourReference": "","ZipCode": "264 32"
    }
}

受此处 Stackoverflow 帖子的启发:Fetch error on Office Script (Excel on web) 我编写了以下代码:

interface aCustomer {
  Customer: CustomerClass;
}

interface CustomerClass {
  Address1: string;
  Country: string;
}

async function main(workbook: ExcelScript.Workbook): Promise<void> {
  let response = await fetch("https://api.fortnox.se/3/customers/2",{
    method: "GET",mode: "no-cors",headers: {
      "Access-Token": "XXXX","Client-Secret": "XXXX","Content-Type": "application/json","Accept": "application/json"
    }
  });
  let customer2: aCustomer = await response.json();
  console.log(customer2);
}

但是当我运行它时,它一直抛出错误:“第 21 行:输入的意外结束

第 21 行:让 customer2:Customer = await response.json()

我想我定义了一个错误的接口,或者不知道可能是什么问题?谢谢!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)