Deploy to your site using the Hosting REST API Stay organized with collections Save and categorize content based on your preferences.
TheFirebase Hosting REST API enablesprogrammatic and customizable deployments to your Firebase-hosted sites.Use this REST API to deploy new or updatedHosting content andconfiguration.
As an alternative to using theFirebase CLI fordeployments, you can use theFirebase Hosting REST API to programmaticallycreate a newversion ofassets for your site, upload files to the version, then deploy the version toyour site.
For example, with theFirebase Hosting REST API, you can:
Schedule deploys. By using the REST API in conjunction with a cron job,you can change Firebase-hosted content on a regular schedule (for example, todeploy a special holiday or event-related version of your content).
Integrate with developer tools. You can create an option in your tool todeploy your web app projects toFirebase Hosting using just one click (forexample, clicking a deploy button within an IDE).
Automate deploys when static content is generated. When a processgenerates static content programmatically (for example, user-generated contentsuch as a wiki or a news article), you can deploy the generated content asstatic files rather than serving them dynamically. This saves you expensivecompute power and serves your files in a more scalable way.
This guide first describes how to enable, authenticate, and authorize the API.Then this guide walks through an example to create aFirebase Hostingversion, to upload required files to the version, then finally to deploy theversion.
You can also learn more about this REST API in thefullHosting REST API reference documentation.
Before you begin: Enable the REST API
You must enable theFirebase Hosting REST API in the Google APIs console:
Open theFirebase Hosting API page in the Google APIs console.
When prompted, select your Firebase project.
Note: Every Firebase project has a corresponding project in the Google APIsconsole.ClickEnable on theFirebase Hosting API page.
Step 1: Get an access token to authenticate and authorize API requests
Firebase projects support Googleservice accounts,which you can use to call Firebaseserver APIs from your app server or trusted environment. If you're developingcode locally or deploying your application on-premises,you can use credentials obtainedvia this service account to authorize server requests.
To authenticate a service account and authorize itto access Firebase services, you must generate a private key file in JSONformat.
To generate a private key file for your service account:
In theFirebase console, openSettings >Service Accounts.
ClickGenerate New Private Key, then confirm by clickingGenerate Key.
Securely store the JSON file containing the key.
Use your Firebase credentials together withtheGoogle Auth Libraryfor your preferred language to retrieve a short-lived OAuth 2.0 access token:
node.js
const{google}=require('googleapis');functiongetAccessToken(){returnnewPromise(function(resolve,reject){varkey=require('./service-account.json');varjwtClient=newgoogle.auth.JWT(key.client_email,null,key.private_key,SCOPES,null);jwtClient.authorize(function(err,tokens){if(err){reject(err);return;}resolve(tokens.access_token);});});}
In this example, the Google API client library authenticates the request witha JSON web token, or JWT. For more information, seeJSON web tokens.
Python
def_get_access_token():"""Retrieve a valid access token that can be used to authorize requests. :return: Access token. """credentials=ServiceAccountCredentials.from_json_keyfile_name('service-account.json',SCOPES)access_token_info=credentials.get_access_token()returnaccess_token_info.access_token
Java
privatestaticStringgetAccessToken()throwsIOException{GoogleCredentialgoogleCredential=GoogleCredential.fromStream(newFileInputStream("service-account.json")).createScoped(Arrays.asList(SCOPES));googleCredential.refreshToken();returngoogleCredential.getAccessToken();}
After your access token expires, the token refresh method is calledautomatically to retrieve an updated access token.
Note: While using a service account is appropriate forautomated tasks inserver environments, there are other ways to obtain authorization to use theFirebase Hosting REST API. For example, project members can use the API ifthey (1) are assigned the Admin or Editor role for a project and (2) provideaccess tokens with the appropriate scope. Review theother scenarios for different OAuth flows that will allow you to obtain authorization to use theFirebase Hosting REST API.Step 2: Ensure that your project has a defaultHosting site
Before your first deployment toFirebase Hosting, your Firebase project musthave a defaultHostingSITE.
Check if your project already has a defaultHosting site by calling the
sites.listendpoint.For example:
cURL command
curl -H "Content-Type: application/json" \ -H "Authorization: BearerACCESS_TOKEN" \https://firebasehosting.googleapis.com/v1beta1/projects/PROJECT_ID/sites
Raw HTTPS request
Host:firebasehosting.googleapis.comPOST/v1beta1/projects/PROJECT_ID/sites HTTP/1.1Authorization:BearerACCESS_TOKENContent-Type:application/json
If one of the sites has
"type": "DEFAULT_SITE", then your projectalready has a defaultHosting site. Skip the remainder of this step,and move onto the next step:Create a new version for your site.If you get an empty array, then you don't have a defaultHostingsite. Complete the remainder of this step.
Decide on the
SITE_IDfor your defaultHosting site. Keep thefollowing in mind when deciding thisSITE_ID:This
SITE_IDis used to create your default Firebase subdomains: andSITE_ID.web.app .SITE_ID.firebaseapp.comA
SITE_IDhas the following requirements:- Must be a valid hostname label, meaning it cannot contain
.,_, etc. - Must be 30 characters or fewer
- Must be globally unique within Firebase
- Must be a valid hostname label, meaning it cannot contain
Note that we often recommend using your project ID as the
SITE_IDfor yourdefaultHosting site. Learn how to find this ID inUnderstand Firebase projects.Create your defaultHosting site by calling the
sites.createendpoint using your desiredSITE_IDas thesiteIdparameter.For example:
cURL command
curl -H "Content-Type: application/json" \ -H "Authorization: BearerACCESS_TOKEN" \https://firebasehosting.googleapis.com/v1beta1/projects/PROJECT_ID/sites?siteId=SITE_ID
Raw HTTPS request
Host:firebasehosting.googleapis.comPOST/v1beta1/projects/PROJECT_ID/sites?siteId=SITE_IDAuthorization:BearerACCESS_TOKENContent-Type:application/json
This API call to
sites.createreturns the following JSON: If you decide to use your project ID as the{"name":"projects/PROJECT_ID/sites/SITE_ID","defaultUrl":"https://SITE_ID.web.app","type":"DEFAULT_SITE"}
SITE_ID, note the following:In rare cases, your project ID has already been used by another project to create aHosting site. In these cases, the call to
sites.createreturns a 400 error message that says the providedSITE_IDisreserved by another project. To resolve this error, try callingsites.createagain either using the suggested string in the error message or another string until the call succeeds.
Step 3: Create a new version for your site
Your first API call is to create a newVersion for your site.Later in this guide, you’ll upload files to this version, then deploy it to yoursite.
Determine theSITE_ID for the site to which you want to deploy.
Note: For your defaultHosting site, theSITE_ID is your Firebase project ID (which is used to create your Firebase subdomainsSITE_ID.web.appandSITE_ID.firebaseapp.com).
If you’ve createdmultiple sites in your Firebase project, make sure that you’re using theSITE_ID of the site to which you’d like to deploy.Call theversions.createendpoint using yourSITE_ID in the call.
(Optional) You can also pass aFirebase Hosting configuration objectin the call, including setting a header that caches all files for a specifiedlength of time.
For example:
cURL command
curl -H "Content-Type: application/json" \ -H "Authorization: BearerACCESS_TOKEN" \ -d '{ "config": { "headers": [{ "glob": "**", "headers": { "Cache-Control": "max-age=1800" } }] } }' \https://firebasehosting.googleapis.com/v1beta1/sites/SITE_ID/versionsRaw HTTPS request
Host:firebasehosting.googleapis.comPOST/v1beta1/sites/SITE_ID/versions HTTP/1.1Authorization:BearerACCESS_TOKENContent-Type:application/jsonContent-Length:134{"config":{"headers":[{"glob":"**","headers":{"Cache-Control":"max-age=1800"}}]}}
This API call toversions.create returns the following JSON:
{ "name": "sites/SITE_ID/versions/VERSION_ID", "status": "CREATED", "config": { "headers": [{ "glob": "**", "headers": { "Cache-Control": "max-age=1800" } }] }}This response contains a unique identifier for the new version, in the format:sites/SITE_ID/versions/VERSION_ID. You’llneed this unique identifier throughout this guide to reference this specificversion.
Step 4: Specify the list of files you want to deploy
Now that you have your new version identifier, you need to tellFirebase Hosting which files you want to eventually deploy in this newversion.
Note thatHosting has a maximum size limit of 2 GB forindividual files.
This API requires that you identify files by a SHA256 hash. So, before you canmake the API call, you’ll first need to calculate a hash for each static file byGzipping the files then taking the SHA256 hash of each newly compressed file.
Important: In this call, you need to listall files that you want to include in the new version, including both new files and any existing files from previous versions (both modifiedand unmodified).You can send a maximum of 1000 file hashes in each API request. So, to list all the files for the version, you can call this endpoint multiple times; the files in each call will be added to the version.
Continuing our example, let's say that you want to deploy three files in the newversion:file1,file2, andfile3.
Gzip the files:
gzip file1 && gzip file2 && gzip file3
You now have three compressed files
file1.gz,file2.gz, andfile3.gz.Get the SHA256 hash of each compressed file:
cat file1.gz | openssl dgst -sha25666d61f86bb684d0e35f94461c1f9cf4f07a4bb3407bfbd80e518bd44368ff8f4
cat file2.gz | openssl dgst -sha256490423ebae5dcd6c2df695aea79f1f80555c62e535a2808c8115a6714863d083
cat file3.gz | openssl dgst -sha25659cae17473d7dd339fe714f4c6c514ab4470757a4fe616dfdb4d81400addf315
You now have the three SHA256 hashes of the three compressed files.
Send these three hashes in an API request to the
versions.populateFilesendpoint. List each hash by the desired path for the uploaded file (in thisexample,/file1,/file2, and/file3).For example:
cURL command
$ curl -H "Content-Type: application/json" \ -H "Authorization: BearerACCESS_TOKEN" \ -d '{ "files": { "/file1": "66d61f86bb684d0e35f94461c1f9cf4f07a4bb3407bfbd80e518bd44368ff8f4", "/file2": "490423ebae5dcd6c2df695aea79f1f80555c62e535a2808c8115a6714863d083", "/file3": "59cae17473d7dd339fe714f4c6c514ab4470757a4fe616dfdb4d81400addf315" } }' \https://firebasehosting.googleapis.com/v1beta1/sites/SITE_ID/versions/VERSION_ID:populateFilesRaw HTTPS Request
Host:firebasehosting.googleapis.comPOST/v1beta1/sites/SITE_ID/versions/VERSION_ID:populateFiles HTTP/1.1Authorization:BearerACCESS_TOKENContent-Type:application/jsonContent-Length:181{"files":{"/file1":"66d61f86bb684d0e35f94461c1f9cf4f07a4bb3407bfbd80e518bd44368ff8f4","/file2":"490423ebae5dcd6c2df695aea79f1f80555c62e535a2808c8115a6714863d083","/file3":"59cae17473d7dd339fe714f4c6c514ab4470757a4fe616dfdb4d81400addf315"}}
This API call toversions.populateFiles returns the following JSON:
{"uploadRequiredHashes":["490423ebae5dcd6c2df695aea79f1f80555c62e535a2808c8115a6714863d083","59cae17473d7dd339fe714f4c6c514ab4470757a4fe616dfdb4d81400addf315"],"uploadUrl":"https://upload-firebasehosting.googleapis.com/upload/sites/SITE_ID/versions/VERSION_ID/files"}
This response includes:
Thehash of each file that needs to be uploaded. For instance, in thisexample
Note: Some files in your new version don’t need to be uploaded, for example,if the file was already in a previous version and is unmodified for the newversion.file1had already been uploaded in a previous version, so its hashis not included in theuploadRequiredHasheslist.The
uploadUrlwhich is specific to the new version.
In the next step to upload the two new files, you’ll need the hashes and theuploadURL from theversions.populateFiles response.
Step 5: Upload required files
You need to individually upload each required file (those files which are listedinuploadRequiredHashes from theversions.populateFiles response in theprevious step). For these file uploads, you’ll need the file hashes and theuploadUrl from the previous step.
Append aforward slash and thehash of the file to the
uploadUrltocreate a file-specific URL in the format:https://upload-firebasehosting.googleapis.com/upload/sites/SITE_ID/versions/VERSION_ID/files/FILE_HASH.Upload all the required files one-by-one (in this example, only
file2.gzandfile3.gz) to the file-specific URL using a series of requests.For example, to upload the compressed
file2.gz:cURL command
curl -H "Authorization: BearerACCESS_TOKEN" \ -H "Content-Type: application/octet-stream" \ --data-binary @./file2.gz \https://upload-firebasehosting.googleapis.com/upload/sites/SITE_ID/versions/VERSION_ID/files/FILE_HASH
Raw HTTPS Request
Host:upload-firebasehosting.googleapis.comPOST/upload/sites/SITE_ID/versions/VERSION_ID/files/FILE_HASHHTTP/1.1Authorization:BearerACCESS_TOKENContent-Type:application/octet-streamContent-Length:500content-of-file2.gz
Successful uploads return a200 OK HTTPS response.
Step 6: Update the status of the version to FINALIZED
After you’ve uploaded all the files which are listed in theversions.populateFiles response, you can update the status of your version toFINALIZED.
Call theversions.patchendpoint with thestatus field in your API request set toFINALIZED.
For example:
cURL command
curl -H "Content-Type: application/json" \ -H "Authorization: BearerACCESS_TOKEN" \ -X PATCH \ -d '{"status": "FINALIZED"}' \https://firebasehosting.googleapis.com/v1beta1/sites/SITE_ID/versions/VERSION_ID?update_mask=statusRaw HTTPS Request
Host:firebasehosting.googleapis.comPATCH/v1beta1/sites/SITE_ID/versions/VERSION_ID?update_mask=status HTTP/1.1Authorization:BearerACCESS_TOKENContent-Type:application/jsonContent-Length:23{"status":"FINALIZED"}
This API call toversions.patch returns the following JSON. Check thatstatus has been updated toFINALIZED.
{"name":"sites/SITE_ID/versions/VERSION_ID","status":"FINALIZED","config":{"headers":[{ "glob": "**", "headers": {"Cache-Control": "max-age=1800"} }]},"createTime":"2018-12-02T13:41:56.905743Z","createUser":{"email":"SERVICE_ACCOUNT_EMAIL@SITE_ID.iam.gserviceaccount.com"},"finalizeTime":"2018-12-02T14:56:13.047423Z","finalizeUser":{"email":"USER_EMAIL@DOMAIN.tld"},"fileCount":"5","versionBytes":"114951"}
Step 7: Release the version for deployment
Now that you have a finalized version, release it for deployment. For this step,you need to create aRelease of your versionthat contains the hosting configuration and all the content files for your newversion.
Call thereleases.createendpoint to create your release.
For example:
cURL command
curl -H "Authorization: BearerACCESS_TOKEN" \ -X POSThttps://firebasehosting.googleapis.com/v1beta1/sites/SITE_ID/releases?versionName=sites/SITE_ID/versions/VERSION_ID
Raw HTTPS Request
Host:firebasehosting.googleapis.comPOST/v1beta1/sites/SITE_ID/releases?versionName=sites/SITE_ID/versions/VERSION_ID HTTP/1.1Authorization:BearerACCESS_TOKEN
This API call toreleases.create returns the following JSON:
{"name":"sites/SITE_ID/releases/RELEASE_ID","version":{"name":"sites/SITE_ID/versions/VERSION_ID","status":"FINALIZED","config":{"headers":[{"glob":"**","headers":{"Cache-Control":"max-age=1800"}}]}},"type":"DEPLOY","releaseTime":"2018-12-02T15:14:37Z"}
The hosting configuration and all the files for the new version should now bedeployed to your site, and you can access your files using the URLs:
https://SITE_ID.web.app/file1https://SITE_ID.web.app/file2https://SITE_ID.web.app/file3
These files are also accessible on URLs associated with yourSITE_ID.firebaseapp.com domain.
You can also see your new release listed in theHosting dashboard of theFirebase console.
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2026-02-05 UTC.