Publishing Events on Spond
Opened this issue · 4 comments
Hi. I'm writing an application that scrapes events from a website and is supposed to publish them to Spond.
I'm having trouble publishing an event on Spond. Maybe someone here was successful doing what I'm trying to do.
I thought I had figured out the payload format but I keep getting 415s.
I double checked the payload format a million times and when executing in curl I can successfully publish an event in Spond. I'm thinking it might be an issue with headers. But judging from the implementation of send_message()
in this lib I don't see any additional headers that are supposed to be sent when interacting with this API. Anyone got an idea what I'm doing wrong?
Once figured out I'd love to contribute to this lib.
payload (resulting from code below)
{
"heading": "test 1234566",
"spondType": "event",
"startTimestamp": "2022-11-19T23:00:00.000Z",
"openEnded": true,
"commentsDisabled": false,
"maxAccepted": 0,
"rsvpDate": null,
"location": null,
"owners": [
{
"id": "351D270163564DBEA4F91A0761102F1A"
}
],
"visibility": "INVITEES",
"participantsHidden": false,
"autoReminderType": "DISABLED",
"autoAccept": false,
"attachments": [],
"type": "EVENT",
"tasks": {
"openTasks": [],
"assignedTasks": []
},
"recipients": {
"groupMembers": [
"351D270163564DBEA4F91A0761102F1A",
"CAACE6F796AE4C279943861CD6D569B2"
],
"group": {
"id": "DD14208A27E34B2B93519977D79B8F16"
}
}
}
code
if not self.spond.cookie:
await self.spond.login()
url = self.spond.apiurl + 'sponds'
event_data = {
'heading': event['title'],
'spondType': 'event',
# 'startTimestamp': event['date'].strftime(SPOND_DATETIME_FORMAT),
'startTimestamp': '2022-11-19T23:00:00.000Z',
'openEnded': True,
'commentsDisabled': False,
'maxAccepted': 0,
'rsvpDate': None,
'location': None,
'owners': [
{
'id': self.client_account_id
}
],
'visibility': 'INVITEES',
'participantsHidden': False,
'autoReminderType': 'DISABLED',
'autoAccept': False,
'attachments': [],
'type': 'EVENT',
'tasks': {
'openTasks': [],
'assignedTasks': []
},
'recipients': {
'groupMembers': member_ids,
'group': {
'id': self.group_id
}
}
}
headers = {'auth': self.spond.auth}
res = await self.spond.clientsession.post(url, data=event_data, headers=headers)
Managed to get this working. There were two important things to consider.
First when publishing events it's necessary to explicitly supply the Content-Type
header as 'application/json'. (Why doesn't the request lib do this?)
Second, it was necessary to wrap the data argument to the POST request in json.dumps()
. You'd think that the request lib would do these sorts of things but for me that wasn't the case.
Here's the code if anyone is wondering:
headers = {
'Content-Type': 'application/json',
}
res = await self.spond.clientsession.post(url, data=json.dumps(event_data), headers=headers)
If you use json=event_data
instead of data=...
I think it will do that for you automatically.