Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Error 500 while updating alarm

ANSWERED

Hi, I'm getting the following error when I try to update an alarm using the Web API:

{"errors":[{"errorType":"request","fieldName":"500","message":"An error occurred with the Fitbit Web API while processing the request. Error id: 4af775c82aaa600b7eca002b2f71245c:172.22.10.192:41571"}],"success":false}

 

The request is:

POST https://api.fitbit.com/1/user/-/devices/tracker/{device}/alarms/{alarmId}.json

Headers:

Authorization:Bearer {token}

Content-Type:application/x-www-form-urlencoded

Body:

time=08:20+02:00&enabled=true&recurring=true&weekDays=MONDAY,TUESDAY,WEDNESDAY,THURSDAY,FRIDAY&snoozeLength=5&snoozeCount=3

 

Am I doing something wrong? 

Best Answer
0 Votes
1 BEST ANSWER

Accepted Solutions

The problem was that my body wasn't url encoded. Now it works. 

View best answer in original post

Best Answer
0 Votes
2 REPLIES 2

The problem was that my body wasn't url encoded. Now it works. 

Best Answer
0 Votes

PLEASE!!! - I'm looking exactly to do this and been banging my head against a wall and my script (python) is getting BER

 

 

import urllib.parse
import gather_keys_oauth2 as Oauth2
import datetime
import fitbit
import requests
from datetime import datetime, time
import pytz
from urllib.parse import urlencode

CLIENT_ID =
CLIENT_SECRET =

server=Oauth2.OAuth2Server(CLIENT_ID, CLIENT_SECRET)
server.browser_authorize()
ACCESS_TOKEN=str(server.fitbit.client.session.token['access_token'])
REFRESH_TOKEN=str(server.fitbit.client.session.token['refresh_token'])
auth2_client=fitbit.Fitbit(CLIENT_ID,CLIENT_SECRET,Oauth2=True,access_token=ACCESS_TOKEN,refresh_token=REFRESH_TOKEN)

# Get a list of devices associated with the user
devices_data = auth2_client.get_devices()

# Extract the device ID of the first device in the list
my_device_id = devices_data[0]["id"]

# Set up the API endpoint and headers
headers = {
    "Authorization": "Bearer " + ACCESS_TOKEN,
    "Content-Type": "application/json"
}

# Replace with your desired alarm time and device ID
alarm_time = time(hour=8, minute=0)

payload = {
   # "alarm_id": 123456789,
    "time": alarm_time.strftime("%H:%M"),
    "enabled": True,
    "recurring": False,
   # "weekdays": []
}

# Make the API request
params = {
        "17:00",
        "true",
        "true"
        }
response=requests.post(url.format(device_id=my_device_id), headers=headers, params=urlencode(payload))

if response.ok:
    print("Alarm set successfully!")
else:
    print("Error setting alarm:", response.text)
 
 
--
 
Could you please possibly post how you've made your request?  I feel SO CLOSE!!
Best Answer
0 Votes