Zapier Code by Zapier更新Float休假记录时出现PATCH 404错误
问题描述
搭建Zapier流程更新Float平台休假记录时,Zapier执行代码返回404错误,但本地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}")
Zapier中运行失败的代码
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}
错误信息
Error HTTP error occurred: 404 Client Error: Not Found for url: https://api.float.com/api/v3/timeoffs/123
Updated time off data: {'timeoff_id': '123', 'start_date': '2024-01-01', 'end_date': '2024-01-10', 'timeoff_notes': 'Updated vacation details', 'people_ids': ['1234'], 'hours': '8'}
Endpoint: https://api.float.com/api/v3/timeoffs/123
HTTP error occurred: 404 Client Error: Not Found for url: https://api.float.com/api/v3/timeoffs/123
问题原因与解决方案
- 核心问题:Zapier中传入的
base_url参数错误,多了一层/api路径。本地代码的BASE_URL是https://api.float.com/v3,而Zapier里的base_url变成了https://api.float.com/api/v3,导致最终接口地址多了/api,Float API无法识别该路径,返回404。 - 解决方案:检查Zapier前置步骤传入的BASE_URL参数,将其修正为
https://api.float.com/v3,去掉多余的/api部分即可解决问题。
内容的提问来源于stack exchange,提问作者IamTrying
相关产品推荐
相关产品推荐

