Cannot create changeset

I’ll programm a simple syntax-editor in javascript. For the communication with osm, I use https://github.com/osmlab/osm-auth.

If I want to create a new changeset, I get everytime a “401 - Unauthorized”.


auth.xhr({
    method: 'GET',
    path: '/api/0.6/user/details'
}, done);

succeeded


auth.xhr({
            method: 'GET',
            path: '/api/0.6/permissions'
}, function(err, details) {
            console.log(err);
            console.log(details);
});

succeeded with following permissions:


<?xml version="1.0" encoding="UTF-8"?>
<osm version="0.6" generator="OpenStreetMap Server">
  <permissions>
    <permission name="allow_read_prefs"/>
    <permission name="allow_write_api"/>
    <permission name="allow_write_notes"/>
  </permissions>
</osm>

But if I create a new Changeset with:


auth.xhr({
        method: 'PUT',
        path: '/api/0.6/changeset/create',
        content:
            '<osm>'+
                '<changeset>'+
                    '<tag k="created_by" v="xxxxxxxxxxxxxxxx"/>'+
                    '<tag k="comment" v="Testing"/>'+
                '</changeset>'+
            '</osm>'
    }, function(err, details) {
        console.log(err);
        console.log(details);
});

I get

I test from a localhost-environment.

Okay, I found the mistake: The xhr-function handle the content as “application/x-www-form-urlencoded” and not as “text/xml”. If I set the Content-Type by hand, every thing works fine.


auth.xhr({
        method: 'PUT',
        path: '/api/0.6/changeset/create',
        dataType: "text/xml",
        options: {header: {"Content-Type": "text/xml"}},
        content:
            '<?xml version="1.0" encoding="UTF-8"?>'+
            '<osm version="0.6" generator="JOSM">'+
                '<changeset>'+
                    '<tag k="created_by" v="xxxxxx"/>'+
                    '<tag k="comment" v="test osmauth"/>'+
                '</changeset>'+
            '</osm>'
        }, function(err, details) {
            console.log(err);
            console.log(details);
        });