I am trying to create Room (called “kkkk” )for video call using Daily API programmatically
I wrote this line in a server module:
import anvil.http
responce = anvil.http.request(url="https://api.daily.co/v1/rooms", method="POST", data = {"name" : "kkkk", "privacy": "private"}, headers={"authorization":"27375241a5e7eaac5573384c54db1717408f4c64fbb9bf113fa6cc49b35a0f52"})
But I have got Http Error Status: HTTP error 400
Please help , with my thanks
stucork
September 19, 2023, 8:55am
2
Hi @khalidmnabil ,
This isn’t the best formulated question, take a look at
How to ask a good question
for tips for next time
Are you just missing "Bearer" from your "Authorization" header
You currently have
headers={"Authorization": "<Token>"}
But the docs suggest it should be
headers={"Authorization": "Bearer <Token>"}
You may also want to change your token since you’ve now made it public
1 Like
I modified my code
import anvil.http
@anvil.server.callable
def Meating_CreateRoom ( ):
responce = anvil.http.request(url="https://api.daily.co/v1/rooms", method="POST", data = {"name" : "kkkk", "privacy": "public"}, headers={"authorization":"Bearer 27375241a5e7eaac5573384c54db1717408f4c64fbb9bf113fa6cc49b35a0f52"})
return responce
The Error still exists
All I Got from Documentations:
• From Daily Docs ( An introduction to room access control with Daily API meeting tokens)
Run the following curl command to create the room:
curl --request POST \
--url https://api.daily.co/v1/rooms \
--header 'authorization: Bearer INSERT_YOUR_TOKEN_HERE' \
--header 'content-type: application/json' \
--data '{"properties":{"owner_only_broadcast":true},"name":"test-room","privacy":"private"}'
• From Anvil Docs (Calling anvil.http.request)
resp = anvil.http.request(url="https://api.mysite.com/foo",
method="POST",
data="Data to post",
headers= {
"Authentication": "my-access-key",
})
print(f"Response MIME type: {resp.content_type}")
Please help
stucork
September 19, 2023, 11:43am
4
Try this instead
@anvil.server.callable
def get_meeting( ):
try:
resp = anvil.http.request("https://api.daily.co/v1/rooms",
method="POST",
data={"name": "kkkk", "privacy": "public"},
json=True,
headers={"Authorization": "Bearer 27375241a5e7eaac5573384c54db1717408f4c64fbb9bf113fa6cc49b35a0f52"})
except anvil.http.HttpError as e:
print(e, e.content)
raise e
else:
return resp
This gives the output:
HTTP error 400 {'error': 'invalid-request-error', 'info': 'a room named kkkk already exists'}
Removing the "name" from the data fixes the error
1 Like
Yes. It works . thank you . best regards