Hi guys,
i have some trouble trying to create Blog Posts, i would like to receive a JSON response, but i have a 400 Bad Request error.
I’ve done the same code with Contact model, using the v1 of HubSpot API and it is working well. The same code for Blog Posts doesn’t go through and i don’t understand why
i am using Java 8 and RestTemplate.
[u]So, with Postman straight to the HubSpotAPI and the following datas
it works
:[/u]
URL: https://api.hubapi.com/content/api/v2/blog-posts?hapikey=*****************
Header: Content-Type: application/json
Body:
{
"name": "My first API blog post!",
"content_group_id": 351076997
}
==> Here is the Response, nice:
{
"correlationId": "************************",
"errorType": "PARENT_BLOG_DOES_NOT_EXIST",
"message": "Selected parent blog doesn't exist",
"requestId": "************************",
"status": "error"
}
Now, when i am using Java to create the request
[u]Through my service,
it doesn’t works
:[/u]
URL: http://localhost:8888/hubspot/blogposts?hapikey=\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
Headers & Request:
// Header and content declarationsHttpHeaders headers = new HttpHeaders();headers.setContentType(MediaType.APPLICATION_JSON);HttpEntity<BlogpostSendPost> request = new HttpEntity<>(blogpostSendPost, headers);// Tried also// HttpEntity<String> request = new HttpEntity<>(blogpostSendPost.toJson(), headers);
In my Java code, i am calling the API in this way (Object type, is for dev needs)
Object answer = restTemplate .postForObject("https://api.hubapi.com/content/api/v2/blog-posts?hapikey=****************", request, Object.class);==> Here is the Reponse, why ?:
{
"timestamp": "2019-12-09T19:10:01.981+0000",
"status": 500,
"error": "Internal Server Error",
"message": "400 Bad Request",
"trace": "org.springframework.web.client.HttpClientErrorException$BadRequest: 400 Bad Request\r\n\tat
.........
}
I have read the other posts about the header like this one:
https://community.hubspot.com/t5/APIs-Integrations/Getting-a-400-Bad-Request-when-trying-to-create-a-deal/m-p/266569
Is there anything in the API v2 changing the way to receive the JSON body, i should add to my code to make it works ?
Thank you for your help ![]()
Romain