Hi,
I'm using C# and Postman with CS 16.2.8 REST API.
I can upload a document with the REST API. I can use the PUT api/v2/nodes/{id}/categories/{category_id}/ endpoint to add Category values to a node that already has the Category applied to it.
But, when I try to upload a document (or create a folder) and include Category info in a single call, I get 500'd.
This is from the implementation notes:
V2 example to create a node with this category
Syntax
- POST api/v2/nodes
- body = {"name":"myName","parent_id":2000,"type":0,"roles":{"categories":{"[category_id]_[attribute_id]":"Value goes here"}}}
Example:
- POST api/v2/nodes
- body = {"name":"myName","parent_id":2000,"type":0,"roles":{"categories":{"15384_2":"Value goes here"}}}
Basically, everything except for "roles" works. If I use Postman, I add a new key called "roles". The value is {"categories":{"5072_2":"Staging"}}. And then when I send the request, I get back a 500 error with this body:
{
"error": "An illegal attempt was made to upload a document"
}
I'm attaching a screenshot of my Postman form.
Does anyone know what the proper request should look like?
Here is my C# code for creating a folder. The part in the (if (myCategory != null)) block doesn't work for the same reason:
public async Task<long> CreateFolderAndReturnId(long parentId, string folderName, string ticket, CategoryMetadataTest myCategory = null) {
Log.Information("Creating folder called {folderName} inside folder {parentId}", folderName, parentId);
var client = ClientFactory.CreateClient();
int folderType = 0;
long folderId = -1;
MultipartFormDataContent mfdcRequest = new MultipartFormDataContent();
StringContent type = new StringContent(folderType.ToString());
StringContent parent = new StringContent(parentId.ToString());
StringContent name = new StringContent(folderName); //name in content server
mfdcRequest.Headers.Add("OTCSTICKET", ticket);
mfdcRequest.Add(type, "type");
mfdcRequest.Add(parent, "parent_id");
mfdcRequest.Add(name, "name");
if (myCategory != null) {
string testCategoryInfo = @{"categories"":{""5072_2"":""Staging""}}";
StringContent scTest = new StringContent(testCategoryInfo);
mfdcRequest.Add(scTest, "roles");
}
try {
var response = await client.PostAsync(GetNodeUri(), mfdcRequest);
response.EnsureSuccessStatusCode();
var stringResult = await response.Content.ReadAsStringAsync();
CreateFolderResponse createFolderResponse = JsonConvert.DeserializeObject<CreateFolderResponse>(stringResult);
Log.Information("Received {stringResult}", stringResult);
folderId = createFolderResponse.results.data.properties.id;
Log.Information("Successfully created folder in {parentId}", parentId);
Log.Information("FolderId = {folderId}", folderId);
}
catch (Exception e) {
Log.Error(e, "Error creating folder in {parentId}", parentId);
}
return folderId;
}