I want to create a cron job on cron-job.org through their API using python.
As a result, I get 404.
I don’t know exactly what is not found
Here’s full code:
from datetime import datetime import requests, json # Cron-job.org API URL api_url = "https://cron-job.org/api/1.0/user/cronjobs" # api_url = "https://api.cron-job.org" # Your cron-job.org API key api_key = "*******************************************" # Cron job details command_url = f"https://httpbin.org/json" # Extract hour and minute try: hour = 10 minute = 30 # Prepare cron job schedule (cron-job.org takes time in hour and minute, not the standard cron format) schedule = { "minute": minute, "hour": hour, "mdays": ["*"], # Every day of the month "months": ["*"], # Every month "wdays": ["*"], # Every day of the week "enabled": True, "url": command_url } # Create headers with API key for authentication headers = { "Authorization": f"Bearer {api_key}", "Content-Type": "application/json"} # Make the API request to create the cron job response = requests.post(api_url, headers=headers, data=json.dumps( schedule)) # Check if the cron job was created successfully if response.status_code == 201: print("Cron job created successfully.") else: print(f"Failed to create cron job: {response}") print(response.text) except Exception as e: print(f'Errrrrrror: {e}')
submitted by /u/LionHeart_soul
[link] [comments]
r/learnpython I want to create a cron job on cron-job.org through their API using python. As a result, I get 404. I don’t know exactly what is not found Here’s full code: from datetime import datetime import requests, json # Cron-job.org API URL api_url = “https://cron-job.org/api/1.0/user/cronjobs” # api_url = “https://api.cron-job.org” # Your cron-job.org API key api_key = “*******************************************” # Cron job details command_url = f”https://httpbin.org/json” # Extract hour and minute try: hour = 10 minute = 30 # Prepare cron job schedule (cron-job.org takes time in hour and minute, not the standard cron format) schedule = { “minute”: minute, “hour”: hour, “mdays”: [“*”], # Every day of the month “months”: [“*”], # Every month “wdays”: [“*”], # Every day of the week “enabled”: True, “url”: command_url } # Create headers with API key for authentication headers = { “Authorization”: f”Bearer {api_key}”, “Content-Type”: “application/json”} # Make the API request to create the cron job response = requests.post(api_url, headers=headers, data=json.dumps( schedule)) # Check if the cron job was created successfully if response.status_code == 201: print(“Cron job created successfully.”) else: print(f”Failed to create cron job: {response}”) print(response.text) except Exception as e: print(f’Errrrrrror: {e}’) submitted by /u/LionHeart_soul [link] [comments]
I want to create a cron job on cron-job.org through their API using python.
As a result, I get 404.
I don’t know exactly what is not found
Here’s full code:
from datetime import datetime import requests, json # Cron-job.org API URL api_url = "https://cron-job.org/api/1.0/user/cronjobs" # api_url = "https://api.cron-job.org" # Your cron-job.org API key api_key = "*******************************************" # Cron job details command_url = f"https://httpbin.org/json" # Extract hour and minute try: hour = 10 minute = 30 # Prepare cron job schedule (cron-job.org takes time in hour and minute, not the standard cron format) schedule = { "minute": minute, "hour": hour, "mdays": ["*"], # Every day of the month "months": ["*"], # Every month "wdays": ["*"], # Every day of the week "enabled": True, "url": command_url } # Create headers with API key for authentication headers = { "Authorization": f"Bearer {api_key}", "Content-Type": "application/json"} # Make the API request to create the cron job response = requests.post(api_url, headers=headers, data=json.dumps( schedule)) # Check if the cron job was created successfully if response.status_code == 201: print("Cron job created successfully.") else: print(f"Failed to create cron job: {response}") print(response.text) except Exception as e: print(f'Errrrrrror: {e}')
submitted by /u/LionHeart_soul
[link] [comments]