我正在尝试使用 .net HttpClient() 为 Calendly 创建一个 webhook 订阅
https://developer.calendly.com/docs/webhook-subscriptions
我正在尝试将此 Curl 命令转换为 .Net
curl --header "X-TOKEN: <your_token>" --data "url=https://blah.foo/bar&events[]=invitee.created&events[]=invitee.canceled" https://calendly.com/api/v1/hooks
这是我的 .Net 代码:
private static async Task<HttpResponseMessage> PostCreateWebhookSubscription()
{
var client = new HttpClient {BaseAddress = new Uri("https://calendly.com")};
var request = new HttpRequestMessage(HttpMethod.Post, "/api/v1/hooks/");
var keyValues = new List<KeyValuePair<string, string>>
{
new KeyValuePair<string, string>("url",
"https://requestb.in/17ruxqh1&events[]=invitee.created&events[]=invitee.canceled")
};
request.Content = new FormUrlEncodedContent(keyValues);
request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/x-www-form-urlencoded") {CharSet = "UTF-8"};
request.Content.Headers.Add("X-TOKEN", "<my_calendly_token>");
return await client.SendAsync(request);
}
我收到此错误 422 错误,但无法弄清楚要更改哪些内容才能使其正常工作。
收到错误无法处理的实体
{"type":"validation_error","message":"验证失败","errors":{"events":["不能为空"]}}
我能够运行 Curl 命令并且它在同一台机器上运行良好,所以我知道它正在运行。
我创建了一个 .net HttpClient 调用来测试基本令牌,它运行良好。
有什么建议么?