Interface with a Squarespace site using a node.js application.
npm install node-squarespace-middleware
npm update node-squarespace-middleware
// Get the middleware module
var nsm = require( "node-squarespace-middleware" );
var sqsMiddleware = new nsm.Middleware();
// Set config values
sqsMiddleware.set( "siteurl", "https://yoursite.squarespace.com" );
sqsMiddleware.set( "useremail", "youremail" );
sqsMiddleware.set( "userpassword", "yourpassword" );
// If you have a sitewide password enabled
sqsMiddleware.set( "sitepassword", "yoursitepassword" );
// If you are using a site in sandbox trial mode
sqsMiddleware.set( "sandboxmode", true );
// If you dont need to pre-fetch full collection data...
sqsMiddleware.set( "fulldata", false );
// Perform the auth login
sqsMiddleware.doLogin(function ( error, headers ) {
// Do stuff here
// headers = validated headers
});
// Perform a squarespace:query
sqsMiddleware.getQuery({
collection: "work",
featured: true,
limit: 6
// Pass null for {qrs} hash if not passing query string
}, null, function ( error, data ) {
// data = JSON for page collection
});
// Get json for a page
// Pass null for {qrs} hash if not passing query string
sqsMiddleware.getJson( "work", null, function ( error, data ) {
// data = {json, status}
});
// Get html for a page
// Pass null for {qrs} hash if not passing query string
sqsMiddleware.getHtml( "work", null, function ( error, data ) {
// data = {html, status}
});
// Get html AND json for a page
// Pass null for {qrs} hash if not passing query string
sqsMiddleware.getJsonAndHtml( "work", null, function ( error, data ) {
// data = {json: {json, status}, html: {html, status}}
});
// Get API data for collections and siteLayout
sqsMiddleware.getAPIData(function ( error, data ) {
// data = {collections, siteLayout}
});
// Get a block rendered through LayoutEngine
// This is a complicated process and is primarily in place to support the node-squarespace-server
// But for example, this is how you would render the first block for a given block id
sqsMiddleware.getBlockJson( blockId, function ( error, json ) {
// get just the first block
var block = json.data.layout.rows[ 0 ].columns[ 0 ].blocks[ 0 ]
sqsMiddleware.getWidgetHtml( block, function ( error, data ) {
// data = {html}, or the rendered html for the block widget
});
});
// Retrieve the logged in crumb
sqsMiddleware.getCrumb();
- get( key )
- set( key, val )
- doLogin( callback )
- getQuery( data, qrs, callback )
- getJson( url, qrs, callback )
- getHtml( url, qrs, callback )
- getJsonAndHtml( url, qrs, callback )
- getAPIData( callback )
- getAPICollection( collectionId, callback )
- getBlockJson( blockId, callback )
- getWidgetHtml( blockJSON, callback )
- getCrumb()
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request