APIs & Integrations

krisgalanida
Member | Elite Partner
Member | Elite Partner

Create a new Page API on PHP problem

Hi,

I am working on a PHP code that will create a webpage to Hubspot using their API. There is a response but when I check it on the Hubspot Website list, no page is create. This is my code:

=============================
$api_key = [hide for security reasons];

$url = " http://api.hubapi.com/content/api/v2/pages?hapikey=".$api_key;

$data = array(
“name” => “Test API Page”,
“template_path” => “Custom/page/For_Testing_Only/TestAPI.html”,
“widgets” => array(“content” => “Test”),
“publish_immediately” => true
);
$data_string = json_encode($data);

$header = array(
‘Content-Type: application/json’,
'Content-Length: ’ . strlen($data_string)
);

$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);

// Display all results
print_r(json_decode($result));

Is there a problem with my code?

Please help.

0 Upvotes
4 Replies 4
Not applicable

Create a new Page API on PHP problem

Hey @KGdeveloper ,

Can you please help me what is the issue . For me I am getting the same issue .
Also what is the exact request format when I want to create the page using template and custom modules using API.

0 Upvotes
krisgalanida
Member | Elite Partner
Member | Elite Partner

Create a new Page API on PHP problem

Hi,

I found the solution. I will close this thread.

Thanks :slight_smile:

Dadams
HubSpot Employee
HubSpot Employee

Create a new Page API on PHP problem

@KGdeveloper are you recording the full response? Are you getting any type of error code in that response? You’d get more details about the error in the body if you are getting an error response.

0 Upvotes
krisgalanida
Member | Elite Partner
Member | Elite Partner

Create a new Page API on PHP problem

@dadams Yes, I got this response.

=============
stdClass Object
(
[ab_status] =>
[ab_test_id] =>
[analytics_page_id] => 4721222068
[archived] =>
[attached_stylesheets] => Array
(
)

[author_user_id] => 
[blueprint_type_id] => 0
[campaign] => 
[campaign_name] => 
[cloned_from] => 
[compose_body] => 
[created] => 1484783371000
[css] => stdClass Object
    (
    )

[css_text] => 
[current_live_domain] => offers.thebrandmanager.com.au
[deleted_at] => 0
[deleted_by] => 
[domain] => 
[enable_domain_stylesheets] => 1
[enable_layout_stylesheets] => 1
[featured_image] => 
[featured_image_alt_text] => 
[flex_areas] => stdClass Object
    (
    )

[folder_id] => 
[footer_html] => 
[freeze_date] => 1484783371000
[has_smart_content] => 
[has_user_changes] => 1
[head_html] => 
[html_title] => 
[id] => 4721222068
[include_default_custom_css] => 
[is_draft] => 1
[keywords] => Array
    (
    )

[language] => 
[last_edit_session_id] => 
[last_edit_update_id] => 
[legacy_blog_tabid] => 
[meta_description] => 
[meta_keywords] => 
[name] => TestAPIPage
[page_expiry_date] => 
[page_expiry_enabled] => 
[page_expiry_redirect_id] => 
[page_expiry_redirect_url] => 
[page_redirected] => 
[password] => 
[performable_url] => 
[personas] => Array
    (
    )

[portal_id] => 347392
[publish_date] => 1484783371000
[publish_immediately] => 1
[published_url] => 
[rss_email_author_line_template] => 
[rss_email_blog_image_max_width] => 
[rss_email_by_text] => By
[rss_email_click_through_text] => Read more »
[rss_email_comment_text] => Comment »
[rss_email_entry_template] => 
[rss_email_entry_template_enabled] => 
[rss_email_image_max_width] => 0
[scheduled_update_date] => 
[slug] => -temporary-slug-2a02e844-4d21-49a7-93f6-ab8bb1a2aa64
[staged_from] => 
[style_override_id] => 
[subcategory] => landing_page
[template_path] => Custom/page/For_Testing_Only/TestAPI.html
[tms_id] => 
[translated_from_id] => 
[unpublished_at] => 
[updated] => 1484783371000
[url] => http://offers.thebrandmanager.com.au/-temporary-slug-2a02e844-4d21-49a7-93f6-ab8bb1a2aa64
[widget_containers] => stdClass Object
    (
    )

[widgetcontainers] => stdClass Object
    (
    )

[widgets] => stdClass Object
    (
        [content] => Test
    )

)

====================

That is all. I am not sure if the template path is wrong. I got the template path from Actions > Get Public URL

0 Upvotes