Martin Loucka
Martin Loucka

Reputation: 13

Autodesk Forge; Pragmatically changing file location without new upload

I would like to change a file directory in Autodesk BIM360 Docs without new upload. Is it possible? How could it be done?

This is an example of what I would like to achieve:

1) Upload file to a temp directory in Autodesk BIM360 Docs

2) Check file content

3) If content OK - move the file to the right directory <- How to do this without a new update?

Thanks

Upvotes: 1

Views: 298

Answers (2)

sanzoghenzo
sanzoghenzo

Reputation: 658

In case someone else has the same issue, the C# API client doesn't allow to pass an object with relationships in it.

I had to extract the code needed to perform a manual REST call:

    public static async Task<bool> MoveItemToFolderAsync(
      this IItemsApi api, string projectId, string itemId, string folderId
    ) {
      dynamic postBody = new {
        jsonapi = new { version = "1.0" },
        data = new {
          type = "items",
          id = itemId,
          relationships = new {
            parent = new {
              data = new {
                type = "folders",
                id = folderId
              }
            }
          }
        }
      };
      string jsonBody = JsonConvert.SerializeObject(postBody);

      var request = new RestRequest(
        $"/data/v1/projects/{projectId}/items/{itemId}", Method.Patch);
      request.AddBody(jsonBody, "application/vnd.api+json");
      request.AddHeader (
        "Authorization", $"Bearer {api.Configuration.AccessToken}");
      request.AddHeader ("Content-Type", "application/vnd.api+json");
      var client = api.Configuration.ApiClient.RestClient;
      var response = await client.ExecuteAsync(request);
      int statusCode = (int)response.StatusCode;
      return statusCode == 200;
    }

Upvotes: 0

Augusto Goncalves
Augusto Goncalves

Reputation: 8594

You can use PATCH Items endpoint: /data/v1/projects/:project_id/items/:item_id and the following body:

{
    "jsonapi": {
        "version": "1.0"
    },
    "data": {
        "type": "items",
        "id": "CURRENT_ITEM_ID",
        "relationships": {
            "parent": {
                "data": {
                    "type": "folders",
                    "id": "DESTINATION_FOLDER_ID"
                }
            }
        }
    }
}

Upvotes: 1

Related Questions