The Instructure Community will enter a read-only state on November 22, 2025 as we prepare to migrate to our new Community platform in early December. Read our blog post for more info about this change.
Found this content helpful? Log in or sign up to leave a like!
Hi All, I am new to Canvas API and have a few question. I am writing my student system in ASP.Net and has a need to create a course in Canvas from my system or list grades and assignments for a particular student. Can someone has a sample code or any guideline for this? I can do it from a form or code behind.
Thanks so much.
If I understand you correctly, you will want to use this - SIS Imports - Canvas LMS REST API Documentation
In C#, you can mobilize CURL to run this with an attachment. But, I have recently been getting server errors, so I'm unsure if someone has changed something on the server or some parameters have changed since I wrote the code or if it's just an error I didn't address before today.
edit - my error above was because the @ sign I thought was part of the CURL URL was in fact not working. So I changed my code. Here's an example in C# --
This is what I'm doing for enrollment:
strAuth - this is the authorization access
string strExecute = "--insecure -F attachment=@" +
@"\\<path_for_this_file>\enrolls.csv " +
" -H " + "\"Authorization: Bearer " + strAuth + "\"" + " \"" +
"https://canvas.park.edu/api/v1/accounts/1/sis_imports.json?import_type=instructure_csv\"";
Process.Start(@"<path_for_this_file>\curl.exe", strExecute);
Tram, Have you had any success using VB.NET? I have been exploring various protocols: WebClient, HttpWebRequest , and HttpClient (requires 4.5 framework), with mixed results (GET works fine, PUT and POST not working). Since we are not on the 4.5 framework yet, I can't use HttpClient - though based on google searches, it seems to be the best option.
Mary,
We are using c# to do api calls, below is part of the code which should point you in the right direction.
public static Course GetCourseByCourseId(int courseId, string canvasApiDomain)
{
string url = "/api/v1/accounts/" + ConfigurationManager.AppSettings["PsuAccount"] + "/courses/" + courseId;
HttpHelper myHelper = new HttpHelper(canvasApiDomain);
Course myCourse = myHelper.GetSingleItem<Course>(url);
return myCourse;
}
public HttpHelper(string baseUrl)
{
_baseUrl = baseUrl;
_jsonSettings = new Newtonsoft.Json.JsonSerializerSettings();
_jsonSettings.NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore;
_jsonSettings.MissingMemberHandling = MissingMemberHandling.Ignore;
}
public T GetSingleItem<T>(string apiUrl)
{
T retval = default(T);
using (HttpClient client = SetupClient())
{
HttpResponseMessage response = client.GetAsync(apiUrl).Result;
if (response.IsSuccessStatusCode)
{
string responseResult = response.Content.ReadAsStringAsync().Result;
if (!string.IsNullOrWhiteSpace(responseResult))
{
retval = JsonConvert.DeserializeObject<T>(responseResult, _jsonSettings);
}
}
}
return retval;
}
Thanks for the information. I don't quite understand the HTTPHelper class
that you defined. Is that inherited from something else?
On Fri, Mar 11, 2016 at 7:30 AM, wbk2@psu.edu <instructure@jiveon.com>
I was just providing the outline. The HttpHelper class does not inherit from any other classes. Let me know if the below code helps.
public class HttpHelper
{
private string _baseUrl;
private JsonSerializerSettings _jsonSettings;
public HttpHelper(string baseUrl)
{ ...
private HttpClient SetupClient()
{
HttpClient client = new HttpClient();
if (!_baseUrl.StartsWith("http"))
{
_baseUrl = string.Format("https://{0}", _baseUrl);
}
client.BaseAddress = new Uri(_baseUrl);
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", ConfigurationManager.AppSettings["token"]);
//client.DefaultRequestHeaders.Add("Authorization", string.Format("Bearer {0}", ConfigurationManager.AppSettings["token"]));
return client;
}
William, Do you have an example of how to create a new User using the api and using the POST method? i was trying to use WebClient to add a new user, but i'm getting an error. Thanks.
Hello all. I am brand new to this site, and to Canvas integration, so I'm not sure I can provide any help. But it's been a few days since the last post on this thread so I thought I'd see if you're still looking for a way to create a new user by using a POST call to the API? I was able to achieve this earlier today. I'm working in a vb.net environment, so if you're interested, let me know and I'll gladly describe what I did. If you've already figured it out, no problem.
Stephane
First, you will need an Access Token, which you can create in your Canvas settings page. That is unique, cannot be shared securely with anyone and must be included in your API calls at the end with a 'access_token=<access_token>', filling in the <access_token> with your token.
You will need to find the CURL executable and set that up in your environment.
You will need your enrolls.csv, which is setup according to this web page - SIS Import Format Documentation - Canvas LMS REST API Documentation (under 'enrollments.csv'). This is a good page to bookmark. ![]()
Here is something I've used in C#, which should be able to be converted over to VB -
strAuth - this is the authorization access code
string strExecute = "--insecure -F attachment=@" +
@"\\<path_for_this_file>\enrolls.csv " +
" -H " + "\"Authorization: Bearer " + strAuth + "\"" + " \"" +
"https://canvas.park.edu/api/v1/accounts/1/sis_imports.json?import_type=instructure_csv\"";
Process.Start(@"<path_for_this_file>\curl.exe", strExecute);
Community helpTo interact with Panda Bot, our automated chatbot, you need to sign up or log in:
Sign inTo interact with Panda Bot, our automated chatbot, you need to sign up or log in:
Sign in