Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Next gen .NET SDK metadata update for multiselect #345

Open
4 tasks done
ma-gis opened this issue Dec 19, 2024 · 2 comments
Open
4 tasks done

Next gen .NET SDK metadata update for multiselect #345

ma-gis opened this issue Dec 19, 2024 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@ma-gis
Copy link

ma-gis commented Dec 19, 2024

Description of the Issue

Here is my code snippet to update doctypes which I am passing as array

        templateKey: "arms", requestBody: Array.AsReadOnly(new[] { new UpdateFolderMetadataByIdRequestBody() { Op = UpdateFolderMetadataByIdRequestBodyOpField.Replace, Path = "/doctypes", Value = "[\"Asbuilt\", \"RW Plat\"]" } }));

I had contacted Box Platform Support Team and they responded that client (Box .NET SDK) should not have \ prefixed.

So I am suspecting some bug where this information is passed to API endpoint in .NET SDK code.

Thanks for the additional information. I can confirm that, on our end, the request body which is being evaluated in the api call is
[{"op":"replace","path":"/doctypes","value":"["Asbuilt","RW Plat"]"}]

In my own testing in Postman PUT request on a multiselect metadata instance without backspaces received a successful 200 response:

curl --location --request PUT 'https://api.box.com/2.0/files/1715987212712/metadata/enterprise/multiselect'
--header 'Content-Type: application/json-patch+json'
--header 'Authorization: ••••••'
--data '[
{
"op": "add",
"path": "/dwarfs",
"value":["doc"]
}
]'

Whereas when backslashes were introduced to the value like so:
curl --location --request PUT 'https://api.box.com/2.0/files/1715987212712/metadata/enterprise/multiselect'
--header 'Content-Type: application/json-patch+json'
--header 'Authorization: ••••••'
--data '[
{
"op": "add",
"path": "/dwarfs",
"value":["doc"]
}
]'

A 400 invalid parameter error is received. You may likewise isolate the issue to the particular C# code in question by taking similar steps.

Steps to Reproduce

  1. Create a template 'arms' with multiselect field type let's say doctypes with acceptable values as doc1,doct2 and doc3
  2. Run following code
UpdateFolderMetadataByIdScope.Enterprise, templateKey: "arms", requestBody: Array.AsReadOnly(new[] { new UpdateFolderMetadataByIdRequestBody() { Op = UpdateFolderMetadataByIdRequestBodyOpField.Replace, Path = "/doctypes", Value = "[\"doc1\", \"doc2\"]" } }));

Expected Behavior

SDK should handle serialization of array items and remove backward slash before making call to API endpoint.

Error Message, Including Stack Trace

System.AggregateException: One or more errors occurred. ({"message":"Encountered invalid value for template field key=doctypes with id=3de83589-70dc-414a-92e1-7aa48d1e77be","code":"bad_request","request_id":"j8bccbhw8f93hatm"})
---> Box.Sdk.Gen.BoxApiException: {"message":"Encountered invalid value for template field key=doctypes with id=3de83589-70dc-414a-92e1-7aa48d1e77be","code":"bad_request","request_id":"j8bccbhw8f93hatm"}
at Box.Sdk.Gen.Internal.HttpClientAdapter.FetchAsync(FetchOptions options)
at Box.Sdk.Gen.Managers.FolderMetadataManager.UpdateFolderMetadataByIdAsync(String folderId, UpdateFolderMetadataByIdScope scope, String templateKey, IReadOnlyList1 requestBody, UpdateFolderMetadataByIdHeaders headers, Nullable1 cancellationToken)
at UpdateEFL.Program.ExecuteMainAsync(AppConfig appConfig) in C:\gisu-repos\UpdateEFL2016\UpdateEFL\Program.cs:line 163
--- End of inner exception stack trace ---
at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
at System.Threading.Tasks.Task.Wait()

Versions Used

.NET SDK: 1.5.0
.NET: 8.0

@mwwoda
Copy link
Contributor

mwwoda commented Dec 20, 2024

It looks like issue lies within specification. In case of multiselect, array of values should be send (as seen in your cURL). Spec describes this field as string https://developer.box.com/reference/put-folders-id-metadata-id-id/#param-%253Citem%253E-value which is incorrect. Due to the fact that we generate models based on spec, it's affecting this operation. I raised an issue internally.

In the meantime, you could try to send custom request as a workaround - https://github.com/box/box-dotnet-sdk-gen/blob/main/docs/Client.md#make-custom-http-request

@ma-gis
Copy link
Author

ma-gis commented Dec 26, 2024

Thanks for sharing workaround link and it worked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

7 participants