Publish CMS Page

resolver
Highlighted
Colaborador Ocasional

I am integrating an application with the API and I encounter a difficulty when I publish pages of the website in Hubspot. I publish the page perfectly but it is being impossible for me to leave it in a state published from the API.

 

Can anyone guide me about this process?

Responder
0 Avaliação positiva
2 Solução aceitas

Soluções aceitas
Highlighted
Moderador da HubSpot

Hi @cmoraleda 

 

This process of creating and publishing pages can be done through the use of 2 endpoints:

  1. Create a new pagehttps://developers.hubspot.com/docs/methods/pages/post_pages
  2. Publish or unpublish pageshttps://developers.hubspot.com/docs/methods/pages/post_pages_page_id_publish_action

To walk-through this with you, i've gone ahead and created a test page using the sample JSON found in the create documentation, see below:

    {
    "name": "My API Page",
    "template_path": "hubspot_default/landing_page/basic_with_form/2_col_form_left.html"
}

This is being posted to the following endpoint:

https://api.hubapi.com/content/api/v2/pages?hapikey={{hapikey}}

Once this is done, my page is created but is returned in draft mode, this is signified by the following values that are returned in your response when the page is created:

"is_draft": true,

"is_published": false,

 

Now, if we're looking to publish this page, we can make a new request to the following endpoint:

https://api.hubapi.com/content/api/v2/pages/PAGE_ID/publish-action?hapikey={{hapikey}}
This is documented in the second link above. You'll see that this endpoint is specifically targetting the page we've just created through the use of the page_id which is returned in the intial response when the page is created using the above method.
 
Once this is sent, the page we've just created will be updated and the is_published value set to true providing we receive the 204 No Content status. 

I hope this helps!

 

Matthew Willson

HubSpot Developer Support
Responder
0 Avaliação positiva
Highlighted
Colaborador Ocasional

Fixed!

I was writing the url wrong.

 

This is correct:

https://api.hubapi.com/content/api/v2/pages/XXXXXXXX/publish-action?hapikey=XXXXXXXXXXXXXXXXXXXX

4 Respostas 4
Highlighted
Moderador da HubSpot

Hi @cmoraleda 

 

This process of creating and publishing pages can be done through the use of 2 endpoints:

  1. Create a new pagehttps://developers.hubspot.com/docs/methods/pages/post_pages
  2. Publish or unpublish pageshttps://developers.hubspot.com/docs/methods/pages/post_pages_page_id_publish_action

To walk-through this with you, i've gone ahead and created a test page using the sample JSON found in the create documentation, see below:

    {
    "name": "My API Page",
    "template_path": "hubspot_default/landing_page/basic_with_form/2_col_form_left.html"
}

This is being posted to the following endpoint:

https://api.hubapi.com/content/api/v2/pages?hapikey={{hapikey}}

Once this is done, my page is created but is returned in draft mode, this is signified by the following values that are returned in your response when the page is created:

"is_draft": true,

"is_published": false,

 

Now, if we're looking to publish this page, we can make a new request to the following endpoint:

https://api.hubapi.com/content/api/v2/pages/PAGE_ID/publish-action?hapikey={{hapikey}}
This is documented in the second link above. You'll see that this endpoint is specifically targetting the page we've just created through the use of the page_id which is returned in the intial response when the page is created using the above method.
 
Once this is sent, the page we've just created will be updated and the is_published value set to true providing we receive the 204 No Content status. 

I hope this helps!

 

Matthew Willson

HubSpot Developer Support
Responder
0 Avaliação positiva
Highlighted
Colaborador Ocasional

Thanks for your answer!

I have performed the steps you comment and the answer has been this:

 

HTTP ERROR 405

Problem accessing /cospages/v1/pages/XXXXXXXX/push-buffer-live. Reason:

Method Not Allowed

 

To publish I used this url:

https://api.hubapi.com/content/api/v2/pages/XXXXXXXX/push-buffer-live?hapikey=XXXXXXXXXXXXXXXXXXXX 

Responder
0 Avaliação positiva
Highlighted
Colaborador Ocasional

Fixed!

I was writing the url wrong.

 

This is correct:

https://api.hubapi.com/content/api/v2/pages/XXXXXXXX/publish-action?hapikey=XXXXXXXXXXXXXXXXXXXX

Highlighted
Moderador da HubSpot

Hi @cmoraleda 

 

Great, glad to hear this is working for you now!

Matthew Willson

HubSpot Developer Support
Responder
0 Avaliação positiva