Information for: DEVELOPERS   PARTNERS   SUPPORT

Factory API examples

The Factory API enables you to interact with Site Factory from the command line by scripting often repeated events.

For information about obtaining your API key or basic usage of the Factory API, see Using the Site Factory API.

The following example scripts were created by Site Factory users, and you can adapt them to meet your needs:

Synchronizing production and development environments

The following script allows you to begin the website staging process to a specified environment, after modifying the script to fit your environment’s needs:

#!/usr/bin/env bash
## Synchronizing production and development environments on
## Site Factory
## Origin: http://docs.acquia.com/site-factory/extend/api/examples

#!/bin/sh

# Update the next two lines to provide your ACSF username and API key
user="[your_ACSF_username]"
api_key="[your_API_key]"

# Machine name of target environment
to_acsf_environment="dev"

# Update the next line to provide a comma-separated list of site IDs
sites="[123,456]"

# Update the next line to provide your Site Factory domain name
curl 'https://www.[domain].acsitefactory.com/api/v1/stage' \
    -X POST -H 'Content-Type: application/json' \
    -d "{"to_env": "${to_acsf_environment}", "sites": [ ${sites} ], "detailed_status": true}" \
    -v -u $user:$api_key

Initiating code releases

The api-dbupdate.txt script begins a code and database update for the specified environment.

Listing all websites

The Site Factory API only returns data for 100 websites at a time. The get_all_sites function in the acsf-backups.php script provides a method for retrieving data for all websites.

Backing up databases of multiple websites

The backup function in this example script provides a method for creating database backups for multiple websites hosted by Site Factory, and a backup_del function to iterate through existing backups, deleting all backups older than a specified age.