In other languages:

Download API: Difference between revisions

From Official Factorio Wiki
Jump to navigation Jump to search
mNo edit summary
 
(10 intermediate revisions by 5 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 9: Line 11:
Login in procedure:
Login in procedure:


# Create an HTTP session and send a GET request. You'll get some HTML in return.<br>There's a [https://en.wikipedia.org/wiki/Cross-site_request_forgery#Synchronizer_token_pattern CSRF token] you'll need to grab which can be found using one of the following selectors:
# Create an HTTP session and send a GET request. You'll get some HTML in return.<br>There's a [[:Wikipedia:Cross-site_request_forgery#Synchronizer_token_pattern|CSRF token]] you'll need to grab which can be found using one of the following selectors:
#* CSS1: <code>input[name=csrf_token]</code> (and then take the "value" attribute).
#* CSS1: <code>input[name=csrf_token]</code> (and then take the "value" attribute).
#* XPATH1: <code>//input[@name="csrf_token"]/@value</code>
#* XPATH1: <code>//input[@name="csrf_token"]/@value</code>
Line 23: Line 25:
<code>https://www.factorio.com/get-download/{version}/{build}/{distro}</code>
<code>https://www.factorio.com/get-download/{version}/{build}/{distro}</code>


* Where {version} is the version string of the release you wish to grab - e.g. "0.15.31".
* 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.
Line 42: Line 44:


== Version Listings ==
== Version Listings ==
There is an API endpoint to find the latest version number at <code>https://factorio.com/api/latest-releases</code>. 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:


You can grab a list of Factorio versions available for download by sending a GET request to the endpoint at
<code>https://www.factorio.com/download/archive</code>


<code>https://www.factorio.com/download/stable</code>
Note: This endpoint require an authenticated session as mentioned above.


Experimental releases have their own page, which has the same interface, and can be found at:
You could the grab all the informations you need by parsing the HTML using selectors but I would recommend only searching for the pattern <code>href="/get-download/*"</code> and then parse the relative link according to the <code>/get-download/{version}/{build}/{distro}</code> structure described in the section above. The second method has a clear advantage of reliability through potential HTML structure changes and simplicity.


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


There is also another endpoint available that filters to only headless releases. (Does not contain experimental releases)
The previous endpoints for experimental and headless releases <code>https://www.factorio.com/download/experimental</code> and <code>https://www.factorio.com/download-headless</code> now both redirect to this page containing only the latest releases:


<code>https://www.factorio.com/download-headless</code>
<code>https://www.factorio.com/download</code>


Then a list of version number and build combinations can be grabbed by using either of the selectors:
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: <code>h3</code>
* CSS1: <code>h3</code>
* XPATH1: <code>//h3</code>
* XPATH1: <code>//h3</code>


Alternatively, you can skip straight to selecting all of the download links, and parsing out the version numbers and such from there. (I actually recommend this method)
A list of available update packages is provided at <code>https://updater.factorio.com/get-available-versions</code>.
* CSS1: <code>body>div>ul a</code> (and then take the "href" attribute)
* XPATH1: <code>//body/div/ul//a/@href</code>
 
 


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

Latest revision as of 09:58, 25 February 2022

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.
    • 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).

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.