General questions

Rest API - Save data

I wonder if it is possible to save the json data and present the handwritten and recognized output later on?


Dear Daniel,

thank you for contacting us.

Currently, it all depends on your use-case. how are you using the REST API? Are you displaying the result by yourself? If so, you can of course save the result (in text format, mathml/latex for math...) and choose to display it when you prefer. it all depends on how you develop your application.

Best regards,

Olivier

Hi Olivier,

Thank you for your response. I am trying to post to your api but get an error response.
I would like to save a handwritten and recognized output and present this
on the page later on. I am using the myscript-math-web-result event, but I can not figure out
how to catch the analyzerInput data structure described in the api docs. I am trying to make
a post request to your api from my server with my application key and the analyzerInput object
from the example, but I get a html message back saying "The requested page cannot be found".
Could you help me how to solve this? How can I learn more abot your data types, I cannot find
information, latext for example...where do I find information about that?

Regards,
/Dan


var url = 'http://doc.myscript.com/api/v3.0/recognition/rest/analyzer/doSimpleRecognition.json';

var applicationKey = "MY_API_KEY";
var analyzerInput = {
"components":[
{
"type":"stroke",
"x":[
133.66668701171875,
141.66668701171875,
145.66668701171875
],
"y":[
319.5,
299.5,
294.5
]
}
],
"resultTypes":[
"LATEX",
"MATHML",
"SYMBOLTREE"
],
"columnarOperation":false,
"userResources":[
]
};


request.post(url, {applicationKey: applicationKey, analyzerInput: analyzerInput}, function (err, httpResponse, body) {
console.log('response', body);
});

I changed "doc" in the url to "cloud" and now seem to get an answer but with this error,

response {"result":{"message":"Required String parameter 'applicationKey' is not present"}}

Dear Daniel,

indeed, the requests should be posted to the http://cloud.myscript.com rather than the http://doc.myscript.com.

Then, as indicated on the API documentation (http://doc.myscript.com/MyScriptCloud/3.2.0/reference/index.html), you should complete the URL with the corresponding service:

For Analyzer: /api/v3.0/recognition/rest/analyzer/doSimpleRecognition.json
 
Math: /api/v3.0/recognition/rest/math/doSimpleRecognition.json
 
Music: /api/v3.0/recognition/rest/music/doSimpleRecognition.json
 
Shape: /api/v3.0/recognition/rest/shape/clearSessionId.json
 
Text: /api/v3.0/recognition/rest/text/contenttypes.json

Also, in your dashboard, as the hmac key is enabled, you should either add it when posting your request or disable it on your dashboard.

Last, if you want to use the Analyzer service, please note your request is not properly formatted, as the "resultTypes" and "columnarOperation" fields are for Math, and not Analyzer. To format your request with the proper fields, you can refer to the API documentation (http://doc.myscript.com/MyScriptCloud/3.2.0/reference/index.html) or the "Recognition types" part of the MyScript Cloud documentation (http://doc.myscript.com/MyScriptCloud/3.2.0/myscript-cloud/reco-types.html).

Let us know if you have further questions.

Best regards,

Olivier

Here is my new attempt, I get an error, saying:

{"result":{"applicationKey":"my_api_key","error":"InvalidHMACSignatureException","status":"error"}},


- whar am I doning wrong?

- how do I get the content of mathInput object on the client`


var express = require('express');
var cors = require('cors');
var request = require('request');
var qs = require('querystring');
var app = express();

app.use(cors());

app.post('/test', function (req, res) {
var body = '';

req.on('data', function (data) {
body += data;

// Too much POST data, kill the connection!
// 1e6 === 1 * Math.pow(10, 6) === 1 * 1000000 ~~~ 1MB
if (body.length > 1e6)
request.connection.destroy();
});

req.on('end', function () {
var url = 'http://cloud.myscript.com/api/v3.0/recognition/rest/math/doSimpleRecognition.json';

var applicationKey = "my api_key";
var math = {
"components":[
{
"type":"stroke",
"x":[
133.66668701171875,
141.66668701171875,
145.66668701171875
],
"y":[
319.5,
299.5,
294.5
]
}
],
"resultTypes":[
"LATEX",
"MATHML",
"SYMBOLTREE"
],
"columnarOperation":false,
"userResources":[
]
};

request.post(
url, {
form: {
applicationKey: "3558cac3-c879-4c82-99be-6508ff1de25d",
hmac: "76363d1d-27eb-458f-b47a-935851377943",
mathInput: JSON.stringify(math)
}
}, function (err, httpResponse, body) {
console.log('response', body);
}
);
});
});

app.listen(3000, function () {
console.log('Example app listening on port 3000!')
});

I get this error: 

response {"result":{"applicationKey":"my_application_key","error":"InvalidHMACSignatureException","status":"error"}}

It now works without hmac....my question is, how do I fetch this data from user input?

{
"components":[
{
"type":"stroke",
"x":[
133.66668701171875,
141.66668701171875,
145.66668701171875
],
"y":[
319.5,
299.5,
294.5
]
}
],
"resultTypes":[
"LATEX",
"MATHML",
"SYMBOLTREE"
],
"columnarOperation":false,
"userResources":[
]
};
Dear Daniel,

I am not sur to properly understand your question.

Could you post the request on the Cloud? Are you getting the proper result?

Best regards,

Olivier
Login or Signup to post a comment