Spond icon indicating copy to clipboard operation
Spond copied to clipboard

Publishing Events on Spond

Open morkohl opened this issue 3 years ago • 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)

morkohl avatar Nov 19 '22 22:11 morkohl

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)

morkohl avatar Nov 20 '22 12:11 morkohl

If you use json=event_data instead of data=... I think it will do that for you automatically.

Olen avatar Nov 20 '22 14:11 Olen

@morkohl or @Olen do you plan to progress this?

elliot-100 avatar Jul 14 '23 17:07 elliot-100

@morkohl If you have some code ready, please submit a PR, so we can try to get it implemented.

Olen avatar Jul 28 '23 06:07 Olen