Download API: Difference between revisions

From Official Factorio Wiki
Jump to navigation Jump to search
(Add new `expansion` string for `build` parameter)
 
(6 intermediate revisions by 4 users not shown)
Line 1: Line 1:
<div align="center" class="stub">'''Category:''' [[Factorio_HTTP_API_usage_guidelines#Internal|Internal API]]</div>
This API allows you to download official releases of stand-alone Factorio from the Factorio servers. It's not so much of an API as it is web scraping, but it's documented here for completeness. Please update this page if you utilize it and the information becomes outdated. Also note that's there's a separate, (semi)official API for upgrading between releases, which should be used when possible to lighten the load on the Factorio servers. (I'll document that later, promise!)
This API allows you to download official releases of stand-alone Factorio from the Factorio servers. It's not so much of an API as it is web scraping, but it's documented here for completeness. Please update this page if you utilize it and the information becomes outdated. Also note that's there's a separate, (semi)official API for upgrading between releases, which should be used when possible to lighten the load on the Factorio servers. (I'll document that later, promise!)


Line 25: Line 27:
* Where {version} is the version string of the release you wish to grab - e.g. "0.15.31". Use "latest" instead to default to the latest version for that build.
* Where {version} is the version string of the release you wish to grab - e.g. "0.15.31". Use "latest" instead to default to the latest version for that build.
* {build} is the release build, which currently comprises of:
* {build} is the release build, which currently comprises of:
** <code>alpha</code> - the current standard full-featured build.
** <code>alpha</code> - the current standard full-featured build without the space age expansion.
** <code>expansion</code> - the current standard full-featured build with the space age expansion.
** <code>demo</code> - the free, publicly accessible demo versions.
** <code>demo</code> - the free, publicly accessible demo versions.
** <code>headless</code> - for running servers on machines without graphical interface.  
** <code>headless</code> - for running servers on machines without graphical interface.  
Line 40: Line 43:


Note: Windows 32 bit and 64 bit installers are [https://en.wikipedia.org/wiki/Inno_Setup Inno Setup] formatted packages (I'll document that somewhere someday).
Note: Windows 32 bit and 64 bit installers are [https://en.wikipedia.org/wiki/Inno_Setup Inno Setup] formatted packages (I'll document that somewhere someday).
=== Using cURL to download Factorio ===
Another way to download factorio is by sending a HTTP GET request with <code>username</code> and <code>token</code> parameters to the download URL.
The authentication token can be found on the factorio website after logging into your account.
Note that the authentication token is a sensitive piece of information and should be kept secret.
The cURL command would look like:
<code>curl https://www.factorio.com/get-download/{version}/{build}/{distro}?username={username}&token={token} -L --output /path/to/output/directory/factorio.tar.xz</code>
And here is a filled in example:
<code>curl https://www.factorio.com/get-download/0.15.31/alpha/linux64?username=exampleUser&token=0123456789abcdef -L --output /tmp/factorio.tar.xz</code>


== Version Listings ==
== Version Listings ==
Line 64: Line 81:
A list of available update packages is provided at <code>https://updater.factorio.com/get-available-versions</code>.
A list of available update packages is provided at <code>https://updater.factorio.com/get-available-versions</code>.


{{Languages}}[[Category:Technical]]
[[Category:Technical]]

Latest revision as of 15:01, 29 October 2024

Category: Internal API

This API allows you to download official releases of stand-alone Factorio from the Factorio servers. It's not so much of an API as it is web scraping, but it's documented here for completeness. Please update this page if you utilize it and the information becomes outdated. Also note that's there's a separate, (semi)official API for upgrading between releases, which should be used when possible to lighten the load on the Factorio servers. (I'll document that later, promise!)

Authenticating

Downloading Factorio requires an authenticated session with the web server, which is different than the typical API authentication mechanism. Authentication uses the HTML endpoint at

https://www.factorio.com/login

Login in procedure:

  1. Create an HTTP session and send a GET request. You'll get some HTML in return.
    There's a CSRF token you'll need to grab which can be found using one of the following selectors:
    • CSS1: input[name=csrf_token] (and then take the "value" attribute).
    • XPATH1: //input[@name="csrf_token"]/@value
  2. Then send a POST request with the following parameters:
    • csrf_token: the CSRF token you grabbed earlier.
    • username_or_email: your username or email address.
    • password: your password.

Downloading

Download Factorio releases at

https://www.factorio.com/get-download/{version}/{build}/{distro}

  • Where {version} is the version string of the release you wish to grab - e.g. "0.15.31". Use "latest" instead to default to the latest version for that build.
  • {build} is the release build, which currently comprises of:
    • alpha - the current standard full-featured build without the space age expansion.
    • expansion - the current standard full-featured build with the space age expansion.
    • demo - the free, publicly accessible demo versions.
    • headless - for running servers on machines without graphical interface.
  • and {distro} is the os / type of release you wish to download, currently:
    • win64 - EXE installer for 64 bit Windows.
    • win64-manual - ZIP package for 64 bit Windows.
    • win32 - EXE installer for 32 bit Windows. No longer supported.
    • win32-manual - ZIP package for 32 bit Windows. No longer supported.
    • osx - DMG package for 64 bit Mac OS.
    • linux64 - tar.gz or tar.xz package for 64 bit Linux.
    • linux32 - tar.gz or tar.xz package for 32 bit Linux. No longer supported.

Factorio servers will correctly respond with a 404 if the requested download isn't available. Experimental builds are taken down quickly after they become obsolete, so it's best to check what versions are available before hand (documented below).

Note: Windows 32 bit and 64 bit installers are Inno Setup formatted packages (I'll document that somewhere someday).

Using cURL to download Factorio

Another way to download factorio is by sending a HTTP GET request with username and token parameters to the download URL. The authentication token can be found on the factorio website after logging into your account. Note that the authentication token is a sensitive piece of information and should be kept secret.

The cURL command would look like:

curl https://www.factorio.com/get-download/{version}/{build}/{distro}?username={username}&token={token} -L --output /path/to/output/directory/factorio.tar.xz

And here is a filled in example:

curl https://www.factorio.com/get-download/0.15.31/alpha/linux64?username=exampleUser&token=0123456789abcdef -L --output /tmp/factorio.tar.xz

Version Listings

There is an API endpoint to find the latest version number at https://factorio.com/api/latest-releases. This can be polled to automatically detect when a new update was released.

Due to changes in the Factorio website, all Factorio versions are now available on the HTML page at this location:

https://www.factorio.com/download/archive

Note: This endpoint require an authenticated session as mentioned above.

You could the grab all the informations you need by parsing the HTML using selectors but I would recommend only searching for the pattern href="/get-download/*" and then parse the relative link according to the /get-download/{version}/{build}/{distro} structure described in the section above. The second method has a clear advantage of reliability through potential HTML structure changes and simplicity.

It is also better to rely on the https://factorio.com/api/latest-releases endpoint and version number comparisons to distinguish between stable and experimental versions than to extract that information from the download HTML page with selectors.

The previous endpoints for experimental and headless releases https://www.factorio.com/download/experimental and https://www.factorio.com/download-headless now both redirect to this page containing only the latest releases:

https://www.factorio.com/download

The selectors used to retrieve version numbers and build combinations are presented below, but they are probably obsolete. I will check them later and update this section accordingly.

  • CSS1: h3
  • XPATH1: //h3

A list of available update packages is provided at https://updater.factorio.com/get-available-versions.