403 Error posting data with PHP or AJAX

oauth

#1

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”, false, $context );
$response = json_decode( $result );

Error:
Warning: file_get_contents(https://api.hubapi.com/hubdb/api/v1/tables/300081/rows?hapikey=XXXXX): 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.


#2

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


#3

THIS is what should be used for PHP