sendinblue / APIv3-nodejs-library

SendinBlue's API v3 Node.js Library
ISC License
101 stars 47 forks source link

"Please provide Email or SMS attribute value to create user" #18

Closed mazero closed 6 years ago

mazero commented 6 years ago

I want to CreateContact but I have this error. "Please provide Email or SMS attribute value to create user" The documentation is very poor to the function 's properties

  // if not exsits, create new client sendinblue newsletter
            let newSendInBlueClient = { 
              "listIds": [ '2' ], 
              "email": req.body.email, 
              "updateEnabled": true, 
              "attributes": {
                "FIRST_NAME": req.body.firstname,
                "LAST_NAME": req.body.lastname,
                "SMS": req.body.mobilephone,
              } 
            }
            let apiInstance = new SibApiV3Sdk.ContactsApi();
            let createContact = new SibApiV3Sdk.CreateContact(newSendInBlueClient); // CreateContact | Values to create a client sendinblue           
            apiInstance.createContact(createContact).then((data) => {
              console.log('API called successfully. Returned data: ' + data);
            }, (error) => {
              console.error(error);
            });

status: 400, text: '{"code":"missing_parameter","message":"Please provide Email or SMS attribute value to create user"}', method: 'POST', path: '/v3/contacts' },

ekta-slit commented 6 years ago

Hi @mazero

Please make sure that req.body is not empty, if it is it will lead you to error Please provide Email or SMS attribute value to create user

Hope that helps!

Regards SendinBlue Team

mazero commented 6 years ago

Req.body is not empty because if i dont’ use « req.bod » but i write real attribute I have the same error (Error: Bad Request) text: '{"code":"missing_parameter","message":"Please provide Email or SMS attribute value to create user"}',

// if not exsits, create new client sendinblue newsletter too let newSendInBlueClient = { listIds: [ '2' ], email: "testor@testor.ch", updateEnabled: true, attributes: { FIRST_NAME: "aaa", LAST_NAME: "aaa", EMAIL: "testor@testor.ch", SMS: "0645535435" } } let apiInstance = new SibApiV3Sdk.ContactsApi(); let createContact = new SibApiV3Sdk.CreateContact(newSendInBlueClient); // CreateContact | Values to create a client sendinblue
apiInstance.createContact(createContact).then((data) => { console.log('API called successfully. Returned data: ' + data); }, (error) => { console.error(error); });

