Level up your Box knowledge with brand new learning paths on Box University. Visit training.box.com to get started

Setting content-type when using box-node-sdk

New post

Comments

10 comments

  • TannerDotJS

    I realize I have to set this Content-Type in the headers just not exactly sure how to go about doing that. Where exactly do we set the headers? 

    0
    Comment actions Permalink
  • mwiller

     That's odd — the SDK should be setting the header correctly for you.  I just tested on my laptop, and unfortunately I'm not able to reproduce the issue you're seeing.  Here's the code I used to test:

    var metadata = {foo: 'bar'};
    client.folders.setMetadata(FOLDER_ID, 'global', 'properties', metadata)
        .then(console.log);

     

    In your code sample, I noticed that you're not passing anything to the method for metadata; did you forget to add that parameter?

    0
    Comment actions Permalink
  • TannerDotJS

    Thanks, this works when trying to create a custom metadata however how would I go about adding a metadata to a folder from an existing template? Im trying to copy over a folder and then add a templated metadata to that folder. 

    await client.folders.copy(copyFolder, destinationFolderID)
        .then(folderCopy => {
          console.log('copied NA');
          var meta = { foo: 'bar' };
          client.folders.setMetadata(folderCopy.ID, 'enterprise', 'afterMarketAndService', meta)
            .then(console.log);
        });

    The template is called afterMarketAndService. Not quite sure what I should have in my meta object, saw that was optional in the docs.  

    0
    Comment actions Permalink
  • mwiller

     I'm not sure that I understand your use case — you just want to add the template to the folder, with no actual data?  The metadata template itself does not contain any actual values; it's essentially a schema for the values you can add.  Without providing any actual data, just adding the template doesn't generally accomplish much.  Could you elaborate a bit more about what you're trying to do?

    0
    Comment actions Permalink
  • TannerDotJS

     so basically I have a ton of different product folders that will all contain the same file structure with in them. Im trying to write a script to copy a templated version of that folder structure into any of the new product folders I create and include the metadata with it. We already have created multiple metadata templates and I want to use those existing ones. The issues is when I copy that folder structure into the new product folder the metadata does not come with is so Im trying to manually add all those metadata tags to it after it copies over. When I copy the code example you sent me it work but create a custom metadata tag with the attributes foo:bar, not sure how to do it using a existing template rather then a new custom metadata. 

    my code looks something like this 

    const copyFolderStucture = (destinationFolderID) => {
      const folderIDs = {
        NA: '7***phone number removed for privacy***',
        China: '7***phone number removed for privacy***',
        LA: '7***phone number removed for privacy***',
        EMEAR: '7***phone number removed for privacy***',
        AUS: '7***phone number removed for privacy***',
        APAC: '7***phone number removed for privacy***'
      }
       client.folders.copy(folderIDs.NA, destinationFolderID)
        .then(folderCopy => {
          console.log('copied NA');
          client.folders.setMetadata(folderCopy.ID, 'enterprise', 'afterMarketAndService')
            .then(console.log);
        });
       client.folders.copy(folderIDs.China, destinationFolderID)
        .then(folderCopy => {
          console.log('copied China');
          var metadata = { foo: 'bar' };
          client.folders.setMetadata(folderCopy.id, 'global', 'properties', metadata)
            .then(console.log);
        });
       client.folders.copy(folderIDs.LA, destinationFolderID)
        .then(folderCopy => {
          console.log('copied Latin America');
          var metadataValues = {
            audience: "internal",
            documentType: "Q1 plans",
            competitiveDocument: "no",
            status: "active",
            author: "Jones",
            currentState: "proposal"
          };
          client.folders.addMetadata(folderCopy.id, client.metadata.scopes.ENTERPRISE, "marketingCollateral", metadataValues)
            .then(metadata => {
              console.log(metadata);
            });
        });
       client.folders.copy(folderIDs.EMEAR, destinationFolderID)
        .then(folderCopy => {
          console.log('copied EMEAR');
        });
       client.folders.copy(folderIDs.AUS, destinationFolderID)
        .then(folderCopy => {
          console.log('copied AUS');
        });
       client.folders.copy(folderIDs.APAC, destinationFolderID)
        .then(folderCopy => {
          console.log('copied APAC');
        });
    }

    Im trying a couple different way of copy over the templated meta data on different folders but non are working. I'm not sure if this is the best approach to doing this, any advice you have will help. Thanks again.

    0
    Comment actions Permalink
  • mwiller

     Ah, I see — if you want to copy the metadata from one folder to another, it's not enough just to apply the same template to the destination folder; you need to actually move the values too.  You'll need to get the metadata values from the first folder and then set them on the destination folder.

     

     

    0
    Comment actions Permalink
  • TannerDotJS

     Thanks, that helps a lot. My last question is how you would enable the cascade feature after creating a new metadata tag with client.folders.addMetadata. does the node sdk support that feature yet? 

    0
    Comment actions Permalink
  • mwiller

     Yes, it does support Metadata Cascade Policies — here's the documentation for creating one: https://github.com/box/box-node-sdk/blob/master/docs/metadata.md#create-cascade-policy

    0
    Comment actions Permalink
  • TannerDotJS

     Hey I'm having another issue getting the items back from inside a copied folder my code looks something like this 

    client.folders.copy('7***phone number removed for privacy***', destinationFolderID)
      .then(folderCopy => {
        client.folders.addMetadata(folderCopy.id, client.metadata.scopes.ENTERPRISE, 'finalMarketingCollateral', dataValuesEmear.EMEAR)
        client.metadata.createCascadePolicy('enterprise', 'finalMarketingCollateral', folderCopy.id)
        client.metadata.forceApplyCascadePolicy('78adb313-d9fc-4dfb-a1f4-cef5f9b2f37a', client.metadata.cascadeResolution.PRESERVE_EXISTING)
    
     client.folders.getItems(folderCopy.id)
          .then((items) => {
            console.log('items!!!', items, 'END');
            console.log('ENTRIES', items.entries);
          })
    }

    When I look at my item entries log in shows the folder is empty even though it does have folders within it. If I set like a minute timeout then it works and gets the correct item entries however that solution feels a bit hacky and can be effected based on how good the wifi is when running this script. Any suggestions? 

    0
    Comment actions Permalink
  • dajak42240

    I am not able to login to my router !

    192.168.0.1

    0
    Comment actions Permalink

Please sign in to leave a comment.