# API returns Cloudflare 400 error for POST calls

**URL:** <https://community.hubspot.com/t/api-returns-cloudflare-400-error-for-post-calls/19000>\
**Category:** APIs & Integrations\
**Tags:** contacts, timeline-and-extensions-apis\
**Created:** [February 24, 2020, 4:05pm UTC](https://community.hubspot.com/t/api-returns-cloudflare-400-error-for-post-calls/19000 "2020-02-24T16:05:40Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![OCG](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/ocg/32/2490_2.png) [@OCG](https://community.hubspot.com/u/OCG)\
**Post date:** [February 24, 2020, 4:05pm UTC](https://community.hubspot.com/t/api-returns-cloudflare-400-error-for-post-calls/19000/1 "2020-02-24T16:05:40Z")

</div>

I’m trying to add a contact to Hubspot and I’ve been following the guide. I wrote a script that runs a PHP script that uses a CURL request, but when I send anything with a POST request, I get a Cloudflare 400 error page.

There’s nothing special here. I’ve stripped my PHP script down to just the bare data (which closely mirrors the demo script in the docs), but no matter what data I send I get the same result.

---

<div class="post-metadata">

**Author:** ![WendyGoh](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/wendygoh/32/42320_2.png) [@WendyGoh](https://community.hubspot.com/u/WendyGoh)\
**Post date:** [February 25, 2020, 7:15am UTC](https://community.hubspot.com/t/api-returns-cloudflare-400-error-for-post-calls/19000/2 "2020-02-25T07:15:28Z")

</div>

Hey @OCG,

Do you mind sharing with me the code snippet and is this the exact endpoint that you’re using - [Create a new contact | Contacts API](https://developers.hubspot.com/docs/methods/contacts/create_contact)?

Additionally, could you try POST-ing the request over [Postman](https://www.postman.com/) and see if it works?

---

<div class="post-metadata">

**Author:** ![OCG](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/ocg/32/2490_2.png) [@OCG](https://community.hubspot.com/u/OCG)\
**Post date:** [February 25, 2020, 4:57pm UTC](https://community.hubspot.com/t/api-returns-cloudflare-400-error-for-post-calls/19000/3 "2020-02-25T16:57:38Z")

</div>

I’ve tried with everything, even the stock PHP example on [https://developers.hubspot.com/docs/methods/contacts/create\_contact](https://developers.hubspot.com/docs/methods/contacts/create_contact) and all get a 400 error from Cloudfront

I ran this on our AWS server and I at least got a 400 with JSON. Running it in-house I only get a 400 HTML page from Cloudflare.

I’ll look into Postman.

---

<div class="post-metadata">

**Author:** ![WendyGoh](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/wendygoh/32/42320_2.png) [@WendyGoh](https://community.hubspot.com/u/WendyGoh)\
**Post date:** [February 26, 2020, 1:04am UTC](https://community.hubspot.com/t/api-returns-cloudflare-400-error-for-post-calls/19000/4 "2020-02-26T01:04:33Z")

</div>

Hey @OCG,

Do you have the full error message code that you can share with me? Additionally, what is the HubSpot portal ID in which you’re creating the contact on?

Please do let me know if it works on Postman!

---

<div class="post-metadata">

**Author:** ![OCG](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/ocg/32/2490_2.png) [@OCG](https://community.hubspot.com/u/OCG)\
**Post date:** [February 26, 2020, 8:16pm UTC](https://community.hubspot.com/t/api-returns-cloudflare-400-error-for-post-calls/19000/5 "2020-02-26T20:16:41Z")

</div>

I haven’t had a chance to fiddle with Postman. This is the full error from CURL

```auto
<html>
<head><title>400 Bad Request</title></head>
<body>
<center><h1>400 Bad Request</h1></center>
<hr><center>cloudflare</center>
</body>
</html>

```

As I said previously, I do get a JSON error running it on an AWS server

`{"status":"error","message":"Invalid JSON input: No content to map due to end-of-input at line 1, column 0","correlationId":"cc0b2d88-bffa-41ef-a18e-60e6641723a6","requestId":"31e53c5741a2fb2e2edfe7f63548012a"}`

That could be due to the copy-paste over the command line, however.

---

<div class="post-metadata">

**Author:** ![WendyGoh](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/wendygoh/32/42320_2.png) [@WendyGoh](https://community.hubspot.com/u/WendyGoh)\
**Post date:** [February 27, 2020, 1:38am UTC](https://community.hubspot.com/t/api-returns-cloudflare-400-error-for-post-calls/19000/6 "2020-02-27T01:38:12Z")

</div>

Hey @OCG,

Can I check if you’re trying to create a new contact using this endpoint [Create a new contact | Contacts API](https://developers.hubspot.com/docs/methods/contacts/create_contact) and the following POST body:

```auto
{
 "properties": [
 {
 "property": "email",
 "value": "testingapis@hubspot.com"
 },
 {
 "property": "firstname",
 "value": "Adrian"
 },
 {
 "property": "lastname",
 "value": "Mott"
 },
 {
 "property": "website",
 "value": "http://hubspot.com"
 },
 {
 "property": "company",
 "value": "HubSpot"
 },
 {
 "property": "phone",
 "value": "555-122-2323"
 },
 {
 "property": "address",
 "value": "25 First Street"
 },
 {
 "property": "city",
 "value": "Cambridge"
 },
 {
 "property": "state",
 "value": "MA"
 },
 {
 "property": "zip",
 "value": "02139"
 }
 ]
}

```

on portal **719xxxx**?

If so, I have managed to successfully create a contact (_which I have deleted_) using the above POST body on portal **719xxxx**.

Additionally, are you using a hapikey/oauth token to authenticate the request?

---

<div class="post-metadata">

**Author:** ![OCG](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/ocg/32/2490_2.png) [@OCG](https://community.hubspot.com/u/OCG)\
**Post date:** [February 27, 2020, 2:07pm UTC](https://community.hubspot.com/t/api-returns-cloudflare-400-error-for-post-calls/19000/7 "2020-02-27T14:07:40Z")

</div>

Just to be clear, I get no response at all. No JSON. If I make calls from my live server (even with your JSON) I get

Invalid JSON input: No content to map due to end-of-input at line 1, column 0

I am using a hapikey call

```auto
$curl = curl_init();
$options = [
 CURLOPT_URL => 'https://api.hubapi.com/contacts/v1/contact?hapikey=<key removed>',
 CURLOPT_RETURNTRANSFER => true
];

```

---

<div class="post-metadata">

**Author:** ![WendyGoh](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/wendygoh/32/42320_2.png) [@WendyGoh](https://community.hubspot.com/u/WendyGoh)\
**Post date:** [February 28, 2020, 1:29am UTC](https://community.hubspot.com/t/api-returns-cloudflare-400-error-for-post-calls/19000/8 "2020-02-28T01:29:15Z")

</div>

Hey @OCG,

Researching into the error, it seems that a simple fix is to add `_Content-Type: application/json_’ based on [this stack overflow thread](https://stackoverflow.com/questions/26925058/no-content-to-map-due-to-end-of-input-jackson-parser).

Could you try and see if this fixes it?

---

<div class="post-metadata">

**Author:** ![OCG](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/ocg/32/2490_2.png) [@OCG](https://community.hubspot.com/u/OCG)\
**Post date:** [February 28, 2020, 3:18pm UTC](https://community.hubspot.com/t/api-returns-cloudflare-400-error-for-post-calls/19000/9 "2020-02-28T15:18:42Z")

</div>

Sorry, was posting snippets. I already do that. Here’s a fuller picture

```auto
<?php
$curl = curl_init();
$options = [
	CURLOPT_URL => 'https://api.hubapi.com/contacts/v1/contact?hapikey=<key removed>',
	CURLOPT_RETURNTRANSFER => true
];

$options[CURLOPT_POST] = true;
$options[CURLOPT_HTTPHEADER] = ['Content-Type: application/json'];
$option[CURLOPT_POSTFIELDS] = '{"properties":[{"property":"email","value":"temp@somedomain.com"},{"property":"firstname","value":"Jack"},{"property":"lastname","value":"Smith"},{"property":"phone","value":"123-456-7890"},{"property":"address","value":"1234 My Street"},{"property":"city","value":"Mytown"},{"property":"state","value":"CA"},{"property":"zip","value":"91030"}]}';

curl_setopt_array($curl, $options);
$response = curl_exec($curl);
echo curl_getinfo($curl, CURLINFO_HTTP_CODE);
echo $response;
echo curl_error($curl);

```

That code does not work with your supplied JSON from a previous answer, either.

---

<div class="post-metadata">

**Author:** ![Anil\_R](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/anil_r/32/2401_2.png) [@Anil\_R](https://community.hubspot.com/u/Anil_R)\
**Post date:** [October 6, 2020, 11:24am UTC](https://community.hubspot.com/t/api-returns-cloudflare-400-error-for-post-calls/19000/10 "2020-10-06T11:24:44Z")

</div>

I’m also getting the same error when try to clear contact properties and create activities. First API call becoms success but after that all calls gives below error. These are consecutive API calls runs one after the other (Clear fields and create activities).

\<html\>  
\<head\>\<title\>400 Bad Request\</title\>\</head\>  
\<body\>  
\<center\>\<h1\>400 Bad Request\</h1\>\</center\>  
\<hr\>\<center\>cloudflare\</center\>  
\</body\>  
\</html\>
