Код Python, который я запускаю локально, следующий:
Код: Выделить всё
import requests
import json
API_KEY = 'the_api_key'
BASE_URL = 'https://api.float.com/v3'
EMPLOYEE_ID = '1234'
BEGIN_DATE='2024-01-01'
END_DATE='2024-01-10'
TIME_OFF_ID = '123'
HOURS='8'
updated_time_off_data = {
'timeoff_id': TIME_OFF_ID,
'start_date': BEGIN_DATE,
'end_date': END_DATE,
'timeoff_notes': 'Updated vacation details',
'people_ids': [EMPLOYEE_ID],
'hours': HOURS
}
endpoint = f"{BASE_URL}/timeoffs/{TIME_OFF_ID}"
headers = {
'Authorization': f"Bearer {API_KEY}",
'Content-Type': 'application/json'
}
try:
response = requests.patch(endpoint, headers=headers, data=json.dumps(updated_time_off_data))
response.raise_for_status()
updated_data = response.json()
print(f"Updated time off data for ID {TIME_OFF_ID}:")
print(json.dumps(updated_data, indent=4))
except requests.exceptions.HTTPError as http_err:
print(f"HTTP error occurred: {http_err}")
except Exception as err:
print(f"An error occurred: {err}")
Код: Выделить всё
import requests
import json
timeoff_id = input_data.get('TIMEOFF_ID')
start_date = input_data.get('START_DATE')
end_date = input_data.get('END_DATE')
employee_id = input_data.get('EMPLOYEE_ID')
hours = input_data.get('HOURS')
api_key = input_data.get('API_KEY')
base_url = input_data.get('BASE_URL')
updated_time_off_data = {
'timeoff_id': timeoff_id,
'start_date': start_date,
'end_date': end_date,
'timeoff_notes': 'Updated vacation details',
'people_ids': [employee_id],
'hours': hours
}
endpoint = f"{base_url}/timeoffs/{timeoff_id}"
headers = {
'Authorization': f"Bearer {api_key}",
'Content-Type': 'application/json'
}
print(f"Updated time off data: {updated_time_off_data}")
print(f"Endpoint: {endpoint}")
try:
response = requests.patch(endpoint, headers=headers, data=json.dumps(updated_time_off_data))
response.raise_for_status()
updated_data = response.json()
return {'message': updated_data}
except requests.exceptions.HTTPError as http_err:
error_message = f"HTTP error occurred: {http_err}"
print(error_message)
return {'error': error_message}
except Exception as err:
error_message = f"An error occurred: {err}"
print(error_message)
return {'error': error_message}
Ошибка Произошла ошибка HTTP: 404 Ошибка клиента: не найден для URL-адреса:https://api.float.com/api/v3/timeoffs/123
Обновленные данные о нерабочем времени: {'timeoff_id': '123', 'start_date':'2024-01-01', 'end_date': '2024-01-10', 'timeoff_notes': 'Обновленные
сведения об отпуске', 'people_ids': ['1234'], 'hours' : '8'
Конечная точка: https://api.float.com/api/v3/timeoffs/123
Произошла ошибка HTTP: 404 Ошибка клиента: не найден для URL:
https://api.float.com/api/v3/timeoffs/123
Что угодно что меня здесь не хватает? Любая помощь очень ценится. Дайте мне знать, если вам нужна дополнительная информация.
Подробнее здесь: https://stackoverflow.com/questions/786 ... off-update