0

I am working on a gamification project whose goal is to build a WebGL game with Unity and post the final score as a grade on an assignment using the canvas LMS API. I need to know two things: how to authenticate using a bearer token for now (I know how to create the token already and I will need to use auth 2.0 later) and how to post a grade on an assignment using UnityWeb Request or similar. I have tried using restsharp, the vs code recognized it, but Unity did not. Also tried making a connection with node.js, Unity and node.js connected successfully, but the node wrappers I was using did not work.

In the worst cenario I would like to be able to post a comment on the assignment (I would pass the final grade as a string).

This is what I've tried with httpWebRequest:

string api_token = "bearer token here";
    //initializing HttpWebRequest object   
    HttpWebRequest request = (HttpWebRequest)WebRequest.Create("domain here");
    IWebProxy theProxy = request.Proxy;
    if (theProxy != null)
    {
        theProxy.Credentials = CredentialCache.DefaultCredentials;
    }
    CookieContainer cookies = new CookieContainer();
    request.UseDefaultCredentials = true;
    request.CookieContainer = cookies;
    request.ContentType = "application/json";
    request.CookieContainer = cookies;
    // write the "Authorization" header  
    request.Headers.Add("Authorization", "Basic " + api_token);
    request.Method = "POST";
    // get the response  
    //WebResponse response = request.GetResponse();  
    using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
    {
        StreamReader reader = new StreamReader(response.GetResponseStream());
        Debug.Log(reader.ReadToEnd());
    }

I need the node wrappers to do authentication and the post request. The node wrappers: c10. I've tried with this one a lot and node-canvas-api

I can access the api and post using postman.

  • Can you share examples of what you've tried? If Unity and node connected successfully, what are the node wrappers that you still need? What are they needed for? If for API access, can you access without them, since you're already familiar with the api? – mcint Jul 01 '21 at 10:10
  • 1
    I've updated my question because the comment section couldn't handle so much. – user16346610 Jul 02 '21 at 21:45
  • Helpful updates, thank you. Might you intercept & inspect the requests? Compare what's on the wire, since it should all be readable (once TLS-unwrapped). – mcint Jul 02 '21 at 23:12

1 Answers1

0

I found out I can use code snippets on postman to retrieve the request in a certain language. With this, I didn't need the python APIs anymore as I was able to get the code directly. I still don't know why Unity did not recognize restSharp, but python solved my problem. As it was hard for me to find how to post grades and comments on Canvas lms I will leave the PATH here for anyone who has the same problem:

PUT /api/v1/courses/:course_id/assignments/:assignment_id/submissions/:user_id

the query params are: comment[text_comment] and submission[posted_grade].