Invite team users via an API


#1

Hi,

We are currently developing some online classes and plan to have our students sign up through our own portal. We intend to use Cloud 9 as the teaching tool however we would like to invite our students to cloud 9 so they avoid the credit card sign up (we use the academic purchase to currently avoid that as not every student has a credit card on hand).

Is there an api to allow this to happen?

We would have a primary paid account that would issue out invite links to our students


Cloud9 for Teams FAQ
Education Plan FAQs
Education Plan FAQs
#2

Currently you must manually enter each email address into the invite screen one at a time.

This can be semi-automated with some javascript magic, though. But I could only get it working by opening the browser and running javascript in the console to manipulate the DOM with looping setTimeouts


#3

Something like using writing a script for PhantomJS to do it for you would be possible, but I would highly recommend against it, as this can be considered botting, which the Cloud9 team might ban you for.


#4

No, I think this would be fine if you can write up a JavaScript snippet that will add several users to your team by their email address.

This needs some work but something like this should work if you run it from the browser console:

var email_addresses = "me@gmail.com, you@gmail.com, us@gmail.com"; // you'll copy/paste your emails here, maybe from a csv
var emails = email_addresses.split(", ");
var email_box = document.querySelector("input");
for (var i = 0; i < emails.length; i++) {
    setTimeout(function(x) {
        return function() {
            email_box.value = emails[x];
            email_box.keydown(); // pseudocode to trigger keydown, this is the wrong function call
            document.querySelector("button[label='Add member']").click();  // trigger add member button press
            // pause here to allow the button to show up
            document.querySelector("button[label='Send Invite']").click();  // trigger confirmation button press, you'll need to find the right selector for this one cause it's missing a label
        };
    }(i), 1000*i);
}

Bonus points for anyone that can come up with a working solution :slight_smile:


Adding multiple members at teacher account
#5

We don’t have the numbers of how many students but we’re hoping it’s hundreds that will use our online portal. We don’t know when they will sign up but at some point if we are going to ask them to use cloud 9, currently at this point, they will have to enter in their credit card to what should be a free online tutorial.

Some of our users won’t have credit cards and currently it creates a barrier asking for the credit card. That is why we use the academic invite. In live sessions I get the students to walk up to a laptop and enter in their email so that they are invited to create an account without a credit card.

In the future we hope that when they sign up to our online learning website, our sever will send them an invite or have cloud 9 send out an invite (via an api call). We want the sign up process to our portal and cloud 9 to be as seamless as possible.


#6

@Ruegen awesome, that’s great feedback. In the meantime, play around with the snippet I included in my post above and you should be able to get that to invite a large list of comma separated emails to your team.


#7

This works for me.


#8
  1. Use python urllib2 with a CookieJar instance built in to auto-manage cookies for you, so you won’t have to worry about cookies. (This guy asking how to print cookies shows a good example in his question: http://stackoverflow.com/questions/35881882/how-can-i-get-cookies-using-urllib2 )

  2. Login with an account with admin rights to the Team.

    POST /auth/login HTTP/1.1
    Host: c9.io
    Connection: keep-alive
    Content-Length: 63
    Origin: https://c9.io
    x-requested-with: xmlhttprequest
    User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36
    Content-Type: application/json
    Accept: /
    Referer: https://c9.io/login
    Accept-Encoding: gzip, deflate, br
    Accept-Language: ja,en-US;q=0.8,en;q=0.6,fr-FR;q=0.4,fr;q=0.2
    Body: {“username”:“yourusername”,“password”:“yourpassword”}

  3. Then send a get to this URL, and the response will be a 20 character text token

    GET /api/nc/auth?client_id=profile_direct&responseType=direct&login_hint=&immediate=1 HTTP/1.1
    Host: c9.io
    Connection: keep-alive
    Accept: application/json
    User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36
    Content-Type: application/json
    Referer: https://c9.io/login
    Accept-Encoding: gzip, deflate, sdch, br
    Accept-Language: ja,en-US;q=0.8,en;q=0.6,fr-FR;q=0.4,fr;q=0.2

  4. Finally, send this POST

    POST /user/org/[YOURTEAMNAMEHERE]/invite?access_token=[YOURTEXTTOKENHERE] HTTP/1.1
    Host: api.c9.io
    Connection: keep-alive
    Content-Length: 37
    Accept: application/json
    Origin: https://c9.io
    User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36
    Content-Type: application/json
    Referer: https://c9.io/team/[YOURTEAMNAMEHERE]/manage
    Accept-Encoding: gzip, deflate, br
    Accept-Language: ja,en-US;q=0.8,en;q=0.6,fr-FR;q=0.4,fr;q=0.2

you can find the YOURTEAMNAMEHERE because it is in the URL of your team admin page.

So the first two requests get you a token and build up cookies in your cookiejar instance, then you just send POST to the above URL with your token, and maybe SLEEP for 5-6 seconds between each request of the email. (don’t spam their servers)

But from the sound of it, your site wouldn’t be sending them tons of requests.


#9
python adduser.py YOUTEAMNAME usermail@example.com

Also need to set environment variables to user name and password for admin account

I also made a script for adding multiple emails in a file separated by line breaks


Education Account - Auto Add Students - Please!
#10

Nice service! I have some friends living in Australia, I will tell them of it.


#11

Cheers, yes that’s us. Still hoping for an API spolution. Thanks for your input - much appreciated


#12

I have hundreds to thousands of students. Adding them by hand one at a time is terrible, and frankly - stupid.

Why can’t you create a log in page (password protect it if you must) where students can add themselves in real time?

That way I can send out a link (with password) to all my students and they can sign up themselves.

Seems drop dead simple to me…


#13

Follow the simple instructions on this site in the main README.md:

for a simple workaround that will give you the functionality that you wish.

To at least keep you over until a more permanent solution is available.


#14

Thank you! This is a seriously nice hack. Extracting the emails from my LMS (Blackboard) was harder than using this script.