INNER CODE UNIT · Python
sync_render_service_env_vars
phasehq/console · backend/api/utils/syncing/render/main.py:155
def sync_render_service_env_vars(secrets, credential_id, service_id):
"""
Sync environment variables to a Render service.
This function overwrites all existing environment variables with the ones defined in `secrets.json`.
There is a limit of 150 environment variables.
"""
try:
url = f"{RENDER_API_BASE_URL}/services/{service_id}/env-vars"
headers = get_render_headers(credential_id)
# Prepare the payload with environment variables from secrets.json
payload = [{"key": key, "value": value} for key, value, _ in secrets]
# Make the PUT request to overwrite the environment variables on Render service
update_response = requests.put(url, headers=headers, json=payload)
if update_response.status_code in [200, 204]:
print("Successfully synced environment variables.")
return True, {