APIs & Integrations

Manobyte
Contributor | Diamond Partner
Contributor | Diamond Partner

HubDB Row Update "Method PUT is not allowed"

So I have done something similar before, and it worked just fine, but for some reason when I try to update a row in a HubDB table I am getting the error "Method PUT is not allowed by Access-Control-Allow-Methods in preflight response." Did something change to not allow this, or am I just missing something? Ill post my code below.

var sub_url = 'https://api.hubapi.com/hubdb/api/v1/tables/XXX/rows/XXX?hapikey=XXX';
fetch(sub_url,
{
headers: {
'Content-Type': 'application/json'
},
method: "PUT",
body: JSON.stringify(
{
"values": {
"5": custom_name,
"6": custom_overview,
"7": custom_val
}
}
)
})

0 Upvotes
22 Replies 22
Derek_Gervais
HubSpot Alumni
HubSpot Alumni

HubDB Row Update "Method PUT is not allowed"

Hi @Drashti_Patel,

That's a good question. Depending on your use case, you might be able to accomplish what you're looking to do with an IPaaS solution like Zapier. If you need a simple hosting solution for your server side scripts, you might consider solutions like Heroku or AWS:

https://aws.amazon.com/application-hosting/

0 Upvotes
Drashti312
Member

HubDB Row Update "Method PUT is not allowed"

Hi @Derek_Gervais,

I need to update the Hubdb cell data and create a new deal based on user's input, I am trying to do so from the client-side but I get the same error.

As per the discussion, I come to know I have to request it from server-side.

I don't have running web-server and actually I'm not that much profecient in server setup, can you please educate me which would be the best option for me to achieve this.

Is there any library or integration available which gets data by API (call PUT or POST request from client-side) and make request on backend-side and do the task.

Thanks!

0 Upvotes
Derek_Gervais
HubSpot Alumni
HubSpot Alumni

HubDB Row Update "Method PUT is not allowed"

Hi @Ankit_Kandoliya,

Only GET methods should allow CORS; other methods should not allow CORS, so I'm not entirely sure why it's possible to create a new row using client-side JavaScript.

I'll touch base with product on this; since the HubDB API should not allow CORS on any methods other than GET, the fact that it's possible to create a row is a bug. I wouldn't recommend depending on this functionality, since it's not officially supported and is likely to be fixed in the near future.

Going forward, you'll need to make POST/PUT requests to the HubDB API server-side, with the necessary authentication. See this developer doc:

0 Upvotes
Derek_Gervais
HubSpot Alumni
HubSpot Alumni

HubDB Row Update "Method PUT is not allowed"

Hi @Ankit_Kandoliya,

What issue are you facing? This post was originally addressing the 'Method PUT is not allowed'; the resolution there is that the HubDB API doesn't support client side requests for write methods (POST, PUT, etc.). It is not possible to make client side write requests to the HubDB API. You'll have to make the requests server side.

Does that address your question? If not, could you give me some more details on what exactly you're trying to do / what issue you're facing?

0 Upvotes
Ankit_Kandoliya
Member

HubDB Row Update "Method PUT is not allowed"

Hi @Derek_Gervais,

here is the summary of my issue

I'm able to create a new row using ajax post request but when I update the same row using ajax put request it gets fail, here is the exact message shows in the console log

Method PUT is not allowed by Access-Control-Allow-Methods in preflight response.

0 Upvotes
Derek_Gervais
HubSpot Alumni
HubSpot Alumni

HubDB Row Update "Method PUT is not allowed"

Hi @Ankit_Kandoliya,

HubDB endpoints that support GET support CORS, but this only applies to GET methods. Other methods (and the GET all tables endpoint) require authentication, and will not support CORS. For those methods, you'll need to make the requests server-side with authentication, either an API key or access token.

0 Upvotes
Ankit_Kandoliya
Member

HubDB Row Update "Method PUT is not allowed"

I already make a request using hapikey to modify particular HubDB table row.

0 Upvotes
Derek_Gervais
HubSpot Alumni
HubSpot Alumni

HubDB Row Update "Method PUT is not allowed"

Hi @erinbebee,

It really depends on what exactly you're looking to build, and how what you have is currently structured. If you have an existing web server that you can add a (relatively) simple script to, you could make requests to that server and then hit the HubSpot API from that server. If you don't have access to an existing web server, you might consider a lightweight solution like Heroku or AWS to host a simple web server to handle the proxying.

