Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Publishing Events on Spond #39

Open
morkohl opened this issue Nov 19, 2022 · 4 comments
Open

Publishing Events on Spond #39

morkohl opened this issue Nov 19, 2022 · 4 comments
Labels
enhancement New feature or request question Further information is requested

Comments

@morkohl
Copy link

morkohl commented Nov 19, 2022

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
Copy link
Author

morkohl commented Nov 20, 2022

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)

@Olen
Copy link
Owner

Olen commented Nov 20, 2022

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

@elliot-100 elliot-100 added the question Further information is requested label Jan 10, 2023
@elliot-100
Copy link
Collaborator

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

@Olen
Copy link
Owner

Olen commented Jul 28, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants