HubDB Row Update "Method PUT is not allowed"


#1

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
}
}
)
})


#2

Hi @erinbebee,

That appears like it should work. I just tested that endpoint out on my portal, and it accepted the PUT request. Can you log and send me the full raw request you're making?


#3

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


#4

Is this what you were looking for ?

HEADERS
Access-Control-Allow-Credentials: true

Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Accept-Charset, Accept-Encoding

Access-Control-Allow-Methods: GET

Cf-Ray: 3f35ff49b89556e1-IAD

Connection: keep-alive

Content-Length: 254

Content-Type: application/json; charset=UTF-8

Date: Mon, 26 Feb 2018 21:28:59 GMT

Expect-Ct: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"

Server: cloudflare

Set-Cookie: __cfduid=d620cdd8115a10dc49b9cb9a0b0337a141519680539; expires=Tue, 26-Feb-19 21:28:59 GMT; path=/; domain=.hubapi.com; HttpOnly

X-Trace: 2BF8F5ACEEA64A3F6B17FE58CAB4D6A4DEFB7E5A17C3D4A0FD15D25DF001

BODY view raw
{
"status": "error",
"message": "Invalid input JSON on line 1, column 3: Unexpected character ('=' (code 61)): Expected space separating root-level values",
"correlationId": "2fd55936-1d02-4718-80a5-cec8e13223b8",
"requestId": "dc5a66b074714cea811dc6af5c0b0765"
}

I used https://www.hurl.it to get this though, so its not my exact code.


#5

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.


#6

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.


#7

Hi @erinbebee,

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


#8

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


#9

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"
  }
}

#10

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 ).


#11

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?


#12

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.


#13

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.


#14

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


#15

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.


#16

Hi @Derek_Gervais I also facing same issue

Please provide solution.


#17

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.


#18

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


#19

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?


#20

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.