# Validate request implementation in Java

**URL:** <https://community.hubspot.com/t/validate-request-implementation-in-java/14283>\
**Category:** APIs & Integrations\
**Tags:** webhooks\
**Created:** [May 8, 2019, 7:03pm UTC](https://community.hubspot.com/t/validate-request-implementation-in-java/14283 "2019-05-08T19:03:18Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![lord\_dark\_basic](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/lord_dark_basic/32/84489_2.png) [@lord\_dark\_basic](https://community.hubspot.com/u/lord_dark_basic)\
**Post date:** [May 8, 2019, 7:03pm UTC](https://community.hubspot.com/t/validate-request-implementation-in-java/14283/1 "2019-05-08T19:03:18Z")

</div>

Hi, I trying to validate request from Hubspot. I had an app in Java with this code to validate auth header token Token.

```auto
@Service
public class HubspotAuth {

 @Autowired
 Hubspot hubspotAuthentication;

 @Value( "${chargebee.redirectUri:https://3b69d752.ngrok.io/api/v1/subscription}" )
 private String redirectUri;

 private Gson gson = new Gson();

 public Boolean checkToken(Object request, String token){
 String jsonRequestString = gson.toJson(request);
 String hash = hubspotAuthentication.getClientSecret() + jsonRequestString;
 String sha256hex = Hashing.sha256()
 .hashString(hash, StandardCharsets.UTF_8)
 .toString();
 return sha256hex.equals(token);
 }
}

```

I tried to with this input :

`String hash = hubspotAuthentication.getClientSecret() + "POST" + redirectUri + jsonRequestString;`

I had an app in HubSpot and a webhook. App id 190755.

 ![Screenshot from 2019-05-08 15-58-59.png](https://d2qpr2jzcazej7.cloudfront.net/original/3X/3/d/3d6806609c5c0f5e76c680431dbc00d78afa09be.png)  
If you need, I can send a request body, but it’s a boil of text.

Thanks for the help.

---

<div class="post-metadata">

**Author:** ![IsaacTakushi](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/isaactakushi/32/70387_2.png) [@IsaacTakushi](https://community.hubspot.com/u/IsaacTakushi)\
**Post date:** [May 9, 2019, 8:13pm UTC](https://community.hubspot.com/t/validate-request-implementation-in-java/14283/2 "2019-05-09T20:13:02Z")

</div>

Welcome, [@lord\_dark\_basic](https://community.hubspot.com/t5/user/viewprofilepage/user-id/93960).

Would you direct message me the following so that I may test on my end?

1. The request body you sent.
2. The `X-HubSpot-Signature` value you received.
3. The string you generated using `hash = hubspotAuthentication.getClientSecret() + "POST" + redirectUri + jsonRequestString;`. (Feel free to redact all but the first _five_ characters in your client secret.)
4. The hash value you generated from the string above.

---

<div class="post-metadata">

**Author:** ![lord\_dark\_basic](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/lord_dark_basic/32/84489_2.png) [@lord\_dark\_basic](https://community.hubspot.com/u/lord_dark_basic)\
**Post date:** [May 10, 2019, 3:13pm UTC](https://community.hubspot.com/t/validate-request-implementation-in-java/14283/3 "2019-05-10T15:13:31Z")

</div>

The request body you sent? I receive a body request.

---

<div class="post-metadata">

**Author:** ![lord\_dark\_basic](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/lord_dark_basic/32/84489_2.png) [@lord\_dark\_basic](https://community.hubspot.com/u/lord_dark_basic)\
**Post date:** [May 10, 2019, 3:19pm UTC](https://community.hubspot.com/t/validate-request-implementation-in-java/14283/4 "2019-05-10T15:19:25Z")

</div>

I tried to send request body, but is too long and superate 60,000 characters in length. I can’t add a file in this forum. If you want I can send an email.  
🙂

---

<div class="post-metadata">

**Author:** ![lord\_dark\_basic](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/lord_dark_basic/32/84489_2.png) [@lord\_dark\_basic](https://community.hubspot.com/u/lord_dark_basic)\
**Post date:** [May 10, 2019, 5:46pm UTC](https://community.hubspot.com/t/validate-request-implementation-in-java/14283/5 "2019-05-10T17:46:46Z")

</div>

SOLVED !!!

`private ObjectWriter ow = new ObjectMapper().writer();public Boolean checkToken(Object request, String token) throws JsonProcessingException { log.info("With redirect uri " + redirectUri + " and secret " + hubspotAuthentication.getClientSecret()); log.info("Expect token ---> "+ token); String jsonRequestString = ow.writeValueAsString(request); String hash = hubspotAuthentication.getClientSecret() + "POST" + redirectUri + jsonRequestString; String sha256hex = Hashing.sha256() .hashString(hash, StandardCharsets.UTF_8) .toString(); log.info("Generate token ---> "+ sha256hex); return sha256hex.equals(token);}`

Thx for all .

🙂

---

<div class="post-metadata">

**Author:** ![IsaacTakushi](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/isaactakushi/32/70387_2.png) [@IsaacTakushi](https://community.hubspot.com/u/IsaacTakushi)\
**Post date:** [May 10, 2019, 6:12pm UTC](https://community.hubspot.com/t/validate-request-implementation-in-java/14283/6 "2019-05-10T18:12:51Z")

</div>

Nice work, [@lord\_dark\_basic](https://community.hubspot.com/t5/user/viewprofilepage/user-id/93960)! I’m sure others will benefit from your solution as well  
 ![16x16_smiley-very-happy.png.png](https://d2qpr2jzcazej7.cloudfront.net/original/2X/a/a83ec960612094a57cfb392e21c202c8e77b967c.png)

And yes, I misspoke earlier regarding the “body you sent.” Thanks for understanding anyway.

---

<div class="post-metadata">

**Author:** ![danielad](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/danielad/32/74736_2.png) [@danielad](https://community.hubspot.com/u/danielad)\
**Post date:** [May 30, 2019, 7:44am UTC](https://community.hubspot.com/t/validate-request-implementation-in-java/14283/7 "2019-05-30T07:44:23Z")

</div>

I am having the same issue here and cannot figure out what I am doing wrong 😞

I am using c# .net and I have tried all 3 validation methods but none of them generate a matching hash.

 ![Untitled.png](https://d2qpr2jzcazej7.cloudfront.net/original/3X/2/7/27910b22a2668cffea16d91dfa04a9db3f3bc5b6.png)

string hashString = HubspotRequestHelper.GetSignatureWithSecretAndBody(context, strJSON);  
string hashString2 = HubspotRequestHelper.GetSignatureWithSecretAndMethodAndUri(context);  
string hashString3 = HubspotRequestHelper.GetSignatureWithSecretAndMethodAndUriAndBody(context, strJSON);

My AppID is 194321 and I am attaching a file with some attempt of webhook validation.. printing the hubspot signature, and all my 3 hash attempts … The body is too long how can I forward it to you? Please help me understand how to correct this validation issue. Thanks!

----------------------------------------------

http\_method=POST|uri=[https://hubspotrequests.azurewebsites.net/default.aspx|](https://hubspotrequests.azurewebsites.net/default.aspx%7C)  
Hubspot SIGNATURE: 67c2c247f4ea809f2d3fffcdbb7e67179980f45e441eb04d55eee8490091f701  
uri:[https://hubspotrequests.azurewebsites.net/default.aspx|](https://hubspotrequests.azurewebsites.net/default.aspx%7C)

My 3 hash attempts  
d6676db9e68e700e7cd64fe4732623df70527fd5ed97f706c7b197a2c56afc96|  
b56a37ad42748356229750033de92672cc8eba8d9775b751a6c8b44bd866569b|  
df2f525f74e2b94f45d800fad905bd1b2c30408b7370eec2fa318a4403e688b7|
