# Invalid HTTP method: PATCH

**URL:** <https://community.hubspot.com/t/invalid-http-method-patch/37178>\
**Category:** APIs & Integrations\
**Tags:** companies, starter\
**Created:** [May 12, 2021, 10:22am UTC](https://community.hubspot.com/t/invalid-http-method-patch/37178 "2021-05-12T10:22:50Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![AdKerremans](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/adkerremans/32/53612_2.png) [@AdKerremans](https://community.hubspot.com/u/AdKerremans)\
**Post date:** [May 12, 2021, 10:22am UTC](https://community.hubspot.com/t/invalid-http-method-patch/37178/1 "2021-05-12T10:22:50Z")

</div>

Hi,

I am trying to update a company but I get the error “Invalid HTTP method: PATCH”

as soon as I set the request method to patch

My url is:

[https://api.hubapi.com/crm/v3/objects/companies/6058260265?hapikey=xxx](https://api.hubapi.com/crm/v3/objects/companies/6058260265?hapikey=xxxxxxxxxxx)

What could be wrong

Thanks and regards

Ad

---

<div class="post-metadata">

**Author:** ![dennisedson](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/dennisedson/32/28044_2.png) [@dennisedson](https://community.hubspot.com/u/dennisedson)\
**Post date:** [May 12, 2021, 5:34pm UTC](https://community.hubspot.com/t/invalid-http-method-patch/37178/2 "2021-05-12T17:34:58Z")

</div>

Hi @AdKerremans

Looks like this is formatted correctly. I just tested and was able to successfully patch a company. Can you confirm that you are still having this issue?

---

<div class="post-metadata">

**Author:** ![AdKerremans](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/adkerremans/32/53612_2.png) [@AdKerremans](https://community.hubspot.com/u/AdKerremans)\
**Post date:** [May 17, 2021, 6:00am UTC](https://community.hubspot.com/t/invalid-http-method-patch/37178/3 "2021-05-17T06:00:41Z")

</div>

Hi @dennisedson ,

I still get the same error.

Regards

Ad

---

<div class="post-metadata">

**Author:** ![dennisedson](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/dennisedson/32/28044_2.png) [@dennisedson](https://community.hubspot.com/u/dennisedson)\
**Post date:** [May 17, 2021, 2:14pm UTC](https://community.hubspot.com/t/invalid-http-method-patch/37178/4 "2021-05-17T14:14:45Z")

</div>

Hey @AdKerremans

Just took a look and it appears that you successfully patched that company record twice on May 12

---

<div class="post-metadata">

**Author:** ![AdKerremans](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/adkerremans/32/53612_2.png) [@AdKerremans](https://community.hubspot.com/u/AdKerremans)\
**Post date:** [May 18, 2021, 6:05am UTC](https://community.hubspot.com/t/invalid-http-method-patch/37178/5 "2021-05-18T06:05:13Z")

</div>

Hi @dennisedson ,

I just created a new company with the command

HTTPS POST request: [https://api.hubapi.com/crm/v3/objects/companies?hapikey=xxx](https://api.hubapi.com/crm/v3/objects/companies?hapikey=xxx)  
2021/mei/18 07:46:25.525-\> [portToClass] Body: {“properties”:{“zip”:“8413 NC”,“country”:“Netherlands”,“website”:“[www.dexxx.nl/","address](http://www.dexxx.nl/%22,%22address)”:" Bolaan 1B",“bp\_code”:"  
0123082315",“city”:“Oudehorne”,“phone”:“0031523413541001”,“name”:“Rooster”,“lifecyclestage”:“customer”,“bp\_balance”:“OEM”,“bp\_company\_type”:“mpc\_nl”}}  
2021/mei/18 07:46:25.843-\> [portToClass] ResponseCode: 201  
2021/mei/18 07:46:25.843-\> [portToClass] HTTP get result: {“id”:“6090153844”,“properties”:{“address”: …  
,“hs\_lastmodifieddate”:“2021-05-18T05:46:25.626Z”,“hs\_object\_id”:“6090153844”,“lifecyclestage”:“customer”,“name”:…},“createdAt”:“2021-05-18T05:46:25.626Z”,“updatedAt”:“2021-05-18T05:46:25.626Z”,“archived”:false}

Now I am trying to update the company

HTTPS PATCH request: [https://api.hubapi.com/crm/v3/objects/companies/6090153844?hapikey=xxx](https://api.hubapi.com/crm/v3/objects/companies/6090153844?hapikey=xxx)

String fullUrl = HubspotUtils.getParameterAlpha(param, “BASE\_URL”) + urlExtension + “?hapikey=” + HubspotUtils.getParameterAlpha(param, “HAPI\_KEY”);  
log("HTTPS " + requestMethod + " request: " + fullUrl);  
URL url = new URL(fullUrl);  
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();  
connection.setRequestProperty(“X-HTTP-Method-Override”, “PATCH”);  
connection.setRequestMethod(“POST”);

It giving the error below:

\<html\>  
\<head\>  
\<meta http-equiv=“Content-Type” content=“text/html;charset=utf-8”/\>  
\<title\>Error 405 Method Not Allowed\</title\>  
\</head\>  
\<body\>\<h2\>HTTP ERROR 405\</h2\>  
\<p\>Problem accessing /crm/v3/objects/companies/6090153844. Reason:  
\<pre\> Method Not Allowed\</pre\>\</p\>  
\</body\>  
\</html\>

When using Postman it just just works.

Regards

Ad

---

<div class="post-metadata">

**Author:** ![dennisedson](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/dennisedson/32/28044_2.png) [@dennisedson](https://community.hubspot.com/u/dennisedson)\
**Post date:** [May 18, 2021, 2:18pm UTC](https://community.hubspot.com/t/invalid-http-method-patch/37178/6 "2021-05-18T14:18:10Z")

</div>

@MichaelC , any thoughts? If it is working in postman, it probably an issue in your app.

**connection.setRequestMethod(“POST”);** looks suspicious 🤔

---

<div class="post-metadata">

**Author:** ![MichaelC](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/michaelc/32/9055_2.png) [@MichaelC](https://community.hubspot.com/u/MichaelC)\
**Post date:** [May 18, 2021, 2:42pm UTC](https://community.hubspot.com/t/invalid-http-method-patch/37178/7 "2021-05-18T14:42:59Z")

</div>

Yep,

I agree.. are you sure it should be a post there and not a patch?

 ![MichaelC_0-1621348823761.png](https://d2qpr2jzcazej7.cloudfront.net/original/3X/8/d/8d136fe0e65cb5424ed3fa7a54c943382ddb0073.png)

---

<div class="post-metadata">

**Author:** ![AdKerremans](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/adkerremans/32/53612_2.png) [@AdKerremans](https://community.hubspot.com/u/AdKerremans)\
**Post date:** [May 19, 2021, 6:08am UTC](https://community.hubspot.com/t/invalid-http-method-patch/37178/8 "2021-05-19T06:08:33Z")

</div>

If I use PATCH I get the error:

“Invalid HTTP method: PATCH”

as soon as I set the request method to patch

---

<div class="post-metadata">

**Author:** ![MichaelC](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/michaelc/32/9055_2.png) [@MichaelC](https://community.hubspot.com/u/MichaelC)\
**Post date:** [May 19, 2021, 2:17pm UTC](https://community.hubspot.com/t/invalid-http-method-patch/37178/9 "2021-05-19T14:17:27Z")

</div>

Hello!

I would say something is off with your own code. You need to review it. There is nothing wrong in the Hubspot API not allowing PATCH method - we have tried it in multiple way - both through postman as well as me through GuzzleHTTP (PHP Framework) and it works.

You need to review your code - in your coding language - and to find error in your specific code langugage is not really something for the HubSpot forums but something for forums like Stack Overflow or similar.

Michael

---

<div class="post-metadata">

**Author:** ![AdKerremans](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/adkerremans/32/53612_2.png) [@AdKerremans](https://community.hubspot.com/u/AdKerremans)\
**Post date:** [May 20, 2021, 8:16am UTC](https://community.hubspot.com/t/invalid-http-method-patch/37178/10 "2021-05-20T08:16:24Z")

</div>

I found the solution on stackoverflow ([https://stackoverflow.com/questions/22355235/patch-request-using-jersey-client](https://stackoverflow.com/questions/22355235/patch-request-using-jersey-client))

I pasted the relevant part below.

So I looked into Java’s HttpUrlConnection code and saw that the allowed methods are specified by an **private static** String[]:

```auto
 /* Adding PATCH to the valid HTTP methods */
 private static final String[] methods = {
 "GET", "POST", "HEAD", "OPTIONS", "PUT", "DELETE", "TRACE"
 };

```

The solution was to change this methods array using reflection:

```auto
 try {
 Field methodsField = HttpURLConnection.class.getDeclaredField("methods");
 methodsField.setAccessible(true);
 // get the methods field modifiers
 Field modifiersField = Field.class.getDeclaredField("modifiers");
 // bypass the "private" modifier 
 modifiersField.setAccessible(true);

 // remove the "final" modifier
 modifiersField.setInt(methodsField, methodsField.getModifiers() & ~Modifier.FINAL);

 /* valid HTTP methods */
 String[] methods = {
 "GET", "POST", "HEAD", "OPTIONS", "PUT", "DELETE", "TRACE", "PATCH"
 };
 // set the new methods - including patch
 methodsField.set(null, methods);

 } catch (SecurityException | IllegalArgumentException | IllegalAccessException | NoSuchFieldException e) {
 e.printStackTrace();
 }

```

Since methods field is static, changing its value works for any concrete instance that is extending HttpUrlConnection including HttpsUrlConnection.

---

<div class="post-metadata">

**Author:** ![dennisedson](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/dennisedson/32/28044_2.png) [@dennisedson](https://community.hubspot.com/u/dennisedson)\
**Post date:** [May 20, 2021, 1:57pm UTC](https://community.hubspot.com/t/invalid-http-method-patch/37178/11 "2021-05-20T13:57:31Z")

</div>

Thanks for adding that solution @AdKerremans ,

Glad you got this worked out
