cancel
Showing results for 
Search instead for 
Did you mean: 
lukeyoung
Community Member

Calling the Conversation API

Hi,

I want to open a new conversation for multiple recipients with the form populated with subject, body and multiple receipients:

https://ourcanvasserver.com/conversations?as_user_id=67&recipients[]=4502&recipients[]=7618&subject=... 

This opens the message form but the form is blank and the to field does not have recipients.

https://ourcanvasserver.com/api/v1/conversations?as_user_id=67&recipients[]=13631&recipients[]=13647...

Also does something but it returns a huge json response and not the form.

Can this be done or is this not implemented yet? I also tried a Post that returns 

while(1);[]

Thanks

Luke

7 Replies
chofer
Community Coach
Community Coach

Hello  @lukeyoung ‌...

I don't have an answer for you, but I wanted to let you know that I will share your question with the https://community.canvaslms.com/groups/canvas-developers?sr=search&searchId=9931fa64-8f4c-4ad2-a3cd-...‌ group here in the Canvas Community in hopes that your question will get some additional exposure.  If you are not following this group, please click on the link that I have provided and then click on the "Follow" button found at the top right corner of the screen.  Good luck, Luke!

James
Navigator

 @lukeyoung  

I've got less than a couple of minutes to respond.

The while(1); happens when you do a GET inside a browser. So you think you did a POST, but I would look into that one more. Doing a POST is not as simple as just putting the URL into the browser as it defaults to GET.

Also, you will not get the form through the API call.

lukeyoung
Community Member

Thanks for answering James. The question is is it possible to open that form pre populated? 

Have a good weekend!

I did something similar many months ago (maybe years?). I was trying to generate a New Conversation pop-up based on clicking on something and pre-populating the subject line and recipient list. If I remember right, I could get it to work for a single person, but it was named based - not ID based, which wasn't going to work where there multiple students with the same name. I might have documented that adventure here in the Community, but I don't know where if I did. I certainly don't know if I still have the source code for what I was playing with as it was a non-productive adventure for me.

How is it you arrived at the parameters you included for the first call (the non-api one). When I try something similar, it just returns the inbox.

If you're returning the list of recipients and the message is prepopulated, does it need changed? If not, you could just do the whole thing through the API and bypass the UI. If you need to modify the message, it might be easier to set up your own dialog box that allows the user to edit it and then send it through the API.

ColinMurtaugh
Adventurer III

Hi Luke --

As  @James ‌ says, it's not going to be easy to simulate the POST request just using your browser.  For working with the API, I recommend checking out Postman (Postman | Supercharge your API workflow ) - it's like a specialized browser for working with REST APIs, and it makes it pretty easy to generate POST, PUT, DELETE, etc. type requests. 

It's definitely possible to create a new conversation like you describe using the API; you'll know that you've got the POST request working correctly when you get back a bunch of JSON-formatted data in the response.

--Colin

dwahl_sales
Instructure
Instructure

Hello  @lukeyoung ‌,

As others have said, if you're just trying to populate a form in Canvas via a query parameter, then it's not really using the API.  If you'd like to see an example of using the API (via AJAX) to create and send a discussion, I have a snippet from a larger script on github which you can view here:

canvas-report-discussion-post/canvas-report-discussion-post.js at master · thedannywahl/canvas-repor... 

I hope that's helpful to you.  As to your question of populating the textarea of the form with the body of the message using a query parameter, I'm afraid that's simply not possible with Canvas as it is.

chofer
Community Coach
Community Coach

Hello  @lukeyoung ‌...

It's been a while since we last heard from you, and so I thought that I would check in with you.  It looks like you have received some good help from both members of the Canvas Community and Instructure employees.  Did any of the above responses help to answer your question?  Are there any outstanding questions you have yet that are related to your initial posting?  if you feel that one of the above responses helped to answer your question, please go ahead and mark it as "Correct".  However, if you are still looking for some assistance, please post a message below so that members of the Community can continue to assist you.  For now, I am going to mark your question as "Assumed Answered" because there hasn't been any new activity in this thread since May 8th, but that won't prevent you or others from posting additional replies and/or questions related to this topic below.  I hope that's okay with you, Luke.  Looking forward to hearing from you soon!