cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
jessicanashemai
Community Participant

Does anyone have a sample Python script that creates a conversation?

Working on a way to create password expiration notifications from a csv file. Would be grateful for a starting point:) 

0 Kudos
5 Replies
michael-espey
Community Participant

This https://community.canvaslms.com/docs/DOC-15537-conversations-api-able-to-create-messages-with-a-new-... may help quite a bit. I can try to put something together in Python as an example but it probably won't be until later this week, but it isn't going to be of much use at scale. I don't have anything running currently that uses these endpoints. Where are you getting the CSV from? Will it include Canvas User IDs?

Are you intending on using a generic API user hard coded in or using AUTH for each user making calls? What language are you planning on doing this in?

Happy to help where I can, but let me know if you have any specific questions. I will hop back on here as I have time.

-Michael

jsavage2
Community Contributor

Hi Jessica,

I was wrestling with this recently, too. Here's my simplest case:

import requests

API_URL = "https://<canvas_instance>/api/v1"
API_KEY = "<developer_key>"

headers = {'Authorization' : "Bearer " + API_KEY }

title = 'README'
message = 'yadda yadda yadda'
payload = {
           'recipients[]' : 1234, # canvas user_id
           'subject' : title,
           'body' : message,
           'force_new' : 'true',
           'context_code' : 'course_5678' # if it's associated with a course
          }

convo = requests.post(API_URL + "/conversations", headers = headers, data = payload)
convo.raise_for_status()

Hope this helps.

Thank you! This is great.

On Thu, Mar 14, 2019 at 9:01 PM jsavage@branded-edu.com <

Thank you this is great!

Micheal - I am actually ditching the csv part, I  have a list of emails in a python collection. The only thing I will know is the user email. Any good tips on efficient querying of users for their Canvas ID in a Sub Account when you do not know the course? 

Thank you and I appreciate your input.

Jessica