AnsweredAssumed Answered

membership create

Question asked by pr36897 on May 3, 2018
Latest reply on May 4, 2018 by pr36897

I am trying to create a membership using the REST API and using .Net. I am using some of the proposed code by Scott. But I keep getting the HTTP Response Code 400 Bad Request - indicating som problems with the Generated JSON. What am I missing - Any suggestions..

 

JSON:

{

  "id": null,

  "userId": "au491937",

  "courseId": "Test_491937_1",

  "dataSourceId": null,

  "created": null,

  "availability": {

  "available": "Yes",

  "duration": null

  },

  "courseRoleId": "Instructor"

}

 

 

ENDPOINT URI:

https://aarhus-test2.blackboard.com/learn/api/public/v1/courses/externalId:Test_491937_1/users/externalId:au491937

 

MEMBERSHIP CREATE USING PUT:

        public async Task<Membership> CreateObject(Membership ms)

        {

            var uri = new Uri(host + Constants.COURSE_PATH + "externalId:Test_491937_1" + "/users/externalId:au491937");

 

            Membership membership = new Membership();

            Availability availability = new Availability();

            availability.available = "Yes";

            membership.courseRoleId = "Instructor";

            membership.availability = availability;

            membership.courseId = "Test_491937_1";

            membership.userId = "au491937";

 

            try

            {

                var json = JsonConvert.SerializeObject(membership);

                var body = new StringContent(json, Encoding.UTF8, "application/json");

                HttpResponseMessage response = await client.PutAsync(uri, body);

 

                if (response.IsSuccessStatusCode)

                {

                    var content = await response.Content.ReadAsStringAsync();

                    membership = JsonConvert.DeserializeObject<Membership>(content);

                    Debug.WriteLine(@"Membership successfully created.");

                }

 

            }

            catch (Exception ex)

            {

                Debug.WriteLine(@"ERROR {0}", ex.Message);

            }

 

            return membership;

        }

 

 

REQUEST MESSAGE:

{Method: PUT, RequestUri: 'https://aarhus-test2.blackboard.com/learn/api/public/v1/courses/externalId:Test_491937_1/users/externalId:au491937', Version: 1.1, Content: System.Net.Http.StringContent, Headers:

{

  Authorization: Bearer 9FP7KM1CajoIieBsYw8ltr7CfHb92Wtm

  Content-Type: application/json; charset=utf-8

  Content-Length: 172

}}

 

 

 

Per Rosenbeck

Web Developer

Aarhus University

Denmark

Outcomes