MikelCalvo / node-mailwizz

[UNOFFICIAL] MailWizz API for NodeJS
https://npmjs.org/package/node-mailwizz
ISC License
10 stars 14 forks source link

Error: Invalid API request signature. Please refer to the documentation. #1

Closed Zaheer211 closed 4 years ago

Zaheer211 commented 6 years ago

Hi,

We're using node-mailwizz and it responds with error Invalid API request signature. Please refer to documentation. when creating a list. It works well when adding a subscriber to a list or getting lists or subscribers in a list and so on.

Any help would be hugely appreciated! Thanks

brianchance commented 5 years ago

I believe the issue is GET's without a query string are getting two ??.

In Request.js, change line 100 from if (method === METHOD.GET) { to if (method === METHOD.GET && Object.keys(paramGet).length > 0) {

Could also merge the separator and apiUrl code, so...

    __sign() {
        let specialHeaderParams = this.header;
        let privateKey = this.config.secret;
        let method = this.method;
        let paramPost = this.data || {};
        let paramGet = this.query || {};
        let separator;

        let params = Object.assign({}, specialHeaderParams, paramPost);
        params = encrypt.ksort(params);

        var apiUrl = this.config.baseUrl + this.url;

        if (this.method === METHOD.GET && Object.keys(paramGet).length > 0) {
            apiUrl += ('?' + querystring.stringify(paramGet));
            separator = '&';
        } else {
            separator = '?';
        }

        let signatureString = `${method} ${apiUrl}${separator}${encrypt.serialize(params)}`;
        console.log(apiUrl);
        console.log(signatureString);
        let hash = encrypt.hmac_sha(privateKey, signatureString);

        this.header['X-MW-SIGNATURE'] = hash;
    }
designcourse commented 5 years ago

I'm getting this same issue still..

etl commented 4 years ago

This is bug and brianchance is absolutely correct.

etl commented 4 years ago

This is bug and brianchance is absolutely correct.

MikelCalvo commented 4 years ago

I fixed the code, make sure to update to 1.0.0, also do the following (I saw this posted on another github repository about the API):

Check that you have set "DISABLE SIGNATURE CHECK" to "YES" in Settings->API - direct URL: https://YOURMAILWIZZ.SERVER/backend/settings/api