You need to enable JavaScript to run this app. 使用RestSharp调用HubSpot FormsAPI返回NotFound错误问题咨询
优惠活动
大模型
产品
解决方案
定价
更多

使用RestSharp调用HubSpot FormsAPI返回NotFound错误问题咨询

问题修复方案

1. 路径占位符大小写不匹配

RestSharp的URL占位符替换严格区分大小写,你代码中路径写的是{PortalId},但AddUrlSegment传入的key是小写的portalId,导致占位符没有被正确替换,请求路径直接携带{PortalId}字符串,触发404。
修复方法:统一两者的大小写,比如把路径中的占位符改为{portalId}:

var request = new RestRequest("submissions/v3/integration/submit/{portalId}/{formGuid}", Method.POST);

2. 请求体格式不符合接口要求

HubSpot v3表单提交接口不支持直接传递根层级的键值对参数,你需要把字段按照要求封装到fields数组中,主动把参数序列化为JSON放到请求体,不能直接用AddParameter添加表单参数。
修复后的完整请求构造代码如下:

var client = new RestClient("https://api.hsforms.com");
// 统一占位符大小写
var request = new RestRequest("submissions/v3/integration/submit/{portalId}/{formGuid}", Method.POST);

request.AddUrlSegment("portalId", "[myportalid]");
request.AddUrlSegment("formGuid", "[myformid]");
request.AddQueryParameter("hapikey", "[myapikey]");

// 构造符合接口要求的请求体
var postBody = new
{
    fields = new[]
    {
        new { name = "firstname", value = "testfirstname" },
        new { name = "lastname", value = "testlastname" },
        new { name = "email", value = "testemail@emailaddress.com" },
        new { name = "business_unit", value = "Test" }
    }
};
// 直接添加JSON请求体
request.AddJsonBody(postBody);

3. 可选校验项

如果修改后仍然有问题,可以添加以下代码打印最终请求的URL,确认路径和参数是否正确:

var fullUrl = client.BuildUri(request).ToString();
Console.WriteLine(fullUrl);
// 打印出来的URL替换占位符后应该类似:https://api.hsforms.com/submissions/v3/integration/submit/12345/xxxx-xxxx-xxxx?hapikey=yourkey

内容的提问来源于stack exchange,提问作者jpieps

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.20 10:57:03