{
"url": "",
"uaa": {
"uaadomain": "",
"tenantmode": "",
"sburl": "",
"clientid": "",
"verificationkey": "",
"apiurl": "",
"xsappname": "",
"identityzone": "",
"identityzoneid": "",
"clientsecret": "",
"tenantid": "",
"url": ""
}
}

Don't forget to replace uaa.clientid and uaa.clientsecret with the values from the Service Key you created before.
Don't forget to replace uaa.url with the values from the Service Key.
Replace the url value with the one from the Service Key. The last part was inserted as requested by the documentation.



You should have the workflow below :
// ----------------------------------------------------------------
// Step: Generate_token
// ----------------------------------------------------------------
GLOBAL.step({ Generate_token: function(ev, sc, st) {
var rootData = sc.data;
ctx.workflow('ExtractDataFromPDF', '7e436b4c-226a-4a50-93c3-4948023e62db') ;
// Generate token
ctx.ajax.call({
url: rootData.WS.Input.ServiceKey.tokenURL + '/oauth/token?grant_type=client_credentials',
method: e.ajax.method.get,
contentType: e.ajax.content.json,
header:{
Accept: e.ajax.content.json,
Authorization: rootData.WS.Input.ServiceKey.client
},
success: function(res, status, xhr) {
sc.localData.token = 'Bearer ' + ctx.get(res, 'access_token');
sc.endStep(); // Upload_file
return;
},
error: function(xhr, error, statusText) {
ctx.log(' ctx.ajax.call error: ' + statusText);
}
});
}});// ----------------------------------------------------------------
// Step: Upload_file
// ----------------------------------------------------------------
GLOBAL.step({ Upload_file: function(ev, sc, st) {
var rootData = sc.data;
ctx.workflow('ExtractDataFromPDF', '0a1f4176-8907-4544-a807-65095d30ea36') ;
// Upload file
ctx.ajax.call({
url: rootData.WS.Input.ServiceKey.doxURL + '/document/jobs',
method: e.ajax.method.post,
formData: [{
file:rootData.WS.Input.filePath,
type:e.ajax.content.pdf,
name:'file'
},{
value:ctx.json.stringify({"extraction":{"headerFields":["documentNumber","taxId","taxName","purchaseOrderNumber","shippingAmount","netAmount","senderAddress","senderName","grossAmount","currencyCode","receiverContact","documentDate","taxAmount","taxRate","receiverName","receiverAddress"],"lineItemFields":["description","netAmount","quantity","unitPrice","materialNumber"]},"clientId":"c_00","documentType":"invoice","enrichment":{"sender":{"top":5,"type":"businessEntity","subtype":"supplier"},"employee":{"type":"employee"}}}),
type:e.ajax.content.jsonText,
name:'options'
}],
header:{
Accept:e.ajax.content.json,
Authorization: sc.localData.token
},
contentType: e.ajax.content.json,
success: function(res, status, xhr) {
rootData.WS.Output.docId = ctx.get(res, 'id');
sc.endStep(); // Retrieve_extracted_da
return;
},
error: function(xhr, error, statusText) {
ctx.log(' ctx.ajax.call error: ' + statusText);
}
});
}});// ----------------------------------------------------------------
// Scenario: ExtractDataFromPDF
// ----------------------------------------------------------------
GLOBAL.scenario({ ExtractDataFromPDF: function(ev, sc) {
var rootData = sc.data;
sc.setMode(e.scenario.mode.clearIfRunning);
sc.setScenarioTimeout(600000); // Default timeout for global scenario.
sc.onError(function(sc, st, ex) { sc.endScenario(); }); // Default error handler.
sc.onTimeout(30000, function(sc, st) { sc.endScenario(); }); // Default timeout handler for each step.
sc.step(GLOBAL.steps.Set_credentials, GLOBAL.steps.Set_tokenURL);
sc.step(GLOBAL.steps.Set_tokenURL, GLOBAL.steps.Set_doxURL);
sc.step(GLOBAL.steps.Set_doxURL, GLOBAL.steps.Set_file_path);
sc.step(GLOBAL.steps.Set_file_path, GLOBAL.steps.Generate_token);
sc.step(GLOBAL.steps.Generate_token, GLOBAL.steps.Upload_file);
sc.step(GLOBAL.steps.Upload_file, GLOBAL.steps.Retrieve_extracted_da);
sc.step(GLOBAL.steps.Retrieve_extracted_da, GLOBAL.steps.Retrieve_extracted_da, 'loop');
sc.step(GLOBAL.steps.Retrieve_extracted_da, null);
}}, ctx.dataManagers.rootData).setId('57146a42-30d7-47af-8aad-9844f008f7d8') ;// ----------------------------------------------------------------
// Step: Retrieve_extracted_da
// ----------------------------------------------------------------
GLOBAL.step({ Retrieve_extracted_da: function(ev, sc, st) {
var rootData = sc.data;
ctx.workflow('ExtractDataFromPDF', '6ae7f1e0-85e1-410d-9ce6-f9509d1d5242') ;
// Retrieve extracted data
ctx.ajax.call({
url: rootData.WS.Input.ServiceKey.doxURL + '/document/jobs/' + rootData.WS.Output.docId + '?clientId=c_00×tamp=' + new Date().getTime(),
method: e.ajax.method.get,
header:{
Accept:e.ajax.content.json,
Authorization: sc.localData.token
},
contentType: e.ajax.content.json,
success: function(res, status, xhr) {
if (res.status == 'DONE'){
rootData.WS.Output.data = res;
sc.endStep(); // end Scenario
return;
} else if (res.status == 'PENDING') {
ctx.wait(function(){
sc.endStep('loop');
},5000);
}
},
error: function(xhr, error, statusText) {
ctx.log(' ctx.ajax.call error: ' + statusText);
}
});
}});And you can even download the sample directly from the Store in the Factory !
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 4246 | |
| 3359 | |
| 2603 | |
| 2153 | |
| 1983 | |
| 1255 | |
| 1164 | |
| 1122 | |
| 1100 |