0

I'm trying to add a custom attribute to a BIM360 folder, using instructions here: https://forge.autodesk.com/en/docs/bim360/v1/reference/http/document-management-custom-attribute-definitions-POST/

public async Task<long> addFolderCustomAttribute(string projectId, string folderId, string attributeName, string type)
    {
        var localVarPath = $"bim360/docs/v1/projects/{projectId.Replace("b.", "")}/folders/{System.Web.HttpUtility.UrlEncode(folderId)}/custom-attribute-definitions";
        var localVarQueryParams = new Dictionary<String, String>();
        Object localVarPostBody = null;
        var localVarHeaderParams = new Dictionary<String, String>(Configuration.Default.DefaultHeader);
        var localVarFormParams = new Dictionary<String, String>();
        var localVarFileParams = new Dictionary<String, FileParameter>();
        var localVarPathParams = new Dictionary<String, String>();
        String[] localVarHttpContentTypes = new String[] {
            "application/vnd.api+json"
        };
        String localVarHttpContentType = Configuration.Default.ApiClient.SelectHeaderContentType(localVarHttpContentTypes);
        if (!String.IsNullOrEmpty(Configuration.Default.AccessToken))
        {
            localVarHeaderParams["Authorization"] = "Bearer " + Configuration.Default.AccessToken;
        }
        localVarPostBody = "{\"name\":\"" + attributeName + "\", \"type\":\"" + type + "\"}";
        IRestResponse localVarResponse = (IRestResponse)await Configuration.Default.ApiClient.CallApiAsync(localVarPath,
            Method.POST, localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarFileParams,
            localVarPathParams, localVarHttpContentType);

        int localVarStatusCode = (int)localVarResponse.StatusCode;

        var response = new ApiResponse</*JsonApiCollection*/dynamic>(localVarStatusCode,
            localVarResponse.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()),
            /*(JsonApiCollection)*/ Configuration.Default.ApiClient.Deserialize(localVarResponse, typeof(JsonApiCollection)));

        var id = (long)((Autodesk.Forge.Model.DynamicJsonResponse)response.Data).Dictionary["id"];
        return id;
    }

And I receive this error: CUSTOM_ATTRIBUTE_DUPLICATE_NAME

however when I enumerate the folder's custom attributes using: https://forge.autodesk.com/en/docs/bim360/v1/reference/http/document-management-custom-attribute-definitions-GET/

public async Task<Dictionary<long, Tuple<string, string>>> getFolderCustomAttributeDefinition(string projectId, string folderId)
    {
        var localVarPath = $"bim360/docs/v1/projects/{projectId.Replace("b.", "")}/folders/{System.Web.HttpUtility.UrlEncode(folderId)}/custom-attribute-definitions";
        var localVarQueryParams = new Dictionary<String, String>();
        Object localVarPostBody = null;
        var localVarHeaderParams = new Dictionary<String, String>(Configuration.Default.DefaultHeader);
        var localVarFormParams = new Dictionary<String, String>();
        var localVarFileParams = new Dictionary<String, FileParameter>();
        var localVarPathParams = new Dictionary<String, String>();
        String[] localVarHttpContentTypes = new String[] {
            "application/vnd.api+json"
        };
        String localVarHttpContentType = Configuration.Default.ApiClient.SelectHeaderContentType(localVarHttpContentTypes);
        if (!String.IsNullOrEmpty(Configuration.Default.AccessToken))
        {
            localVarHeaderParams["Authorization"] = "Bearer " + Configuration.Default.AccessToken;
        }
        IRestResponse localVarResponse = (IRestResponse) await Configuration.Default.ApiClient.CallApiAsync(localVarPath,
            Method.GET, localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarFileParams,
            localVarPathParams, localVarHttpContentType);

        int localVarStatusCode = (int)localVarResponse.StatusCode;

        var response =  new ApiResponse</*JsonApiCollection*/dynamic>(localVarStatusCode,
            localVarResponse.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()),
            /*(JsonApiCollection)*/ Configuration.Default.ApiClient.Deserialize(localVarResponse, typeof(JsonApiCollection)));
        
        var sret = ((Autodesk.Forge.Model.DynamicJsonResponse)response.Data).Dictionary["results"];
        var resultsDic = ((Autodesk.Forge.Model.DynamicDictionary)sret).Dictionary;
        Dictionary<long, Tuple<string, string>> ret = new Dictionary<long, Tuple<string, string>>();
        foreach (var att in resultsDic) {
            var attrDic = (Autodesk.Forge.Model.DynamicDictionary)att.Value;
            ret.Add((long)attrDic.Dictionary["id"], new Tuple<string, string>((string)attrDic.Dictionary["name"], (string)attrDic.Dictionary["type"]));
        }
        return ret;
    }

It does not show any attribute with that name.

Any ideas?

Afshin
  • 1,222
  • 11
  • 29
  • as a way of troubleshooting and narrowing down, could you try with a tool like postman? And see if you see the same result? It might be that there is a syntactic error in a body and the error message is misleading. Also, attributes maybe the name exist in the predefined attribute names? I could create duplicated names if I define two attributes at different levels in folder structure. I got the duplicated name error message when I tried to define a name which exists as predefined attributes by the product. – Mikako Harada Apr 14 '21 at 20:15
  • Hi @MikakoHarada, thanks for your comment. I think this is due to the recent change in BIM360 custom attributes. the code was working fine for an older project (couple months maybe) but it seems with new attribute definition changes in projects created after March 23rd 2021 the above code won't work if there's already another attribute with that name is already created 'somewhere' in the project. I guess the API now needs to reflect the change so that we can enumerate all 'project' attributes and assign from the list to any folder. – Afshin Apr 15 '21 at 10:26
  • Afshin, you are right. Attribute behavior is different between the old project and new. I can reproduce the problem you described now. I will raise the issue with the product team. – Mikako Harada Apr 16 '21 at 04:47
  • Afshin, I am told by engineer team there is indeed a change with the behavior of custom attributes. The name of attribute def was unique per folder, while now is unique per project, starting from March 23rd. I logged an internal ticket (ALEX-40828) to ask engineer team to expose data of project attributes. Thank you for your patience – Xiaodong Liang Apr 19 '21 at 12:22
  • Thanks Xiadong, did they give any estimate? – Afshin Apr 20 '21 at 22:34
  • Afshin, I am chasing the engineers of this API to discuss. At this moment I have not exact estimation, while I may need to check with you about the use case, in order to ensure the API update will fit the requirement. Could you email me at xiaodong.liang AT autodesk.com. I will make a note with your email address. Thank you. – Xiaodong Liang Apr 23 '21 at 01:18

0 Answers0