0

我尝试在 asp.net 核心 API 项目中使用 easy post 创建一个简单的 post webhook。它在 webhook 创建中返回一个空值。

我试过这个

using EasyPost;
EasyPost.ClientManager.SetCurrent("<YOUR_TEST/PRODUCTION_API_KEY>");

Webhook webhook = Webhook.Create(
    new Dictionary<string, object>() {
        { "url", "https://www.foobar.com" }
    }
);

4

1 回答 1

0

通过使用最新版本的C# 客户端库,我能够让 webhook create 方法正确返回 JSON 。这是我使用的代码片段:

using System;
using System.Collections.Generic;
using EasyPost;
using Newtonsoft.Json;

namespace create_webhook
{
    class createWebhook
    {
        static void Main(string[] args)
        {
            EasyPost.ClientManager.SetCurrent(Environment.GetEnvironmentVariable("EASYPOST_API_KEY"));

            Webhook webhook = Webhook.Create(
                new Dictionary<string, object>() {
                    { "url", "https://www.foobar.com" }
                }
            );
            Console.WriteLine(JsonConvert.SerializeObject(webhook, Formatting.Indented));
        }
    }
}

回复:

{
  "id": "hook_123...",
  "mode": "test",
  "url": "https://www.foobar.com",
  "disabled_at": null
}

作为参考,与为 C# 创建 webhook 相关的API 文档没有特别提到要打印返回的内容,这就是为什么在我的示例中添加了打印语句的原因。

于 2020-09-12T20:20:50.257 回答