【问题标题】:Data from logic app to function and send to Fortnox api从逻辑应用程序到功能并发送到 Fortnox api 的数据
【发布时间】:2021-12-19 02:11:56
【问题描述】:

在逻辑应用中我有 json 数据:

{
  "amount": "116159.90",

  "date": "2021-11-04",

  "fee": "3412.30"
}

第 1 步: 我想将此数据发送到 azure 函数

第 2 步: 我想输入 json 数据(金额、日期和费用),所以我可以将它作为 C# 代码发送到 api 端点,所以它看起来像下面的代码。其余数据是硬编码的。

在此处查看文档(创建凭证 C#)https://developer.fortnox.se/documentation/resources/vouchers/


VoucherConnector connector = new VoucherConnector();
List<VoucherRow> rows = new List<VoucherRow>();

rows.Add(new VoucherRow() {

    Account = "2480",
    Description = "Checkräkningskredit, kortfristig",
    **Debit = "AMOUNT",**
    Credit = "0"
});

rows.Add(new VoucherRow() {

    Account = "6092",
    Description = "Shopify Fee",
    **Debit = "FEE",**
    Credit = "0"
});

rows.Add(new VoucherRow() {

    Account = "1509",
    Description = "Shopify fordran",
    Debit = "0",
    **Credit = "(=AMOUNT+FEE)"**
});

Voucher result = connector.Create(new Voucher() {

    ****TransactionDate = "DATE",****
    Description = "Inbetalning Shopify",
    VoucherRows = rows,
    VoucherSeries = "A"
});

【问题讨论】:

  • 从您的问题来看,尚不清楚您在流程的哪个具体部分遇到了困难。
  • 因为数据是位于逻辑应用程序中的 json 格式,所以我的问题是如何使 json 数据可供函数使用,因为代码在 C# 中,所有代码都已经完成后,我只需要知道如何将数据放入相应的凭证行中,如上面的描述。逻辑应用按计划运行,因此每次运行都会有不同的数据。

标签: c# json api azure-functions azure-logic-apps


【解决方案1】:

您有以下问题:

因为数据是位于逻辑应用程序中的 json 格式,所以我的 问题是如何让函数可以访问 json 数据

通过查看您的 JSON 数据,您只需传递 3 个值:金额、日期和费用。您真的必须以 JSON 格式传递这些数据。例如。您可以通过查询字符串将其发送到您的 API 端点:

https://example.com/over/there?amount=116159.90&amp;date=2021-11-04&amp;fee=3412.30

然后您可以轻松地从HttpRequest 对象中获取它们:

string date = req.Query["date"];

如果您确实想在请求正文中将 JSON 数据发送到您的 API 端点,您可以使用 Newtonsoft.Json NuGet 到 deserialize 它:

string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
dynamic data = JsonConvert.DeserializeObject(requestBody);
string date = data?.date;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-04-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-09
    • 2013-04-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多