Anonymous edits have been disabled on the wiki. If you want to contribute please login or create an account.


Warning for game developers: PCGamingWiki staff members will only ever reach out to you using the official press@pcgamingwiki.com mail address.
Be aware of scammers claiming to be representatives or affiliates of PCGamingWiki who promise a PCGW page for a game key.

Difference between revisions of "PCGamingWiki:API"

From PCGamingWiki, the wiki about fixing PC games
m (updated API examples)
m (updated page to replace SMW examples with Cargo examples)
Line 4: Line 4:
  
 
===MediaWiki API===
 
===MediaWiki API===
{{ii}} As the PCGamingWiki is based on MediaWiki, the built-in [https://www.mediawiki.org/wiki/API:Main_page MediaWiki API] endpoint can be used to access a lot of data. Some MediaWiki extensions we use such as [https://www.semantic-mediawiki.org/wiki/Help:API Semantic MediaWiki] and [https://www.mediawiki.org/wiki/Extension:Cargo/Exporting_data#API Cargo] also exposes their own API actions through the MediaWiki API.
+
{{ii}} As the PCGamingWiki is based on MediaWiki, the built-in [https://www.mediawiki.org/wiki/API:Main_page MediaWiki API] endpoint can be used to access a lot of data. Some MediaWiki extensions we use such as [https://www.mediawiki.org/wiki/Extension:Cargo/Exporting_data#API Cargo] also exposes their own API actions through the MediaWiki API.
{{++}} If you want to retrieve the Semanic MediaWiki properties (e.g. cover image, developer, publisher, release date, etc) of a page, the {{Code|browsebysubject}} API action is currently the most relevant one if you know the page name. See [https://www.pcgamingwiki.com/w/api.php?action=browsebysubject&format=json&subject=NieR%3A%20Automata this example] ([https://www.pcgamingwiki.com/wiki/Special:ApiSandbox#action=browsebysubject&format=json&subject=NieR%3A%20Automata sandbox]).
+
{{++}} If you want to retrieve the Cargo table and their columns (e.g. cover image, developer, publisher, release date, etc) of a page, the '''[[Special:CargoTables|Cargo Tables]]''' page is the go-to place to understanding the structure, while {{Code|cargoquery}} is the API call you will mostly use. See [https://www.pcgamingwiki.com/w/api.php?action=cargoquery&tables=Infobox_game&fields=Infobox_game._pageName=Page,Infobox_game.Developers,Infobox_game.Released,Infobox_game.Cover_URL&where=Infobox_game._pageName%3D%22Half-Life%22&format=jsonfm this example] ([https://www.pcgamingwiki.com/wiki/Special:ApiSandbox#action=cargoquery&tables=Infobox_game&fields=Infobox_game._pageName=Page,Infobox_game.Developers,Infobox_game.Released,Infobox_game.Cover_URL&where=Infobox_game._pageName%3D%22Half-Life%22 sandbox]).
{{mm}} The '''[[Special:ApiSandbox|API Sandbox]]''' can be helpful in figuring the API out.
+
{{mm}} The '''[[Special:ApiSandbox|API Sandbox]]''' can be helpful in figuring the API out, and the '''[[Special:CargoQuery|Cargo Query]]''' page for figuring out Cargo.
 +
{{mm}} When querying {{Code|_pageName}} or {{Code|_pageID}} (or any Cargo column that starts with an _ underscore), the fields parts of the query needs to alias it to another name, using e.g. <code>&fields=Infobox_game._pageName=Page</code>
 +
{{mm}} See the '''[https://www.mediawiki.org/wiki/Extension:Cargo/Querying_data Extension:Cargo/Querying data]''' for even more information about Cargo.
  
  
 
'''Examples:'''
 
'''Examples:'''
{{ii}} '''Find PCGW page(s) using the SMW property [[Property:Steam AppID|Steam AppID]]:''' {{Pre|1=https://www.pcgamingwiki.com/w/api.php?action=askargs&conditions=Steam_AppID::863550&format=jsonfm}}
 
  
{{ii}} '''Retrieve all populated SMW properties for a single page:''' {{Pre|1=https://www.pcgamingwiki.com/w/api.php?action=browsebysubject&subject=Hitman_2&format=jsonfm}}
+
{{ii}} '''Retrieve some specific Cargo values from the Infobox_game table using its Steam AppID:''' {{Pre|1=https://www.pcgamingwiki.com/w/api.php?action=cargoquery&tables=Infobox_game&fields=Infobox_game._pageName=Page,Infobox_game.Developers,Infobox_game.Released,Infobox_game.Cover_URL&where=Infobox_game.Steam_AppID%20HOLDS%20%221245620%22&format=jsonfm}}
:* ''<code>Hitman_2</code>'' was retrieved using the previous example query.''
 
:* ''<code>#0#</code> at the end of the <code>subject</code> key represents the MediaWiki namespace the page resides under, see [https://www.pcgamingwiki.com/w/api.php?action=query&meta=siteinfo&siprop=namespaces the siteinfo API action] for the details. <code>#0#</code> refers to the main namespace of the site.''
 
  
{{ii}} '''Retrieve specific populated SMW properties for a single page retrieved using the the SMW property [[Property:Steam AppID|Steam AppID]]:''' {{Pre|1=https://www.pcgamingwiki.com/w/api.php?action=askargs&conditions=Steam+AppID::863550&printouts=4K_Ultra_HD{{!}}Ultra-widescreen{{!}}Published_by&format=jsonfm}}
+
:* ''If the exact page name is known, it is also possible to retrieve using <code>_pageName</code> like so: <code>&where=Infobox_game._pageName%3D"Elden Ring"</code>
:* ''This example retrieves the [[Property:4K Ultra HD|4K Ultra HD]], [[Property:Ultra-widescreen|Ultra-widescreen]], and [[Property:Published by|Published by]] SMW properties.
+
 
:* ''<code>%7C</code> is an URL encoded <code>|</code> that is used to separate multiple specified properties to retrieve.''
+
{{ii}} '''Find the page ID of a PCGW page using the Cargo Infobox_game.Steam_AppID column:''' {{Pre|1=https://www.pcgamingwiki.com/w/api.php?action=cargoquery&tables=Infobox_game&fields=Infobox_game._pageID%3DPageID%2CInfobox_game.Steam_AppID&where=Infobox_game.Steam_AppID%20HOLDS%20%221245620%22&format=jsonfm}}
 +
 
 +
{{ii}} '''Retrieve some specific Cargo values from the Infobox_game table using the page ID retrieved earlier:''' {{Pre|1=https://www.pcgamingwiki.com/w/api.php?action=cargoquery&tables=Infobox_game&fields=Infobox_game._pageName=Page,Infobox_game.Developers,Infobox_game.Released,Infobox_game.Cover_URL&where=Infobox_game._pageID%3D%22146683%22&format=jsonfm}}
 +
 
 +
{{ii}} '''Retrieve the wikitext of the page using the page ID retrieved earlier:''' {{Pre|1=https://www.pcgamingwiki.com/w/api.php?action=parse&format=json&pageid=146683&prop=wikitext}}
 +
 
 +
{{ii}} '''Retrieve specific Cargo values stored in different tables using its Steam AppID:''' {{Pre|1=https://www.pcgamingwiki.com/w/api.php?action=cargoquery&tables=Infobox_game,Video&fields=Infobox_game._pageName=Page,Infobox_game.Developers,Infobox_game.Released,Infobox_game.Cover_URL,Video.4K_Ultra_HD,Video.HDR,Video.Ultrawidescreen&join_on=Infobox_game._pageID=Video._pageID&where=Infobox_game.Steam_AppID%20HOLDS%20%221245620%22&format=jsonfm}}
 +
:* ''This example retrieves three values from the '''Video''' table as well as four values from the '''Infobox_game''' table for a single page.
  
  

Revision as of 15:57, 6 April 2022

API

This page might not be updated to reflect all available API endpoints or functionality.


MediaWiki API

As the PCGamingWiki is based on MediaWiki, the built-in MediaWiki API endpoint can be used to access a lot of data. Some MediaWiki extensions we use such as Cargo also exposes their own API actions through the MediaWiki API.
If you want to retrieve the Cargo table and their columns (e.g. cover image, developer, publisher, release date, etc) of a page, the Cargo Tables page is the go-to place to understanding the structure, while cargoquery is the API call you will mostly use. See this example (sandbox).
The API Sandbox can be helpful in figuring the API out, and the Cargo Query page for figuring out Cargo.
When querying _pageName or _pageID (or any Cargo column that starts with an _ underscore), the fields parts of the query needs to alias it to another name, using e.g. &fields=Infobox_game._pageName=Page
See the Extension:Cargo/Querying data for even more information about Cargo.


Examples:

Retrieve some specific Cargo values from the Infobox_game table using its Steam AppID:
https://www.pcgamingwiki.com/w/api.php?action=cargoquery&tables=Infobox_game&fields=Infobox_game._pageName=Page,Infobox_game.Developers,Infobox_game.Released,Infobox_game.Cover_URL&where=Infobox_game.Steam_AppID%20HOLDS%20%221245620%22&format=jsonfm
  • If the exact page name is known, it is also possible to retrieve using _pageName like so: &where=Infobox_game._pageName%3D"Elden Ring"
Find the page ID of a PCGW page using the Cargo Infobox_game.Steam_AppID column:
https://www.pcgamingwiki.com/w/api.php?action=cargoquery&tables=Infobox_game&fields=Infobox_game._pageID%3DPageID%2CInfobox_game.Steam_AppID&where=Infobox_game.Steam_AppID%20HOLDS%20%221245620%22&format=jsonfm
Retrieve some specific Cargo values from the Infobox_game table using the page ID retrieved earlier:
https://www.pcgamingwiki.com/w/api.php?action=cargoquery&tables=Infobox_game&fields=Infobox_game._pageName=Page,Infobox_game.Developers,Infobox_game.Released,Infobox_game.Cover_URL&where=Infobox_game._pageID%3D%22146683%22&format=jsonfm
Retrieve the wikitext of the page using the page ID retrieved earlier:
https://www.pcgamingwiki.com/w/api.php?action=parse&format=json&pageid=146683&prop=wikitext
Retrieve specific Cargo values stored in different tables using its Steam AppID:
https://www.pcgamingwiki.com/w/api.php?action=cargoquery&tables=Infobox_game,Video&fields=Infobox_game._pageName=Page,Infobox_game.Developers,Infobox_game.Released,Infobox_game.Cover_URL,Video.4K_Ultra_HD,Video.HDR,Video.Ultrawidescreen&join_on=Infobox_game._pageID=Video._pageID&where=Infobox_game.Steam_AppID%20HOLDS%20%221245620%22&format=jsonfm
  • This example retrieves three values from the Video table as well as four values from the Infobox_game table for a single page.


Redirect API

Our custom redirect API allows us to redirect incoming users using any registered GOG ID, Steam App ID, or WineHQ ID to the relevant PCGamingWiki page.
Source code


Examples:

GOG ID:
https://www.pcgamingwiki.com/api/gog.php?page=1785384169
Steam App ID:
https://www.pcgamingwiki.com/api/appid.php?appid=674020
WineHQ:
https://www.pcgamingwiki.com/api/winehq.php?appid=15482