# Hubspot form API \[RESOLVED\]

**URL:** <https://community.hubspot.com/t/hubspot-form-api-resolved/15763>\
**Category:** APIs & Integrations\
**Tags:** forms\
**Created:** [August 15, 2019, 10:05am UTC](https://community.hubspot.com/t/hubspot-form-api-resolved/15763 "2019-08-15T10:05:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/system/32/124_2.png) [@system](https://community.hubspot.com/u/system)\
**Post date:** [August 15, 2019, 10:05am UTC](https://community.hubspot.com/t/hubspot-form-api-resolved/15763/1 "2019-08-15T10:05:13Z")

</div>

I’m trying to use api form ([https://developers.hubspot.com/docs/methods/forms/submit\_form\_v3](https://developers.hubspot.com/docs/methods/forms/submit_form_v3)) on my site , but I get this error, HTTP ERROR 405  
Problem accessing / submissions / v3 / integration / submit / XXX / xxxxxx. Reason: Method Not Allowed

```auto
 var request = $.ajax({ 
 url: "https://api.hsforms.com/submissions/v3/integration/submit/MyPportalid/FormId", 
 method: "POST",
 data: { 
 "fields": [
 {
 "name": "firstname",
 "value": firstname
 },
 {
 "name": "lastname",
 "value": lastname
 },
 {
 "name": "email",
 "value": email
 },
 {
 "name": "phone",
 "value": phone
 },
 {
 "name": "company",
 "value": company
 },
 {
 "name": "dataMessage",
 "value": dataMessage
 }
 ],
 "context": {
 "hutk": ":"+hubspotutk, 
 "pageUri": pageUrl,
 "pageName": pageName
 } ,
 "legalConsentOptions": {
 "consent": { 
 "consentToProcess": true,
 "text": "I agree to allow Example Company to store and process my personal data.",
 "communications": [
 {
 "value": true,
 "subscriptionTypeId": 999,
 "text": "I agree to receive marketing communications from Example Company."
 }
 ]
 }
 }
 },
 dataType: "json"
 });

 request.done(function(msg) {
 console.log( "success "+msg );
 })
 .fail(function(msg) {
 console.log( "error "+msg );
 })
 .always(function(msg) {
 console.log( "complete "+msg );
 });

```

The method is in POST, why i get that message ?

---

<div class="post-metadata">

**Author:** ![WendyGoh](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/wendygoh/32/42320_2.png) [@WendyGoh](https://community.hubspot.com/u/WendyGoh)\
**Post date:** [August 16, 2019, 6:48am UTC](https://community.hubspot.com/t/hubspot-form-api-resolved/15763/2 "2019-08-16T06:48:17Z")

</div>

Hi [@francobolla](https://community.hubspot.com/t5/user/viewprofilepage/user-id/102634),

I hope all is well with you 😃

When looking to submit a form using ajax, we can look at the endpoint here: [https://developers.hubspot.com/docs/methods/forms/submit\_form\_v3](https://developers.hubspot.com/docs/methods/forms/submit_form_v3)

- It looks like you’re missing te contentType and setting the datatype as json
- The following codes works for me:

```auto
 $.ajax({
 url: "https://api.hsforms.com/submissions/v3/integration/submit/4753304/0db94b1d-bdc0-4da9-a454-97d1ff454413",
 type: "POST",
 contentType: "application/json",
 dataType: "json",
 headers: {
 "accept": "application/json",
 "Access-Control-Allow-Origin":"*"
 }
 data: JSON.stringify({

 "fields": [
 {
 "name": "email",
 "value": getEmail
 },
 {
 "name": "firstname",
 "value": getName
 }
 ],
 }),

 success: function(result) {
 console.log(result);
 },
 error: function(xhr,status,error) {
 console.log(xhr);
 console.log(status);
 console.log(error);
 }
 });

```

Hope this helps to clarify 🙂

---

<div class="post-metadata">

**Author:** ![system](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/system/32/124_2.png) [@system](https://community.hubspot.com/u/system)\
**Post date:** [August 16, 2019, 8:58am UTC](https://community.hubspot.com/t/hubspot-form-api-resolved/15763/3 "2019-08-16T08:58:10Z")

</div>

@WendyGoh ooh thank you very much, it works great.
