Search code examples
httpgetsquarespace

Get Squarespace Collection items with HTTP


I am trying to get content from a Squarespace blog collection to display on an alternate platform, an app. Is there a way to do this with HTTP requests? I have NOT enabled developer mode in an effort to keep the site template live.

For example, if there were a blog collection with 5 posts in it, I would like to receive a GET response that contains the data of those 5 posts to display on the app.

Any help is appreciated :)


Solution

  • Yes, all Squarespace collections and items can be requested as JSON (though not all content is always available as JSON, such as open-block fields) by using the format=json or format=json-pretty parameters.

    For example, here is the JSON version of the official Squarespace Blog:

    https://blog.squarespace.com/?format=json

    Since the information is available as JSON, it becomes a question of how you make your request. If it's being handled in the browser, you'd likely make use of JSONP.

    Once you successfully request and receive the data, it is then a question of parsing and rendering the properties you need.

    For example, you might first look at the items array, which contains a list of the items/posts in the collection (up to the maximum per-page limit; take note of the pagination property). You can then loop over the array of items, obtain the body property or other properties you need, and do with the data as needed. You could also utilize the fullUrl property to make subsequent requests to individual item URLs, appending ?format=json accordingly, as needed.

    Understand that the content within the body property is likely to be full of Squarespace-specific markup.