Happy to give more specific feedback if you want to share more details regarding your goal and existing process.

0 Upvotes
Ankit_Kandoliya
Member

HubDB Row Update "Method PUT is not allowed"

Hi @Derek_Gervais I also facing same issue

Please provide solution.

0 Upvotes
Derek_Gervais
HubSpot Alumni
HubSpot Alumni

HubDB Row Update "Method PUT is not allowed"

Hi @erinbebee,

I understand; that makes much more sense. HubDB endpoints that support GET support CORS, but this only applies to GET methods. Other methods and the GET all tables API require authentication, and will not support CORS. For those methods, you'll need to make the requests server-side with authentication, either an API key or access token.

0 Upvotes
Manobyte
Contributor | Diamond Partner
Contributor | Diamond Partner

HubDB Row Update "Method PUT is not allowed"

hm, ok. any pointers for how would I go about doing this?

0 Upvotes
Derek_Gervais
HubSpot Alumni
HubSpot Alumni

HubDB Row Update "Method PUT is not allowed"

Hi @erinbebee,

That's exceedingly strange. Are you making these requests from the browser? The HubDB endpoints only support CORS for GET requests, so you'd be seeing an error like this if you were trying to make PUT requests client-side. Do you have any other details about your setup that might be useful? Are you using a particular language, request library, or hosting service that might be related?

0 Upvotes
Manobyte
Contributor | Diamond Partner
Contributor | Diamond Partner

HubDB Row Update "Method PUT is not allowed"

Ya, I am trying to update it from the browser. It is an interface for people in my company to search sort create and update content in the database. It uses jquery/javascript.

0 Upvotes
Derek_Gervais
HubSpot Alumni
HubSpot Alumni

HubDB Row Update "Method PUT is not allowed"

Hi @erinbebee,

I just gave it a shot on my end, and I was able to update that row with some test value successfully. I think there might be something malformed in your request URL and/or your request body. The request URL and body should look like the following:

https://api.hubapi.com/hubdb/api/v1/tables/((tableid))/rows/((rowid))?hapikey=xxx 

body:
{
  "values": {
    "2": "5466613837",
    "3": {
      "id": 2,
      "name": "February",
      "type": "option"
    },
    "4": {
      "id": 2,
      "name": "2018",
      "type": "option"
    },
    "5": "test - request successful!",
    "6": "test - request successful!",
    "7": "2"
  }
}
0 Upvotes
Manobyte
Contributor | Diamond Partner
Contributor | Diamond Partner

HubDB Row Update "Method PUT is not allowed"

I tried making The body exactly the same, but still got the error "Method PUT is not allowed by Access-Control-Allow-Methods in preflight response." I though maybe there was something wrong with my api key so a double checked and that doesn't seem to be it ( also I have another method for the same table that creates rows using the same api key and that works fine ).

0 Upvotes
Derek_Gervais
HubSpot Alumni
HubSpot Alumni

HubDB Row Update "Method PUT is not allowed"

Hi @erinbebee,

Can you give me your Hub ID and the info for the table in question so I can troubleshoot directly?

0 Upvotes
Manobyte
Contributor | Diamond Partner
Contributor | Diamond Partner

HubDB Row Update "Method PUT is not allowed"

Sure, the Hub ID is 249181 and the table is 675874, row 5602290909 is what I was testing on

0 Upvotes
Derek_Gervais
HubSpot Alumni
HubSpot Alumni

HubDB Row Update "Method PUT is not allowed"

Hi @erinbebee,

Hmm... That looks like an error response from us, but it also looks different than the "Method not allowed" you mentioned earlier. I was looking for the request body right before sending the request. The code you included has variable names (e.g. custom_name, custom_overview, etc.) so it's tough to know if those might be malformed or something.

0 Upvotes
Manobyte
Contributor | Diamond Partner
Contributor | Diamond Partner

HubDB Row Update "Method PUT is not allowed"

I did try to instead send just a default value instead of a variable, with the same results. It was just a simple "Test" text. Also I checked the thing I had made before, which did previously work, now gets the same error.

0 Upvotes
Manobyte
Contributor | Diamond Partner
Contributor | Diamond Partner

HubDB Row Update "Method PUT is not allowed"

hm, Im not sure how to get thing information. Ill keep looking.

0 Upvotes