APIs & Integrations

TDwebdev
Contributor | Diamond Partner
Contributor | Diamond Partner

Publish page by id not work

SOLVE

Hello,

 

Iam trying to make pages via a API. Everything works except the publish page by page id.

 

Here is my PHP code where i put the page id from de latest created page in url to publish the page.


$url = "https://api.hubapi.com/content/api/v2/pages/".$page_id."/publish-action?hapikey=".$api_key;

$data = array(
// Action for publish page
"action" => "push-buffer-live"
);
 
// Encode JSON
$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);
// Post new Data
$result = curl_exec($ch);

$result_back = json_decode($result);
?>

<pre>
<?php print_r($result_back);?>
</pre>
<?php

curl_close ($ch);
 
Is there a method where i can publish the latest pages created by the api?
 
For now i get the following error when i try to publish a specific page:
 [correlationId] => 52febc1b-f92f-4939-a00b-b1acbb854b9a
 [message] => Invalid publish action
 [status] => error


Vet Digital

Did my post solve your question? Help the community by marking it as a solution
0 Upvotes
1 Accepted solution
TDwebdev
Solution
Contributor | Diamond Partner
Contributor | Diamond Partner

Publish page by id not work

SOLVE

Hi,

Okay, for me it wont work. I find out that schedule-publish works:

$url = "https://api.hubapi.com/content/api/v2/pages/page_id/publish-action?hapikey=".$api_key;

$data = array(
"action" => "schedule-publish",
);

 

But thank you for your reply!

Regards,

TDwebdev



Vet Digital

Did my post solve your question? Help the community by marking it as a solution

View solution in original post

0 Upvotes
6 Replies 6
RMones
Contributor | Platinum Partner
Contributor | Platinum Partner

Publish page by id not work

SOLVE

Did you chnge the URL endpoint from publish-action to push-buffer-live??

 

When I look at your reply, it looks like you dont have changed the url from publish-action to push-buffer-live..

 

Regards, Ronald

0 Upvotes
TDwebdev
Contributor | Diamond Partner
Contributor | Diamond Partner

Publish page by id not work

SOLVE

Yes i tried, I have adjusted it because it does not work for me.



Vet Digital

Did my post solve your question? Help the community by marking it as a solution
0 Upvotes
TDwebdev
Solution
Contributor | Diamond Partner
Contributor | Diamond Partner

Publish page by id not work

SOLVE

Hi,

Okay, for me it wont work. I find out that schedule-publish works:

$url = "https://api.hubapi.com/content/api/v2/pages/page_id/publish-action?hapikey=".$api_key;

$data = array(
"action" => "schedule-publish",
);

 

But thank you for your reply!

Regards,

TDwebdev



Vet Digital

Did my post solve your question? Help the community by marking it as a solution
0 Upvotes
RMones
Contributor | Platinum Partner
Contributor | Platinum Partner

Publish page by id not work

SOLVE

Hi,

 

I used the following code:

<?php
$page_id = '';
$api_key = '';
$url = "https://api.hubapi.com/content/api/v2/pages/".$page_id."/push-buffer-live?hapikey=".$api_key;

$data = array(
// Action for publish page
"action" => "push-buffer-live"
);
 
// Encode JSON
$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);
// Post new Data
$result = curl_exec($ch);

$result_back = json_decode($result);
?>

<pre>
<?php print_r($result_back);?>
</pre>
<?php

curl_close ($ch);

 

And thats working like a charm! 🙂

Regards,

 

Ronald

0 Upvotes
RMones
Contributor | Platinum Partner
Contributor | Platinum Partner

Publish page by id not work

SOLVE

Hi @TDwebdev ,

 

Try to change your endpoit from 

$url = "https://api.hubapi.com/content/api/v2/pages/".$page_id."/publish-action?hapikey=".$api_key;
 
to

$url = "https://api.hubapi.com/content/api/v2/pages/".$page_id."/push-buffer-live?hapikey=".$api_key;

I supose there is something wrong in the documentation of the API.
https://legacydocs.hubspot.com/docs/methods/pages/post_pages_page_id_push_buffer_live
 
Regards,
 
Ronald
 
 
TDwebdev
Contributor | Diamond Partner
Contributor | Diamond Partner

Publish page by id not work

SOLVE

Hello,

Thank you for the reply, but what do i have to do with the PHP POST?

Do i need to remove the action?

$data = array(
// Action for publish page
"action" => "push-buffer-live"
);
 
// Encode JSON
$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);

// Post new Data

$result = curl_exec($ch);

 

$result_back = json_decode($result);
?>
 
It still doesn't work now.
 
Regards,
TDwebdev


Vet Digital

Did my post solve your question? Help the community by marking it as a solution
0 Upvotes