Getting 400 Bad Request when trying to add a Blog Post
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
Based on my research, it appears that this error is because of wrong headers or wrong request body. Looking at the header it looks fine. One thing that I noticed though is that the code didn't include the HTTP method POST. Could we try that out and see if it works?
Dec 10, 201910:17 AM - edited Dec 10, 201910:18 AM
Member
Getting 400 Bad Request when trying to add a Blog Post
Hey WendyGoh,
Thank you for your anwser.
I am already using "PostForObject" from the class RestTemplate for POST requests, but just to be sure, i changed my code with the following lines, but i still have the same response 400:
When looking at TRY 1 and TRY 2, I noticed something different in the way you set the POST body to JSON. For TRY 1, you aint' using the toJson() method whereas for TRY 2 you're using the to.Json() method.
Curious to know if there are any differences between the way you convert contactSendList and blogpostSendPost to JSON?
Dec 11, 201910:23 AM - edited Dec 11, 201910:52 AM
Member
Getting 400 Bad Request when trying to add a Blog Post
Hi WendiGoh,
Thank your for your anwser.
Theses toJson(). are totally the same code and optionals.
This line can be replace:
HttpEntity<String> request2 = new HttpEntity<>(blogpostSendPost.toJson(), headers); log(request2.toString()); //<{"name":"My first API blog post!","content_group_id":"351076997"},[Content-Type:"application/json"]>
with
HttpEntity<BlogpostSendPost> request2 = new HttpEntity<>(blogpostSendPost, headers); log(request2.toString()); //<BlogpostSendPost(name=My first API blog post!, content_group_id=351076997),[Content-Type:"application/json"]>
and it change nothing to the response i get from the API (OK ou 400 depending on the 4 Try)