Add custom metadata to existing node

cancel
Showing results for 
Search instead for 
Did you mean: 
alexandreb
Active Member II

Add custom metadata to existing node

Jump to solution

Hi,

I'd like to add some metadata to a file already existing on Alfresco.
I want to do it from a server-side of a node application.

I'm doing a request as following :

var request = require('request')

var r = request.put('http://localhost:8080/alfresco/api/-default-/public/alfresco/versions/1/nodes/'+nodeId+'?alf_ticket=..., function callback(err, httpResponse, body) {

   if(err){

      return console.log('Error')

   }

   console.log('Success')

}

var form = r.form()

form.append("myProperty", "myValue")

But it doesn't work, it return an error 400 'Could not read content from HTTP request body: No content to map to Object due to end of input'

I assume that I don't pass the right values, but I don't know how to do it so .. If anyone have a tip =)
Thanks in advance

1 Solution

Accepted Solutions
alexandreb
Active Member II

Re: Add custom metadata to existing node

Jump to solution

Got it done with :

var http = require("http");

var options = {
      'host': 'localhost',
      'port': '8080',
      'path': '/alfresco/api/-default-/public/alfresco/versions/1/nodes/'+nodeId+'?alf_ticket='+JSON.parse(chunk).data.ticket,
      'method': 'PUT',
      'headers': {
        'Content-Type': 'application/json'
        }
    };

var body = {
                'properties':{
                    'cm:description': 'desc'
                }
            }

var req = http.request(options, function(res){
                console.log('STATUS: ' + res.statusCode);
                console.log('HEADERS: ' + JSON.stringify(res.headers));
                res.setEncoding('utf8');
                res.on('data', function (chunk) {
                    console.log('BODY: ' + chunk);
                })
            })
req.on('error', function(e) {
     console.log('problem with request: ' + e.message);
});

req.write(JSON.stringify(body));

req.end();

Allows to update already existing properties, now looking for creating custom ones easily

View solution in original post

1 Reply
alexandreb
Active Member II

Re: Add custom metadata to existing node

Jump to solution

Got it done with :

var http = require("http");

var options = {
      'host': 'localhost',
      'port': '8080',
      'path': '/alfresco/api/-default-/public/alfresco/versions/1/nodes/'+nodeId+'?alf_ticket='+JSON.parse(chunk).data.ticket,
      'method': 'PUT',
      'headers': {
        'Content-Type': 'application/json'
        }
    };

var body = {
                'properties':{
                    'cm:description': 'desc'
                }
            }

var req = http.request(options, function(res){
                console.log('STATUS: ' + res.statusCode);
                console.log('HEADERS: ' + JSON.stringify(res.headers));
                res.setEncoding('utf8');
                res.on('data', function (chunk) {
                    console.log('BODY: ' + chunk);
                })
            })
req.on('error', function(e) {
     console.log('problem with request: ' + e.message);
});

req.write(JSON.stringify(body));

req.end();

Allows to update already existing properties, now looking for creating custom ones easily