[#1050] addClient is returning wrong email.

Migrated from Redmine #1050 | Author: Marc Fielding
Status: New | Priority: High, I’m very impatient | Created: 2023-04-25


Hey Guys,

I’m trying to use addClient to as part of a custom signUp flow where we send a coupon code to new customers THEN add them to simply book.

error is


{
  code: -32062,
  message: 'Client email value is wrong',
  data: { field: 'email' }
}

Calling code is:


        axios.post( 'https://user-api.simplybook.me/admin',
                {
                    jsonrpc: '2,0',
                    method: 'addClient',
                    params: {name: 'marc fielding', email: 'MY_VALID_EMAIL', phone:'XXXX'},
                    id: 1,
                },
                {
                    headers: {
                        'X-Company-Login': 'oasisthaimassage',
                        'X-User-Token': token.data,
                        'Content-Type': 'application/json',
                    }
                }
            )
            .then(response => {
                console.log(response.data)
                if (response.data.error) {
                    console.log(response.data.error)
                    reject({
                        success: false,
                        data: response.data.error
                    })
                } else if (response.data.result.errors) {
                    console.log(response.data.result.errors)
                    reject({
                        success: false,
                        data: response.data.result.errors
                    })
                } else if (response.data.result) {
                    console.log(response.data.result)
                    resolve({
                        success: true,
                        data: response.data.result
                    })
                }
            })
            .catch(err => {
                reject({
                    success: false,
                    data: err
                })
            })
    })
}

Any ideas?

Thanks

Marc

Redmine Admin wrote:

hi, MY_VALID_EMAIL is for sure a wrong email

Marc Fielding wrote:

Well yeah, I just didn’t wanna put my email on the forum.

But I figured it out.

addClient takes an ARRAY which is [clientDataObject, boolean sendEmail] so the axios params code should be:


                    params: [{name: 'marc fielding', email: 'marcfielding@X.com', phone:'MY_NUMBER'}, true],

Marc Fielding wrote:

If you like we can contribute to API docs for NodeJS examples as the RPC Client example only works client side(relies on jquery)?

It’s actually pretty simple but could be better documented for those that haven’t used JSONRPC before.

Marc Fielding wrote:

We pieced it together from here(random npm lib by some guy in APAC by the looks of it) https://www.npmjs.com/package/simplybook-js-api?activeTab=code

Marc Fielding wrote:

Quick last question on this, you can repeatedly add the same client over and over with the same details? Is there a way to prevent or do we need to lookup the client first to check if it exists?

Redmine Admin wrote:

you can enable client login custom feature if its behavior suits you. Otherwise you need to lookup th client, yes.

Marc Fielding wrote:

Thanks the client login feature doesn’t seem to prevent this, is this something I should follow through here or contact support chat?

Redmine Admin wrote:

you shouldn’t be able to make 2 clients with same email with this feature. If you managed to do this please let us know