This article explains how to download the solution JSON for a completed solve using the API (with a Python example). This can also be translated into other programming languages.
The full API docs can be found here.
Prerequisites
Before you begin:
- Authenticate and load your access token
- The
load_token()andauthenticate()functions are given in the Authenticating and getting a token article
- The
- Having a solve ID to pass in. You can get this from:
- If using the API to submit your solves, the response to the
/solveendpoint is a list of solve ID(s) - If looking through the web UI, the solve ID can be found in the URL where it says
id=, for example this solve ID is 1234./solve?id=1234
- If using the API to submit your solves, the response to the
See the Output JSON article for interpreting the solution JSON file that is downloaded from this API endpoint. This is the same solution JSON file that is downloaded by clicking the download button on a solve in the web interface.
Example: Python code to download the solution JSON
import json
def download_solution(token, solve_id, output_path="solution.json"):
"""
Downloads the solution for a given solve_id and saves it locally.
"""
url = f"{BASE_URL}/solve/{solve_id}/solution"
headers = {"Authorization": f"Bearer {token}"}
print("⬇️ Downloading solution...")
# Step 1: Get the presigned URL for the solution
response = requests.get(url, headers=headers)
response.raise_for_status()
data = response.json()
solution_url = data.get("solution_url")
if not solution_url:
raise ValueError("❌ No presigned URL returned — the solve may not be completed or the ID may be invalid.")
# Step 2: Download the actual solution from S3
solution_response = requests.get(solution_url)
solution_response.raise_for_status()
with open(output_path, "wb") as f:
f.write(solution_response.content)
print(f"✅ Solution downloaded and saved to {output_path}")
# Main workflow
if __name__ == "__main__":
token = load_token() or authenticate()
print("✅ Authenticated")
solve_id = "<populate your solve ID here>"
download_solution(token, solve_id, "solution.json")
You can now open the downloaded solution.json in any text editor or parse it programmatically to extract objective values, variable assignments, or solver metadata.
Comments
0 comments
Please sign in to leave a comment.