Creating User in Canvase

145 views
Skip to first unread message

Rob Callicotte

unread,
Apr 22, 2015, 5:59:31 PM4/22/15
to canvas-l...@googlegroups.com
While creating a user in Canvas via the API, if get this message - while(1);[], does this mean it did not work?

Rob Callicotte

unread,
Apr 23, 2015, 8:45:56 AM4/23/15
to canvas-l...@googlegroups.com
I also get just plain []

Chris Herdt

unread,
Apr 23, 2015, 9:30:33 AM4/23/15
to canvas-l...@googlegroups.com
Rob, a successful request should return a user object (see https://canvas.instructure.com/doc/api/users.html#method.users.create).

Can you provide an example of the request you are sending (with the API key and any specific user data redacted)?


--

---
You received this message because you are subscribed to the Google Groups "Canvas LMS Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to canvas-lms-use...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Chris Herdt
Web Applications Developer
http://osric.com/chris/

Rob Callicotte

unread,
Apr 23, 2015, 9:31:12 AM4/23/15
to canvas-l...@googlegroups.com
Following the API, I'm not certain this is going through correctly. Anyone help?

1. I have a user
2. As far as I know my API is in the context of the Park Test server (not production)
3. User ID is the user I plan to promote 
4. Role ID is the role I plan to promote the User ID to
5. I send confirmation

Here is the URI - https://<test_server>/api/v1/accounts/1/admins?user_id=<Existing_ID>&role_id=12&send_confirmation=true&<access_token>

Does anything look amiss or has anyone seen anything not work with this in particular?



class AdminsController < ApplicationController
before_filter :require_user
before_filter :get_context
include Api::V1::Admin
# @API Make an account admin
#
# Flag an existing user as an admin within the account.
#
# @argument user_id [Required, Integer]
# The id of the user to promote.
#
# @argument role [String] (deprecated)
# The user's admin relationship with the account will be created with the
# given role. Defaults to 'AccountAdmin'.
#
# @argument role_id [Integer]
# The user's admin relationship with the account will be created with the
# given role. Defaults to the built-in role for 'AccountAdmin'.
#
# @argument send_confirmation [Boolean] Send a notification email to
# the new admin if true. Default is true.
#
# @returns Admin

On Wednesday, April 22, 2015 at 4:59:31 PM UTC-5, Rob Callicotte wrote:

Rob Callicotte

unread,
Apr 23, 2015, 9:51:54 AM4/23/15
to canvas-l...@googlegroups.com
Thanks Chris. Here's my post in C# --


protected string POST(string strURI, string strAuth)
    {
        HttpWebRequest httpWebRequest = WebRequest.Create(strURI) as HttpWebRequest;
        httpWebRequest.Headers.Add("Authorization", "Bearer " + strAuth);
        httpWebRequest.ContentType = "text/json";
        httpWebRequest.Method = "POST";
        httpWebRequest.PreAuthenticate = true;

        string strResponse = "";
        try
        {
            using (var streamWrite = new StreamWriter(httpWebRequest.GetRequestStream(), Encoding.UTF8))
            {
                streamWrite.Write(strURI);
                streamWrite.Flush();
                streamWrite.Close();

                string strSuccess = "Successful.";
                return strSuccess;
            }
        }
        catch (WebException ex)
        {
           [still working on this]

Chris Herdt

unread,
Apr 23, 2015, 1:47:45 PM4/23/15
to canvas-l...@googlegroups.com
I typically verify that the cURL examples work and then go from there. That way you can verify that you have the correct request parameters before moving it into your language-of-choice.

According to the docs, only pseudonym[unique_id] is required, but I'm getting an error with that as well:
curl -H 'Authorization: Bearer [redacted API key]' https://[my.canvas.domain]/api/v1/accounts/999999/users -X POST -d 'pseudonym\[unique_id\]=testuser'

The error returned:
{"errors":[{"message":"An error occurred.","error_code":"internal_server_error"}],"error_report_id":101249770}




Rob Callicotte

unread,
Apr 23, 2015, 2:10:44 PM4/23/15
to canvas-l...@googlegroups.com
I haven't yet used 'curl', though I assume I need to learn. Are you thinking there is a problem with this API or what do you think?

Rob Callicotte

unread,
Apr 23, 2015, 2:22:39 PM4/23/15
to canvas-l...@googlegroups.com
I'm using this API (Create Admin)

POST /api/v1/accounts/:account_id/admins

Flag an existing user as an admin within the account.

Request Parameters:

  •  user_id
    Required, Integer
  • The id of the user to promote.

  •  role
    String

    (deprecated)

    The user's admin relationship with the account will be created with the given role. Defaults to 'AccountAdmin'.

  •  role_id
    Integer

    The user's admin relationship with the account will be created with the given role. Defaults to the built-in role for 'AccountAdmin'.

  •  send_confirmation
  • Boolean

    Send a notification email to

  • the new admin if true. Default is true.

Returns a Admin

Chris Herdt

unread,
Apr 24, 2015, 10:04:34 AM4/24/15
to canvas-l...@googlegroups.com
OK, so using that API endpoint I was able to add an existing user as an account admin:
curl -H 'Authorization: Bearer [redacted API key]' https://[redacted]/api/v1/accounts/[redacted]/admins -d 'user_id=[redacted]'

This returned a JSON object containing the new admin.

Does this work for you using curl?

Rob Callicotte

unread,
Apr 24, 2015, 1:17:07 PM4/24/15
to canvas-l...@googlegroups.com
Chris, I guess not, since my use of CURL is apparently not the same as yours, which means I likely don't know CURL. Good to know it works.

What I'm not sure about is doing this in C#. I can read (GET), but have yet to POST anything in C#. I'm not getting errors in my code, but it isn't posting. Then I heard I first need to remove the person's role and then it would work. Looking into this.

Rob Callicotte

unread,
Apr 24, 2015, 4:00:34 PM4/24/15
to canvas-l...@googlegroups.com
Found help on using the CURL with this and another API function. Thanks for the help, Chris! It does work.


On Wednesday, April 22, 2015 at 4:59:31 PM UTC-5, Rob Callicotte wrote:
Reply all
Reply to author
Forward
0 new messages