How to Create a Site Page on PHP Curl



Just sharing my experience on how to implement Hubspot API - Create a Page using PHP Curl
Based on this link -

Here’s my code:

$api_key = [your api key]
$url = “”.$api_key;

$data = array(
“name” => [required],
“meta_description” => [optional],
“template_path” => [required],
“subcategory” => “site_page”,
“slug” => [optional],
“publish_immediately” => “true”,
“html_title” => [optional],
“widgets” => array(
“sample1” => array(“body” => array(“value” => “add value”))

$data_string = json_encode($data);

$header = array(
‘Content-Type: application/json’,
‘Accept: application/json’

$ch = curl_init();
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, “POST”);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$result = curl_exec($ch);
curl_close ($ch);


For the widgets, the format will be like that above. For example if you have a module “contact_name”, it will be “contact_name” => array(“body” => array(“value” => “add value”))

The good response will return all the data of the page created.

Hope this helps