---
title: "Factory API examples"
date: "2024-02-14T06:18:38+00:00"
summary: "Explore practical Factory API examples for Site Factory. Learn to synchronize environments, initiate releases, list websites, and backup databases efficiently using command-line scripts."
image:
type: "page"
url: "/site-factory/factory-api-examples"
id: "7b8c599c-ad40-4d08-a041-47281e232fe9"
---

The [Factory API](/site-factory/extend/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](/site-factory/extend/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](#acsf-sync-envs)
*   [Initiating code releases](#acsf-initiate-release)
*   [Listing all websites](#acsf-list-all-websites)
*   [Backing up databases of multiple websites](#acsf-db-backup-websites)

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`](https://docs.acquia.com/downloadable-resources?cid=3e60e#section-api-dbupdatetxt) script begins a code and database update for the specified environment.

Listing all websites
--------------------

The [Site Factory API](/site-factory/extend/api) only returns data for 100 websites at a time. The `get_all_sites` function in the [`acsf-backups.php`](https://docs.acquia.com/downloadable-resources?cid=3e60e#section-acsf-backupsphp) script provides a method for retrieving data for all websites.

Backing up databases of multiple websites
-----------------------------------------

The `backup` function in [`this example script`](https://docs.acquia.com/downloadable-resources?cid=3e60e#section-acsf-backupsphp) provides a method for creating [database backups](/acquia-cloud-platform/manage-apps/back-up#backup-db) 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.