C# SDK Assign and populate existing metadata template

SOLVED
Go to solution
New Contributor

C# SDK Assign and populate existing metadata template

I am importing a large set of files from an existing document library and would like to upload the
file then assign and populate an existing metadata template named (Research). The file uploads to box fine but
I receive the following error when assigning the metadata template.

 

 

Box.V2.Exceptions.BoxException: '{"message":"Instance not found for '\"template\", \"scopedKey\", \"enterprise_xxxxx\", \"Research\"'","code":"instance_tuple_not_found","request_id":"***number removed for privacy***59xxxxxx"}'

The file upload code seems to work fine. 

 

 

using (FileStream stream = new FileStream(@row["FilePath"].ToString(), FileMode.Open))
{
      BoxFileRequest req = new BoxFileRequest()
      {
          Name = "test12.doc",
          Parent = new BoxRequestEntity() { Id = "3***phone number removed for privacy***" }
     };
     newFile = await userClient.FilesManager.UploadAsync(req, stream);
}

 

But I receive the error when I try to create the file metadata

var md = new Dictionary<string, object>()
                {
                    { "Symbol", "ABC" }
                };
Box.V2.Managers.BoxMetadataManager mm = userClient.MetadataManager;
var createMD = await mm.CreateFileMetadataAsync(newFile.Id.ToString(), md, "enterprise", "Research");

 

image.png

 

 

Thanks

 

 

 

1 REPLY
Highlighted
New Contributor

Re: C# SDK Assign and populate existing metadata template

Solved this myself by running the following curl command, which returned a list of all my templates and their template keys. The template I created was named "Research" but box created a template key of "research". So a simple capitalization issue fixed my code and I am now able to add and populate the metadata template to the file. Hope this helps someone.

 

curl https://api.box.com/2.0/metadata_templates/enterprise \ -H "Authorization: Bearer "YOUR DEVELOPER TOKEN"

Users online (252)