- Blind mode tutorial
lichess.org
Donate

Download multiple games through API

I have a list of about 1000 game ids which I want to download
These are of different players
I checked the documentation at
https://lichess.org/api#operation/gamesExportIds
Can someone please point me to a working example of this as I am not able to understand how POST requests work compared to the GET requests with which I was able to export 1 game at a time?
Any help is highly appreciated! Thanks in advance.

I have a list of about 1000 game ids which I want to download These are of different players I checked the documentation at https://lichess.org/api#operation/gamesExportIds Can someone please point me to a working example of this as I am not able to understand how POST requests work compared to the GET requests with which I was able to export 1 game at a time? Any help is highly appreciated! Thanks in advance.

Same, trying to get this to work as well!

Same, trying to get this to work as well!

Hmm, I tried a few things but the POST API is something I am not able to figure out. Will post if I am able to find anything.

Hmm, I tried a few things but the POST API is something I am not able to figure out. Will post if I am able to find anything.

I'm still working on it with some help from #general-programming on the lichess discord. Will also update if I get it to work!

I'm still working on it with some help from #general-programming on the lichess discord. Will also update if I get it to work!

You can use curl from the terminal / command line like this:

curl -X POST https://lichess.org/games/export/_ids --data 'TJxUmbWK,4OtIh2oh,ILwozzRZ' -o games.pgn

Where data is your list of game IDs and games.pgn is the output file.

If you are on windows you may need to install curl or you can use an equivalent command

You can use curl from the terminal / command line like this: curl -X POST https://lichess.org/games/export/_ids --data 'TJxUmbWK,4OtIh2oh,ILwozzRZ' -o games.pgn Where data is your list of game IDs and games.pgn is the output file. If you are on windows you may need to install curl or you can use an equivalent command

Hey, @VishyNotAnand , I managed to make it to work with @synapz help!

gameIDs = ['0B9StLGe','NUfIs3FP','0ukER2Kl']

r = requests.post(
"https://lichess.org/games/export/_ids",
data = gameIDs,
params={"clocks":"true", "evals":"true", "opening":"true"}
)

newfile = "games.pgn"
with open(newfile, 'w') as outfile:
outfile.write(r.text)

Those 3 games are just examples, now I plan to pass more games. The limit per post is 300 I believe. I'll try to see how I can make this iterate until it goes through a list of say, 1200 games.

Hey, @VishyNotAnand , I managed to make it to work with @synapz help! gameIDs = ['0B9StLGe','NUfIs3FP','0ukER2Kl'] r = requests.post( "https://lichess.org/games/export/_ids", data = gameIDs, params={"clocks":"true", "evals":"true", "opening":"true"} ) newfile = "games.pgn" with open(newfile, 'w') as outfile: outfile.write(r.text) Those 3 games are just examples, now I plan to pass more games. The limit per post is 300 I believe. I'll try to see how I can make this iterate until it goes through a list of say, 1200 games.

@synapz
I tried your command
curl -X POST lichess.org/games/export/_ids --data 'TJxUmbWK,4OtIh2oh,ILwozzRZ' -o games.pgn
and in games.pgn I found below text

<html>
<head><title>301 Moved Permanently</title></head>
<body>
<center><h1>301 Moved Permanently</h1></center>
<hr><center>nginx</center>
</body>
</html>

@lc91
with your code I got the python too many values to unpack error
I modified it a bit and tried below code

import requests

r=requests.post("https://lichess.org/games/export/_ids",
data={'data':"TJxUmbWK"},
params={"clocks":"true", "evals":"true", "opening":"true"})
print(str(r))
print(r.text)
newfile = "C:/temp/games.pgn"
with open(newfile, 'w') as outfile:
outfile.write(r.text)

However even this is not outputting anything

Not sure what I am doing wrong

Thanks @synapz & @lc91 for looking into it!

@synapz I tried your command curl -X POST lichess.org/games/export/_ids --data 'TJxUmbWK,4OtIh2oh,ILwozzRZ' -o games.pgn and in games.pgn I found below text <html> <head><title>301 Moved Permanently</title></head> <body> <center><h1>301 Moved Permanently</h1></center> <hr><center>nginx</center> </body> </html> @lc91 with your code I got the python too many values to unpack error I modified it a bit and tried below code import requests r=requests.post("https://lichess.org/games/export/_ids", data={'data':"TJxUmbWK"}, params={"clocks":"true", "evals":"true", "opening":"true"}) print(str(r)) print(r.text) newfile = "C:/temp/games.pgn" with open(newfile, 'w') as outfile: outfile.write(r.text) However even this is not outputting anything Not sure what I am doing wrong Thanks @synapz & @lc91 for looking into it!

I think it's the brackets on the data= parameter. I don't think you need it to be a dictionary, at least mine worked with a plain list.

data = '0B9StLGe','NUfIs3FP','0ukER2Kl',

Although in my code I have a list called gameIDs that I use to pass to the function:

gameIDs = ['0B9StLGe','NUfIs3FP','0ukER2Kl']

r = requests.post(
"lichess.org/games/export/_ids",
data = gameIDs, # THIS IS THE ONE I'M TALKING ABOUT
params={"clocks":"true", "evals":"true", "opening":"true"}
)

I think it's the brackets on the data= parameter. I don't think you need it to be a dictionary, at least mine worked with a plain list. data = '0B9StLGe','NUfIs3FP','0ukER2Kl', Although in my code I have a list called gameIDs that I use to pass to the function: gameIDs = ['0B9StLGe','NUfIs3FP','0ukER2Kl'] r = requests.post( "lichess.org/games/export/_ids", data = gameIDs, # THIS IS THE ONE I'M TALKING ABOUT params={"clocks":"true", "evals":"true", "opening":"true"} )

which version of python are you running this code in?

which version of python are you running this code in?

Hello @VishyNotAnand , for future problems and help you'll have more success on the Lichess discord server: https://discordapp.com/invite/pvHanhg

EDIT: I believe you need to replace TJxUmbWK,4OtIh2oh,ILwozzRZ with your game IDs separated by commas. Try synapz's command now.

Hello @VishyNotAnand , for future problems and help you'll have more success on the Lichess discord server: https://discordapp.com/invite/pvHanhg EDIT: I believe you need to replace TJxUmbWK,4OtIh2oh,ILwozzRZ with your game IDs separated by commas. Try synapz's command now.

This topic has been archived and can no longer be replied to.