{ Error: Bad Request at Request.callback (E:\www\setmassage-final\web\server\node_modules\superagent\lib\node\index.js:675:11) at E:\www\setmassage-final\web\server\node_modules\superagent\lib\node\index.js:883:18 at IncomingMessage. (E:\www\setmassage-final\web\server\node_modules\superagent\lib\node\parsers\json.js:16:7) at emitNone (events.js:91:20) at IncomingMessage.emit (events.js:185:7) at endReadableNT (_stream_readable.js:974:12) at _combinedTickCallback (internal/process/next_tick.js:80:11) at process._tickCallback (internal/process/next_tick.js:104:9) status: 400, response: Response { domain: null, _events: {}, _eventsCount: 0, _maxListeners: undefined, res: IncomingMessage { _readableState: [Object], readable: false, domain: null, _events: [Object], _eventsCount: 4, _maxListeners: undefined, socket: [Object], connection: [Object], httpVersionMajor: 1, httpVersionMinor: 1, httpVersion: '1.1', complete: true, headers: [Object], rawHeaders: [Object], trailers: {}, rawTrailers: [], upgrade: false, url: '', method: null, statusCode: 400, statusMessage: 'Bad Request', client: [Object], _consuming: true, _dumped: false, req: [Object], text: '{"code":"missing_parameter","message":"Please provide Email or SMS attribute value to create user"}', read: [Function] }, request: Request { domain: null, _events: {}, _eventsCount: 0, _maxListeners: undefined, _agent: false, _formData: null, method: 'POST', url: 'https://api.sendinblue.com/v3/contacts', _header: [Object], header: [Object], writable: true, _redirects: 0, _maxRedirects: 5, cookies: '', qs: {}, qsRaw: [], _redirectList: [], _streamRequest: false, _timeout: 60000, _responseTimeout: 0, _data: [Object], req: [Object], protocol: 'https:', host: 'api.sendinblue.com', _endCalled: true, _callback: [Function], res: [Object], response: [Circular], called: true }, req: ClientRequest { domain: null, _events: [Object], _eventsCount: 3, _maxListeners: undefined, output: [], outputEncodings: [], outputCallbacks: [], outputSize: 0, writable: true, _last: true, upgrading: false, chunkedEncoding: false, shouldKeepAlive: false, useChunkedEncodingByDefault: true, sendDate: false, _removedHeader: [Object], _contentLength: 23, _hasBody: true, _trailer: '', finished: true, _headerSent: true, socket: [Object], connection: [Object], _header: 'POST /v3/contacts HTTP/1.1\r\nHost: api.sendinblue.com\r\nAccept-Encoding: gzip, deflate\r\nUser-Agent: node-superagent/3.5.2\r\napi-key: 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\r\nContent-Type: application/json\r\nAccept: application/json\r\nContent-Length: 23\r\nConnection: close\r\n\r\n', _headers: [Object], _headerNames: [Object], _onPendingData: null, agent: [Object], socketPath: undefined, timeout: undefined, method: 'POST', path: '/v3/contacts', _ended: true, parser: null, res: [Object] }, text: '{"code":"missing_parameter","message":"Please provide Email or SMS attribute value to create user"}', body: { code: 'missing_parameter', message: 'Please provide Email or SMS attribute value to create user' }, files: undefined, buffered: true, headers: { vary: 'Origin, Accept-Encoding', 'access-control-allow-credentials': 'true', 'x-frame-options': 'DENY', 'x-download-options': 'noopen', 'content-type': 'application/json; charset=utf-8', 'content-length': '99', etag: 'W/"63-gLNhL3qGLT9GQvp4oEZrUpmEUhE"', date: 'Thu, 07 Dec 2017 12:43:57 GMT', connection: 'close', 'x-sib-server': 'SENDINBLUE-web2-3', 'x-content-type-options': 'nosniff', 'x-xss-protection': '1' }, header: { vary: 'Origin, Accept-Encoding', 'access-control-allow-credentials': 'true', 'x-frame-options': 'DENY', 'x-download-options': 'noopen', 'content-type': 'application/json; charset=utf-8', 'content-length': '99', etag: 'W/"63-gLNhL3qGLT9GQvp4oEZrUpmEUhE"', date: 'Thu, 07 Dec 2017 12:43:57 GMT', connection: 'close', 'x-sib-server': 'SENDINBLUE-web2-3', 'x-content-type-options': 'nosniff', 'x-xss-protection': '1' }, statusCode: 400, status: 400, statusType: 4, info: false, ok: false, redirect: false, clientError: true, serverError: false, error: { Error: cannot POST /v3/contacts (400) at Response.toError (E:\www\setmassage-final\web\server\node_modules\superagent\lib\node\response.js:94:13) at ResponseBase._setStatusProperties (E:\www\setmassage-final\web\server\node_modules\superagent\lib\response-base.js:122:16) at new Response (E:\www\setmassage-final\web\server\node_modules\superagent\lib\node\response.js:40:8) at Request._emitResponse (E:\www\setmassage-final\web\server\node_modules\superagent\lib\node\index.js:738:20) at E:\www\setmassage-final\web\server\node_modules\superagent\lib\node\index.js:883:38 at IncomingMessage. (E:\www\setmassage-final\web\server\node_modules\superagent\lib\node\parsers\json.js:16:7) at emitNone (events.js:91:20) at IncomingMessage.emit (events.js:185:7) at endReadableNT (_stream_readable.js:974:12) at _combinedTickCallback (internal/process/next_tick.js:80:11) at process._tickCallback (internal/process/next_tick.js:104:9) status: 400, text: '{"code":"missing_parameter","message":"Please provide Email or SMS attribute value to create user"}', method: 'POST', path: '/v3/contacts' }, accepted: false, noContent: false, badRequest: true, unauthorized: false, notAcceptable: false, forbidden: false, notFound: false, type: 'application/json', charset: 'utf-8', links: {}, setEncoding: [Function: bound ], redirects: [] } }

Provenance : Courrier pour Windows 10

De : Ekta Gupta Envoyé le :jeudi, 7 décembre 2017 13:07 À : sendinblue/APIv3-nodejs-library Cc : mazero; Mention Objet :Re: [sendinblue/APIv3-nodejs-library] "Please provide Email or SMSattribute value to create user" (#18)

Hi @mazero Please make sure that req.body is not empty, if it is it will lead you to error Please provide Email or SMS attribute value to create user Hope that helps! Regards SendinBlue Team — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.


L'absence de virus dans ce courrier électronique a été vérifiée par le logiciel antivirus Avast. https://www.avast.com/antivirus

ekta-slit commented 6 years ago

Hi @mazero

Please change your sample to below and request will be good to go.

let apiInstance = new SibApiV3Sdk.ContactsApi();
let createContact = new SibApiV3Sdk.CreateContact(); // CreateContact | Values to create a client sendinblue

createContact = {
  listIds: [ '2' ],
  email: "testor@sendinblue.com",
  updateEnabled: true,
  attributes: {
    FIRST_NAME: "aaa",
    LAST_NAME: "aaa",
    EMAIL: "testor@testor.ch",
    SMS: "0645535435"
  }
}

apiInstance.createContact(createContact).then((data) => {
  console.log('API called successfully. Returned data: ' + data);
}, (error) => {
  console.error(error);
});

Thanks

cdelalama commented 6 years ago

listIds: [ '2' ] should be listIds: [ 2 ]

bvanhou commented 4 years ago

This should be included in the example, very helpful