Cloud Development Kit

Required String parameter 'applicationKey' is not present

I'm trying to use CDK according to API(http://doc.myscript.com/MyScriptCloud/3.0.0/reference/index.html#api-Resource-deleteGlobalResource), with javascript send request to cloud:


var request=require('request');
var options = {
url : https://cloud.myscript.com/api/v3.0/recognition/rest/text/doSimpleRecognition.json,
method: POST,
json: true,
body: {applicationKey:!!!!MyKeyHere!!!!,
textInput: {textParameter:{textInputMode:CURSIVE,resultDetail:CHARACTER,language:en_US,contentTypes:[text]}, inputUnits:[{textInputType:MULTI_LINE_TEXT,components:[{type:stroke,x:[438,439,439], y:[319.5,313.5,312.5]}]}]}}
}

function callback(error, response, body) {
console.log(body);
}
request(options, callback);

It works fine in Chrome Postman, but I got Required String parameter 'applicationKey' is not present from nodeJs.


Thanks for your message.
In oder to troubleshoot, here is an example of json file that may help you.

Requirement: node js installation

1. Create a file 'simple.js' in a 'test' folder:

var request=require('request');
var textInput = {
'textParameter':
{'textInputMode':'CURSIVE',
'resultDetail':'CHARACTER',
'language':'en_US',
'contentTypes':['text']
},
'inputUnits':[
{'textInputType':'MULTI_LINE_TEXT',
'components':[
{'type':'stroke','x':[438,439,439], 'y':[319.5,313.5,312.5]}
]
}
]
};
var payload = {
applicationKey : "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
textInput : JSON.stringify(textInput)
};
console.log("Payload build " + JSON.stringify(payload));

function callback(error, response, body) {
console.log(body);
}
console.log("Posting to myscript cloud");
request.post('https://cloud.myscript.com/api/v3.0/recognition/rest/text/doSimpleRecognition.json', { form : payload},callback)


2 Create a file package.json in the same folder

{
"name": "very_simple_node",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo "Error: no test specified" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"request": "^2.72.0"
}
}


3. In your 'test' folder, execute the following command lines:
- npm install
- node 'simple.js'

You should see your request and the result.

Please let us know if it helps.

Thanks it works!

But when I tried to add my resources by the methods you said in other posts, I got results like following:

{result:{message:Unrecognized field userResources (class com.myscript.backend.recognition.json.api.text.simple.SimpleTextInputUnitWsBean), not marked as ignorable (3 known properties: components, textInputType, boundingBox])n at [Source: java.io.ByteArrayInputStream@65fb79fe; line: 1, column: 257] (through reference chain: com.myscript.backend.recognition.json.api.text.simple.SimpleInputTextWsBean[inputUnits]->com.myscript.backend.recognition.json.api.text.simple.SimpleTextInputUnitWsBean[userResources]),error:ApiJsonParsingException,status:error,colNumber:257,lineNumber:1}}

Here is how I revised your code:

var textInput = {
'textParameter':
{'textInputMode':'CURSIVE',
'resultDetail':'CHARACTER',
'language':'en_US',
'contentTypes':['text']
},
'inputUnits':[
{'textInputType':'MULTI_LINE_TEXT',
'components':[
{'type':'stroke','x':[438,439,439], 'y':[319.5,313.5,312.5],},
],
userResources:[test1,test2]
}
]
};

I already added the resources to my account.

Thanks for your feedback.
The custom resource parameter must be added in the 'textParameter' list:

 'textParameter':
{'textInputMode':'CURSIVE',
'resultDetail':'CHARACTER',
'language':'en_US',
'contentTypes':['text'],
 'userResources':['test1']
},


Best regards

Login or Signup to post a comment