# 403 Error posting data with PHP or AJAX

**URL:** <https://community.hubspot.com/t/403-error-posting-data-with-php-or-ajax/12019>\
**Category:** APIs & Integrations\
**Created:** [September 12, 2017, 2:36pm UTC](https://community.hubspot.com/t/403-error-posting-data-with-php-or-ajax/12019 "2017-09-12T14:36:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/system/32/124_2.png) [@system](https://community.hubspot.com/u/system)\
**Post date:** [September 12, 2017, 2:36pm UTC](https://community.hubspot.com/t/403-error-posting-data-with-php-or-ajax/12019/1 "2017-09-12T14:36:17Z")

</div>

I read that AJAX automatically doesn’t work with the API so I tried PHP. I send data with this code:

$data = array(  
‘values’ =\> array(  
‘3’ =\> 7,  
‘4’ =\> “New Row Text”  
)  
);

$options = array(  
‘http’ =\> array(  
‘method’ =\> ‘POST’,  
‘content’ =\> json\_encode( $data ),  
‘header’=\> “Content-Type: application/json\r\n” .  
“Accept: application/json\r\n”  
)  
);

$context = stream\_context\_create( $options );  
$result = file\_get\_contents(“[https://api.hubapi.com/hubdb/api/v1/tables/300081/rows?hapikey=XXXXX”](https://api.hubapi.com/hubdb/api/v1/tables/300081/rows?hapikey=XXXXX%E2%80%9D), false, $context );  
$response = json\_decode( $result );

Error:  
**Warning** : file\_get\_contents([https://api.hubapi.com/hubdb/api/v1/tables/300081/rows?hapikey=XXXXX😞](https://api.hubapi.com/hubdb/api/v1/tables/300081/rows?hapikey=XXXXX%F0%9F%98%9E) failed to open stream: HTTP request failed! HTTP/1.0 403 Forbidden

I’m still using AJAX to call a PHP file through POST and then I do the same with PHP and the url.

---

<div class="post-metadata">

**Author:** ![system](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/system/32/124_2.png) [@system](https://community.hubspot.com/u/system)\
**Post date:** [September 12, 2017, 2:47pm UTC](https://community.hubspot.com/t/403-error-posting-data-with-php-or-ajax/12019/2 "2017-09-12T14:47:58Z")

</div>

If my code is invalid can someone provide me with some form of code that would work with php?

---

<div class="post-metadata">

**Author:** ![system](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/system/32/124_2.png) [@system](https://community.hubspot.com/u/system)\
**Post date:** [September 13, 2017, 9:25am UTC](https://community.hubspot.com/t/403-error-posting-data-with-php-or-ajax/12019/3 "2017-09-13T09:25:02Z")

</div>

[developers.hubspot.com](https://developers.hubspot.com/docs/methods/contacts/create_contact)

### [Create a new contact | Contacts API](https://developers.hubspot.com/docs/methods/contacts/create_contact)

POST /contacts/v1/contact - Create a new contact in HubSpot with a simple HTTP POST to the Contacts API.

THIS is what should be used for PHP
