Broken integration : page.data contains no html

When I create a page, be it draft or published, the HTML API returns no html data.

Here is the “data” object from an example response (from the REST API explorer):
“data”: {
“themeId”: false,
“title”: “My Test Page”,
“url”: “/my-test-page”
},

As per the documentation, there should be an “html” object in this data object.
The case where there is no data.html is not even suggested in the documentation.

For older entries, I do have the html object corresponding to the page, and they load perfectly.

Perhaps I’m getting no html object because the page contains nothing yet?
Unfortunately, since I’m getting nothing, my page displays no html, meaning the visual editor cannot work and I can’t add anything to the page.

So what’s going on?

Hello @RobbEesh,

Welcome to the Builder.io forum post.

Could you kindly provide an example of an HTML API network call that returns no data?

Hello and thank you for your reply.

Here is the request generated by the API explorer tool :

curl -X GET "https://cdn.builder.io/api/v3/html/page?url=https%3A%2F%2Fwww.mysite.com%2Ftext-m-2%2F&apiKey=myapikey&limit=1&includeUnpublished=true" -H "accept: */*"

I replaced the url of my site, and the api key.

Hello @RobbEesh,

We’ve encountered difficulty reproducing the issue you’ve reported on our end. In order to conduct a more thorough investigation, could you kindly provide us with your API key and the site URL where the issue is occurring? This will enable us to accurately replicate the problem and work towards a resolution.

Thanks,

Yes, thank you.

Our public API key is 0e283f9aec57480a988bd13b48a6526f.

An example URL is https://www.ethikdo.co/preview/text-m-2.

Hello @RobbEesh,

It appears that our HTML API is returning the data for other content except for the contents which has the preview error, is there anything different you are doing for integrating the content which has path /text-m-2 ?

https://cdn.builder.io/api/v3/html/page?url=%2Fa-test-page&apiKey=0e283f9aec57480a988bd13b48a6526f&limit=1

Hello Manish,

No I think the only difference is when the page was created or published.

Any page that we create/publish now seems to have the same issue. I just created one now :
https://cdn.builder.io/api/v3/html/page?url=%2Fpotato-page&apiKey=0e283f9aec57480a988bd13b48a6526f&limit=1

Hello @RobbEesh,

The newly created content also seems to return the response. Is it not working for you?

Yes, but as you can see this response contains no HTML to display on my site.
Should it not contain an “html” property in “data” ?

Hello @RobbEesh,

The reason for the response containing no HTML data is that both the content “text M 2” and “potato-page” don’t have any content, meaning there are no Builder blocks present. On the other hand, if you examine the content “a-test-page” which contains blocks, it returns the correct HTML data in response.

To resolve this, I recommend adding a Builder block first. You can use the fallback editor for that purpose or use includeUnpublished: true in your builder integration code. Once you’ve added the block, publish the content. Afterwards, the HTML API will return the correct response.



Hello and thank you Manish,

We are already using includeUnpublished, but since there is no content, the API still does not provide HTML. Is this expected ?

The solution you proposed does indeed work. Potato Page is now alive : https://www.ethikdo.co/preview/potato-page/

This workaround is a bit annoying though. How is the integration supposed to make the connection with the visual builder if there is no HTML in the API response ?
I’m assuming the visual builder requires some HTML meta data to be present so it can read from it ?
Is there an alternative way for the visual builder to recognize the page is integrated properly ?

Hello @RobbEesh,

You are indeed correct. The HTML API is supposed to return HTML data even if there is no content present. I have verified that it does return data if there is an existing Builder integration. During my testing, I was able to reproduce the issue when using the Builder fallback editor. Therefore, I suspect that something within your integration may be causing the problem.

Would you be able to share the integration code for Builder with us? This will allow us to conduct further investigation into the issue.

Thank you for your cooperation.

Hello Manish,

Sure thing, but if you are saying that HTML data should be present even if there is no content, does that not mean that my code is not even involved ?

Here is the code : builder io issue - Pastebin.com

Hello @RobbEesh,

I firmly believe that the HTML metatag should be present in the response. I will proceed to check with the product team to determine if its absence is intentional or if it could potentially be a bug.

Meanwhile, couple of things that could give you a possible workaround,

  1. Use API version v3 instead of v1
        try:
            html = get("v3/html/page", params)['data']['html'] // change from v1 to v3
        except KeyError:
            html = "Page could not be loaded"
        else:
            cache.set(url, html)
  1. When using HTML API make sure you wrap the HTML response body within the
    <builder-component>
    e.g.
    <builder-component>
     <div>
      ${builderData.data.html}
     </div>
    </builder-component>