Creating ACC Issues - POST request (Issues API for ACC) in Autodesk Construction Cloud using C#

I am trying to create a POST RestRequest in ACC Issues, and I am getting error as:

{"title":"request validation failed","details":[{"message":"should have required property 'title'","path":["#/allOf/1/required"],"context":{"value":{}}},{"message":"should have required property 'issueSubtypeId'","path":["#/allOf/1/required"],"context":{"value":{}}},{"message":"should
have required property 'status'","path":["#/allOf/1/required"],"context":{"value":{}}}],"middlewareName":"bodySchemaValidatorMiddleware"}

The BIM 360 API Issues have changed, and I am trying to replicate the same with ACC Issues, where I want the ability to access Placement in Revit Models for the highlighted Issues

My Post Request is as follows:

public async Task < RestResponse > PostIssuesAsync(string userAccessToken, string projectId, string subTypeId, string title, string description, string itemId)
{
    string BASE_URL = "https://developer.api.autodesk.com";
    string POST_ISSUES = "/construction/issues/v1/projects/{projectId}/issues";

    string projectIdEdited = projectId.Split(".")[1];
    RestClient client = new RestClient(BASE_URL);
    RestRequest request = new RestRequest(POST_ISSUES, Method.Post);
    request.AddParameter("projectId", projectIdEdited, ParameterType.UrlSegment);
    request.AddHeader("Authorization", "Bearer " + userAccessToken);
    request.AddHeader("Content-Type", "application/vnd.api+json");

    dynamic body = new JObject();
    body.data = new JObject();
    body.data.type = "issues";
    body.data.attributes = new JObject();
    body.data.attributes.title = title;
    body.data.attributes.description = description;
    body.data.attributes.issuesubTypeId = subTypeId;
    body.data.attributes.published = true;
    body.data.attributes.status = "open";
    //body.data.attributes.locationId = itemId;

    return await client.ExecuteAsync(request);
}

Upvotes: 1

Views: 194

Answers (1)

Jo&#227;o Martins
Jo&#227;o Martins

Reputation: 688

Please try with the snippet below

public static async Task<RestResponse> PostIssuesAsync(string userAccessToken, string projectId, string subTypeId, string title)
{
  string BASE_URL = "https://developer.api.autodesk.com";
  string POST_ISSUES = "/construction/issues/v1/projects/{projectId}/issues";

  string projectIdEdited = projectId.Split(".")[1];
  RestClient client = new RestClient(BASE_URL);
  RestRequest request = new RestRequest(POST_ISSUES, Method.Post);
  request.AddParameter("projectId", projectIdEdited, ParameterType.UrlSegment);
  request.AddHeader("Authorization", "Bearer " + userAccessToken);
  request.AddHeader("Content-Type", "application/json");

  dynamic body = new JObject();
  body.title = title;
  body.issueSubtypeId = subTypeId;
  body.published = true;
  body.status = "open";
  body.assignedTo = "someuresId";
  body.assignedToType = "user";
  string stringBody = ((JObject)body).ToString(Formatting.None);
  request.AddParameter("application/json", stringBody, ParameterType.RequestBody);

  return await client.ExecuteAsync(request);
}

Note that the request body structure is different from the one you're using.

Upvotes: 1

Related Questions