Reputation: 93
I am using NodeJS SDK of watson to test Personality Insights Service but getting the following error:
> Error: { Bad Request: Invalid JSON input at line 1, column 2
> at RequestWrapper.formatError (C:\Users\...\Desktop\..\..\ibm-analyser-cloud\node_modules\ibm-cloud-sdk-core\lib\request-wrapper.js:208:21)
> at C:\Users\...\Desktop\..\..\ibm-analyser-cloud\node_modules\ibm-cloud-sdk-core\lib\request-wrapper.js:196:25
> at process._tickCallback (internal/process/next_tick.js:109:7) name: 'Bad Request', code: 400, message: 'Invalid JSON input at
> line 1, column 2', body:
> '{"code":400,"sub_code":"S00005","error":"Invalid JSON input at line
> 1, column 2"}', headers: { 'content-type': 'application/json',
> 'content-length': '81',
> 'access-control-allow-origin': '*',
> 'x-service-api-version': '4.0.2',
> 'x-service-build-number': '2020-01-20T06:02:53.029 UTC',
> 'x-content-type-options': 'nosniff',
> 'x-xss-protection': '1; mode=block',
> 'content-security-policy': 'default-src \'none\'',
> pragma: 'no-cache',
> 'cache-control': 'no-store',
> 'x-service-pi-error-code': 'S00005',
> 'content-language': 'en-US',
> 'strict-transport-security': 'max-age=31536000; includeSubDomains;',
> 'x-global-transaction-id': '833a39d917c511e8921aa5286669721c',
> 'x-dp-watson-tran-id': '833a39d917c511e8921aa5286669721c',
> 'x-edgeconnect-midmile-rtt': '289',
> 'x-edgeconnect-origin-mex-latency': '416',
> date: 'Tue, 28 Jan 2020 02:59:53 GMT',
> connection: 'close' } }
Below is the code snippet I am using :
app.get("/personality-insights", function(req, res) { const personalityInsights = new PersonalityInsightsV3({ version: '2017-10-13', authenticator: new IamAuthenticator({ apikey: watsonKeyPersonalityInsights, }), url: watsonUrlPersonalityInsights, }); let params = { content: "I am very happy today", content_type: 'text/plain', raw_scores: true, consumption_preferences: true }; personalityInsights.profile(params, function(error, response) { if (error) console.log('Error:', error); else console.log(JSON.stringify(response, null, 2)); } ); });
this is a sample Node JS based snippet where I am providing the API credentials and the URL provided by the IBM cloud and making the request with a single line of input text. Everything seems correct but don't know why I am getting that error.
Upvotes: 2
Views: 205
Reputation: 597
All the parameters were converted to lower camel case in v5. See the MIGRATION doc in the repo and the parameter details in the API reference
contentType
rawScores
consumptionPreferences
Upvotes: 3