pythonzapier

Zapier "Code by Zapier" PATCH/POST 404 Error for FLOAT Time Off Update


I have been trying to work on a Zapier process that updates an existing Float time off record. I have everything I need to update the submission from previous steps, but I am unable to update the submission from Zapier, while executing a similar script locally does work.

The Python code I run locally is the following:

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}")

But the following code in Zapier Webhooks does not work:

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}

I receive the following error:

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

Anything that I'm missing here? Any help is greatly appreciated. Let me know if you would like more information.


Solution

  • It seems like the example that you run locally is using https://api.float.com/v3 as the base_url while the Zapier error message shows that it's using https://api.float.com/api/v3 instead, which might be the reason it's failing.