# Create contact

**URL:** <https://community.hubspot.com/t/create-contact/80998>\
**Category:** APIs & Integrations\
**Created:** [May 11, 2023, 10:05am UTC](https://community.hubspot.com/t/create-contact/80998 "2023-05-11T10:05:41Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![DvonLemberg](https://avatars.discourse-cdn.com/v4/letter/d/b782af/32.png) [@DvonLemberg](https://community.hubspot.com/u/DvonLemberg)\
**Post date:** [May 11, 2023, 10:05am UTC](https://community.hubspot.com/t/create-contact/80998/1 "2023-05-11T10:05:41Z")

</div>

Hi,  
We are migrating to a private app.

Hi, I’m trying to add a new user directly to a list using php. If I just try to create a contact within hubspot  
I have a problem, the contact will be not created.

this is my code:

$arr = array(  
‘properties’ =\> array(  
array(  
‘property’ =\> ‘email’,  
‘value’ =\> $email  
),  
array(  
‘property’ =\> ‘firstname’,  
‘value’ =\> $vorname  
),  
array(  
‘property’ =\> ‘lastname’,  
‘value’ =\> $nachname  
),  
array(  
‘property’ =\> ‘newsletter’,  
‘value’ =\> $newsletter  
)

)  
);  
$post\_json = json\_encode($arr);  
$bkey = “pat-na1-xxxxxx”;  
$headers = [  
‘Content-Type: application/json’,  
'Authorization: Bearer ’ . $bkey,  
];  
$curl = curl\_init();  
@curl\_setopt($curl, CURLOPT\_POSTFIELDS, $post\_json);  
@curl\_setopt($curl, CURLOPT\_HTTPHEADER, $headers);  
@curl\_setopt($curl, CURLOPT\_URL, ‘[https://api.hubapi.com/crm/v3/objects/contacts](https://api.hubapi.com/crm/v3/objects/contacts)’);  
@curl\_setopt($curl, CURLOPT\_RETURNTRANSFER, true);  
$contacts = curl\_exec($curl);  
curl\_close($curl);

Can you help me, please? Thanks

---

<div class="post-metadata">

**Author:** ![skimura](https://avatars.discourse-cdn.com/v4/letter/s/9de053/32.png) [@skimura](https://community.hubspot.com/u/skimura)\
**Post date:** [May 11, 2023, 10:15am UTC](https://community.hubspot.com/t/create-contact/80998/2 "2023-05-11T10:15:00Z")

</div>

@DvonLemberg

Hi.

How about try this?

```lia-code-sample
..
$arr = array(
 'properties' => array(
 'email' => $email,
 'firstname' => $vorname,
 'lastname' => $nachname,
 'newsletter' => $newsletter,
 )
);
...

```

Please check api reference.

> **[Accounts Dashboard | HubSpot](https://app.hubspot.com/myaccounts?next=developerdocs&redirect=%2Fapi-reference%2Fcrm-contacts-v3%2Fguide)**

Thanks.

---

<div class="post-metadata">

**Author:** ![DvonLemberg](https://avatars.discourse-cdn.com/v4/letter/d/b782af/32.png) [@DvonLemberg](https://community.hubspot.com/u/DvonLemberg)\
**Post date:** [May 11, 2023, 11:57am UTC](https://community.hubspot.com/t/create-contact/80998/3 "2023-05-11T11:57:25Z")

</div>

I try  
$arr = array(  
‘properties’ =\> array(  
‘email’ =\> $email,  
‘firstname’ =\> $vorname,  
‘lastname’ =\> $nachname  
)  
);  
I don’t know what is wrong with my code. This is very frustrating. Can anyone recommend something?

---

<div class="post-metadata">

**Author:** ![skimura](https://avatars.discourse-cdn.com/v4/letter/s/9de053/32.png) [@skimura](https://community.hubspot.com/u/skimura)\
**Post date:** [May 11, 2023, 12:09pm UTC](https://community.hubspot.com/t/create-contact/80998/4 "2023-05-11T12:09:14Z")

</div>

@DvonLemberg

This format is for legacy APIs.

```lia-code-sample
$arr = array(
 'properties' => array(
 array(
 'property' => 'email',
 'value' => 'XXX'
 ),
 ),
...
);

```

[https://legacydocs.hubspot.com/docs/methods/contacts/create\_contact](https://legacydocs.hubspot.com/docs/methods/contacts/create_contact)

Your code uses hubspot API **v3**. (‘[https://api.hubapi.com/crm/\*\*v3\*\*/objects/contacts](https://api.hubapi.com/crm/ **v3** /objects/contacts)’)

v3 APIs format is like this.

```lia-code-sample
$arr = array(
 'properties' => array(
 'email' => 'XXX'
 ...
 )
);

```

Please check v3 APIs reference.

> **[Accounts Dashboard | HubSpot](https://app.hubspot.com/myaccounts?next=developerdocs&redirect=%2Fapi-reference%2Fcrm-contacts-v3%2Fguide)**

---

<div class="post-metadata">

**Author:** ![DvonLemberg](https://avatars.discourse-cdn.com/v4/letter/d/b782af/32.png) [@DvonLemberg](https://community.hubspot.com/u/DvonLemberg)\
**Post date:** [May 11, 2023, 12:30pm UTC](https://community.hubspot.com/t/create-contact/80998/5 "2023-05-11T12:30:11Z")

</div>

Hi,

thank you for the replay. I use v3 APIs and formats like this.

```auto
$arr = array(
 'properties' => array(
 'email' => 'XXX'
 ...
 )
);

```

but the contact will be not created

---

<div class="post-metadata">

**Author:** ![skimura](https://avatars.discourse-cdn.com/v4/letter/s/9de053/32.png) [@skimura](https://community.hubspot.com/u/skimura)\
**Post date:** [May 11, 2023, 12:32pm UTC](https://community.hubspot.com/t/create-contact/80998/6 "2023-05-11T12:32:30Z")

</div>

@DvonLemberg

Can you post the response code and response message?

Thanks.

---

<div class="post-metadata">

**Author:** ![skimura](https://avatars.discourse-cdn.com/v4/letter/s/9de053/32.png) [@skimura](https://community.hubspot.com/u/skimura)\
**Post date:** [May 11, 2023, 12:45pm UTC](https://community.hubspot.com/t/create-contact/80998/7 "2023-05-11T12:45:25Z")

</div>

In my case this works.

```lia-code-sample
$arr = [
 'properties' => [
 'email' => 'XXXX',
 'firstname' => 'test',
 'lastname' => 'test',
 ]
];

$post_json = json_encode($arr);
$bkey = "XXXX";
$headers = [
 'Content-Type: application/json',
 'Authorization: Bearer ' . $bkey
];

$curl = curl_init();
@curl_setopt($curl, CURLOPT_POSTFIELDS, $post_json);
@curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
@curl_setopt($curl, CURLOPT_URL, 'https://api.hubapi.com/crm/v3/objects/contacts');
@curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($curl);
curl_close($curl);
$status_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ($status_code == 200) {
 $response_json = json_decode($response, true);
 print_r($response_json);
} else {
 print_r(json_decode($response, true));
 echo "Request failed with status code: " . $status_code;
}

```

---

<div class="post-metadata">

**Author:** ![DvonLemberg](https://avatars.discourse-cdn.com/v4/letter/d/b782af/32.png) [@DvonLemberg](https://community.hubspot.com/u/DvonLemberg)\
**Post date:** [May 11, 2023, 1:27pm UTC](https://community.hubspot.com/t/create-contact/80998/8 "2023-05-11T13:27:17Z")

</div>

Hi, response code:

curl Errors: Status code: Response: {“status”:“error”,“message”:“Contact already exists. Existing ID: 35401”,“correlationId”:“ce92ca80-99e4-473d-96dd-aa6f93d4b5f8”,“category”:“CONFLICT”}“0 results”

---

<div class="post-metadata">

**Author:** ![skimura](https://avatars.discourse-cdn.com/v4/letter/s/9de053/32.png) [@skimura](https://community.hubspot.com/u/skimura)\
**Post date:** [May 11, 2023, 1:30pm UTC](https://community.hubspot.com/t/create-contact/80998/9 "2023-05-11T13:30:56Z")

</div>

@DvonLemberg

\>Contact already exists

Is the contact already exists?

Please try another ‘email’.

Or delete exists contact.

---

<div class="post-metadata">

**Author:** ![DvonLemberg](https://avatars.discourse-cdn.com/v4/letter/d/b782af/32.png) [@DvonLemberg](https://community.hubspot.com/u/DvonLemberg)\
**Post date:** [May 11, 2023, 1:50pm UTC](https://community.hubspot.com/t/create-contact/80998/10 "2023-05-11T13:50:38Z")

</div>

The contact doesn’t exists. I try another email:

curl Errors: Status code: Response: {“status”:“error”,“message”:“Contact already exists. Existing ID: 35401”,“correlationId”:“2132dbc9-ef03-4d6f-bd5e-15e01ee9f0b2”,“category”:“CONFLICT”}“0 results”

---

<div class="post-metadata">

**Author:** ![skimura](https://avatars.discourse-cdn.com/v4/letter/s/9de053/32.png) [@skimura](https://community.hubspot.com/u/skimura)\
**Post date:** [May 11, 2023, 1:57pm UTC](https://community.hubspot.com/t/create-contact/80998/11 "2023-05-11T13:57:04Z")

</div>

@DvonLemberg

It may just be that you don’t see it in your contact list.

Since the ID is known, can’t it be displayed directly from the URL?

URL like this.

[https://app.hubspot.com/contacts/{YOU\_PORTAL}/contact/](https://app.hubspot.com/contacts/%7BYOU_PORTAL%7D/contact/)35401

---

<div class="post-metadata">

**Author:** ![DvonLemberg](https://avatars.discourse-cdn.com/v4/letter/d/b782af/32.png) [@DvonLemberg](https://community.hubspot.com/u/DvonLemberg)\
**Post date:** [May 11, 2023, 10:10pm UTC](https://community.hubspot.com/t/create-contact/80998/12 "2023-05-11T22:10:47Z")

</div>

Thank you, the issue is solved 🙂

---

<div class="post-metadata">

**Author:** ![DvonLemberg](https://avatars.discourse-cdn.com/v4/letter/d/b782af/32.png) [@DvonLemberg](https://community.hubspot.com/u/DvonLemberg)\
**Post date:** [May 11, 2023, 12:14pm UTC](https://community.hubspot.com/t/create-contact/80998/13 "2023-05-11T12:14:28Z")

</div>

I check the link and I use the correct api.

“To create new contacts, make a POST request to /crm/v3/objects/contacts”

When creating a new contact, you should include at least one of the following properties in your request: email, firstname, or lastname."

I use

$arr = array(  
‘properties’ =\> array(  
‘email’ =\> $email,  
‘firstname’ =\> $vorname,  
‘lastname’ =\> $nachname

)  
);

The contact is not created.

I am not able to find the error
