APIs & Integrations

rvaladez
Member

C# RestSharp library Submit a Form Example

This is my Code but is not working, Whats could be the problem??
I´m new in Hubspot integrations

 

var client = new RestClient("https://api.hubapi.com/");
var request = new RestRequest("uploads/form/v2/{PortalId}/{formGuid}", Method.POST);
request.AddUrlSegment("portalId", "miportalId");
request.AddUrlSegment("formGuid", "miformGuid");
request.AddQueryParameter("hapikey", "mihapiKey");

request.AddBody(new
{
    properties = new[]

    {

        new { property = "firstname", value = firstName ?? string.Empty },
        new { property = "lastname", value = lastName ?? string.Empty },
        new { property = "email", value = email },
        new { property = "lifecyclestage", value = stage },
        new { property = "company", value = company },
        new { property = "ubicaci_n", value = stateName },
        new { property = "centro_de_interes", value = locationName },

        new { property = "me_interesa", value = answerInterest },
        new { property = "puesto", value = answerTitle ?? string.Empty }, // Puesto
        new { property = "rea_de_trabajo", value = answerArea ?? string.Empty },
        new { property = "necesito_un_espacio_para", value = answerSpace ?? string.Empty },
        new { property = "dentro_de_cu_nto_tiempo_necesitas_el_espacio_", value = answerTime ?? string.Empty },
        new { property = "tiempo_aproximado_de_contrato", value = answerTimeStay ?? string.Empty }
    }
});

IRestResponse response = client.Execute(request);

 

But i am getting the next response.StatusCode: 0

"StatusCode: 0, Content-Type: , Content-Length: 0)"

Error Exception: {System.PlatformNotSupportedException: Operation is not supported on this platform. at System.Net.SystemWebProxy.GetProxy(Uri destination) at System.Net.ServicePointManager.ProxyAddressIfNecessary(Uri& address, IWebProxy proxy) at System.Net.ServicePointManager.FindServicePoint(Uri address, IWebProxy proxy) at System.Net.HttpWebRequest.get_ServicePoint() at RestSharp.Http.ConfigureWebRequest(String method, Uri url) at RestSharp.Http.PostPutInternal(String method) at RestSharp.Http.AsPost(String httpMethod) at RestSharp.RestClient.DoExecuteAsPost(IHttp http, String method) at RestSharp.RestClient.Execute(IRestRequest request, String httpMethod, Func`3 getResponse)}

Error Message: "Operation is not supported on this platform."

 

 

 

0 Upvotes
6 Replies 6
lscanlan
HubSpot Alumni
HubSpot Alumni

C# RestSharp library Submit a Form Example

Hi @rvaladez,

 

I'm not as familiar with C# but I did want to point out something that could be causing your error. It looks like you're trying to use the form submission endpoint documented here: https://developers.hubspot.com/docs/methods/forms/submit_form. And it also looks like you're trying to submit the request to api.hubapi.com . Our form submission endpoints are actually on a different domain. So that form submission URL is on forms.hubspot.com . Does your request work if you change:

 

var client = new RestClient("https://api.hubapi.com/");

to:

 

var client = new RestClient("https://forms.hubspot.com/");

If not, let me know and I can take another look.

 

Leland Scanlan

HubSpot Developer Support
rvaladez
Member

C# RestSharp library Submit a Form Example

I tried the change, I had not noticed that it was another domain, but the result is still the same error.

I appreciate your help

0 Upvotes
lscanlan
HubSpot Alumni
HubSpot Alumni

C# RestSharp library Submit a Form Example

Hi @rvaladez,

 

I'm trying to understand if this error is getting thrown on our side or if it's something that's happening before it gets to our API. I did a search for that error and a few things come up: link to Google search . A status code 0 sounds like the request was canceled, and so it never made it to our API, which I would tend to think means something is going wrong before the request gets sent. But if I'm misunderstanding, definitely let me know. Could it be that you need to update something in your setup? I'm not sure if that search helps, but there are some GitHub threads that come up there. The top result is a pretty long thread, but I think they found a solution.

 

One other thing that's worth testing here is whether you're getting this error when making API calls to other HubSpot endpoints. If you're not, and this error is only happening for the form submission endpoint, that's something we'll want to look at. But if this is happening whenever you use this code to make any request to a HubSpot API, I'd think it's probably worth looking through that GitHub thread.

 

Leland Scanlan

HubSpot Developer Support
0 Upvotes
rvaladez
Member

C# RestSharp library Submit a Form Example

I understand, I will review my configuration more thoroughly if I am missing something, if the result changes I will let you know.

 

I will also check GitHub.

 

We only need the integration with hubspot with the form submission, we are not currently integrating any other method of your Api.

 

Thank you

0 Upvotes
rvaladez
Member

C# RestSharp library Submit a Form Example

The problem has already been resolved, the problem was caused by an error in a version of the C# RestClient. Once the library was updated to the latest version, the call to hubspot worked correctly.

 

Thank you very much for your help!

 

Regards

0 Upvotes
lscanlan
HubSpot Alumni
HubSpot Alumni

C# RestSharp library Submit a Form Example

That's great, thank you for the follow-up!

Leland Scanlan

HubSpot Developer Support
0 Upvotes