Api add user and link to customer


I’m currently implementing implementing your api inside an NodeJS application. I’m using the current latest version of ERPNext.

I want to add an user with an customer account. Sometimes it does succeed, sometimes it doesn’t I haven’t found out the logic yet. And when an user is added with an customer. It creates two customer accounts. One without the link and one without the link. And the one with the link has an prefix -1` on the end of the name.

first I do these post requests:
/api/resource/User { "doctype": "User", "username": "test09823169", "first_name": "test09823169 test09823169", "full_name": "test09823169 test09823169", "email": "test09823169@test.com", "owner": "Guest", "language": "nl", "user_type": "Website User", "new_password": "huy", "send_password_update_notification": 0, "send_welcome_email": 0, "roles": [ { "doctype": "Has Role", "role": "Customer" } ] } { "naming_series": "CUST-", "doctype": "Customer", "customer_type": "Individual", "territory": "Alle gebieden", "customer_group": "Individueel", "customer_name": "test09823169 test09823169", "name": "test09823169 test09823169" }

I am also trying to achieve the same for the app I am writing for my customer.

Are you first calling the Login method for a system user? I am getting permission error if I directly call the create user API!

Appreciate your help.


Bit offtopic. But you got to query like this with the cookies stored from your request. NodeJS example:

 const request = require('request').defaults({jar: true});
 static login(done) {
    const url = api_root_url + `method/login?usr=${api_username}&pwd=${api_password}`;
    request({url: url}, (err, res) => {
        if (err) return console.error(err);

Not exactly what i wanted - but seems ERPNext does not allow website user to be created directly i.e. have to first login a user who has rights to create users and then create the user; kind of exposes the security here for applications that want people to download the app and submit sales orders