Problem with an API script

Problem with an API script
Hello everyone.
I have a python script that authenticates through the API by creating an access_token.txt file, file session_cookies.txt and another id_value.txt file for the Sophos Enterprise console.
Then I run a second script to query data from the sub-states and it fails. Returns a 404 error.
My intention is to obtain the list of sub-states, be able to choose a specific one and obtain information about the endpoints.
Can somebody help me?

Script1

import requests
import json

# Obtener el access token
Client_ID = "yyyyyyyyyyyyyyyyyyyyyyyyyyy"
Client_Secret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
url = "https://id.sophos.com/api/v2/oauth2/token"
payload = {'grant_type': 'client_credentials', 'client_id': Client_ID, 'client_secret': Client_Secret, 'scope': 'token'}
headers = {'Content-Type': 'application/x-www-form-urlencoded'}
response = requests.post(url, headers=headers, data=payload, verify=True)

# Verificar si la autenticación fue exitosa
if response.status_code == 200:
    response_data = json.loads(response.text)
    access_token = response_data['access_token']

    # Escribir el access token en un archivo
    with open('access_token.txt', 'w') as f:
        f.write(access_token)

    # Leer el token del archivo access_token.txt
    with open('access_token.txt', 'r') as f:
        token = f.read().strip()

    # Guardar las cookies de sesión en un archivo
    with open('session_cookies.txt', 'w') as f:
        f.write(json.dumps(response.cookies.get_dict()))

    # Obtener el valor del id
    url_whoami = "https://api.central.sophos.com/whoami/v1"
    response_whoami = requests.get(url_whoami, headers={'Authorization': f'Bearer {token}'}, verify=True)

    if response_whoami.status_code == 200:
        response_whoami_data = json.loads(response_whoami.text)
        id_value = response_whoami_data['id']

        # Escribir el valor del id en un archivo
        with open('id_value.txt', 'w') as f:
            f.write(id_value)

        print("Autenticación exitosa.")
    else:
        print("Error en la autenticación. Código de estado:", response_whoami.status_code)
else:
    print("Error en la autenticación. Código de estado:", response.status_code)

Script2

import requests
import csv
import json

# Leer las cookies de sesión del archivo
with open('session_cookies.txt', 'r') as f:
    saved_cookies = json.loads(f.read())
cookies = requests.utils.cookiejar_from_dict(saved_cookies)

# Hacer una solicitud para obtener la lista de subtenants
url = "https://api.central.sophos.com/v1/tenants"
response = requests.get(url, cookies=cookies)

# Verificar si la solicitud fue exitosa
if response.status_code == 200:
    data = response.json()

    # Crear un listado de los subtenants en un fichero csv
    with open('subtenants.csv', 'w', newline='') as csvfile:
        fieldnames = ['Nombre', 'ID']
        writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
        writer.writeheader()
        for item in data['items']:
            writer.writerow({'Nombre': item['name'], 'ID': item['id']})

    # Mostrar por pantalla los subtenants ordenados alfabeticamente y numerados en un menú
    subtenants = sorted(data['items'], key=lambda x: x['name'])
    print("Lista de Subtenants:")
    for i, subtenant in enumerate(subtenants, 1):
        print(f"{i}. {subtenant['name']}")

    # Permitir al usuario seleccionar un subtenant
    choice = input("Por favor, elige un subtenant (ingresa el número correspondiente): ")
    try:
        choice = int(choice)
        if 1 <= choice <= len(subtenants):
            selected_subtenant = subtenants[choice - 1]
            print(f"Información de '{selected_subtenant['name']}':")
            print(json.dumps(selected_subtenant, indent=4))
        else:
            print("Selección inválida.")
    except ValueError:
        print("Por favor, ingresa un número válido.")
else:
    print(f"Error al obtener la lista de subtenants: {response.status_code}")