create method

Future<AddOnAttachment> create(
  1. AddOnAttachment request,
  2. String courseId,
  3. String postId, {
  4. String? addOnToken,
  5. String? itemId,
  6. String? $fields,
})

Creates an add-on attachment under a post.

Requires the add-on to have permission to create new attachments on the post. This method returns the following error codes: * PERMISSION_DENIED for access errors. * INVALID_ARGUMENT if the request is malformed. * NOT_FOUND if one of the identified resources does not exist.

request - The metadata request object.

Request parameters:

courseId - Required. Identifier of the course.

postId - Optional. Deprecated, use item_id instead.

addOnToken - Optional. Token that authorizes the request. The token is passed as a query parameter when the user is redirected from Classroom to the add-on's URL. This authorization token is required for in-Classroom attachment creation but optional for partner-first attachment creation. Returns an error if not provided for partner-first attachment creation and the developer projects that created the attachment and its parent stream item do not match.

itemId - Identifier of the Announcement, CourseWork, or CourseWorkMaterial under which to create the attachment. This field is required, but is not marked as such while we are migrating from post_id.

$fields - Selector specifying which fields to include in a partial response.

Completes with a AddOnAttachment.

Completes with a commons.ApiRequestError if the API endpoint returned an error.

If the used http.Client completes with an error when making a REST call, this method will complete with the same error.

Implementation

async.Future<AddOnAttachment> create(
  AddOnAttachment request,
  core.String courseId,
  core.String postId, {
  core.String? addOnToken,
  core.String? itemId,
  core.String? $fields,
}) async {
  final body_ = convert.json.encode(request);
  final queryParams_ = <core.String, core.List<core.String>>{
    if (addOnToken != null) 'addOnToken': [addOnToken],
    if (itemId != null) 'itemId': [itemId],
    if ($fields != null) 'fields': [$fields],
  };

  final url_ = 'v1/courses/' +
      commons.escapeVariable('$courseId') +
      '/posts/' +
      commons.escapeVariable('$postId') +
      '/addOnAttachments';

  final response_ = await _requester.request(
    url_,
    'POST',
    body: body_,
    queryParams: queryParams_,
  );
  return AddOnAttachment.fromJson(
      response_ as core.Map<core.String, core.dynamic>);
}