For partners that build or integrate commercially available applications and service solutions with the Oracle Cloud Platform
For partners that provide implementation or managed services around Oracle Cloud Applications
I have a REST URL(ISG) that has header parameters.How can I create a REST connector using that REST URL in oracle MCS.
The REST URL is POST method and have 5 header parameters.
please clarify me below
1)where I have to attach the headers of rest URL (in rules or during testing endpoint)
2)If in testing endpoint means I have to add headers in my custom api using Node js?
Now,I have added headers in Rules,while Testing endpoint it says authentication error so I added headers there also. Now I get 415 error code.
Comment
Have you read the documentation? https://docs.oracle.com/en/cloud/paas/mobile-cloud/mcsua/rest-connector-apis.html#GUID-12D976D7-5FCA-49C1-8D85-44A9BC438…
Have you watched the videos? https://www.youtube.com/watch?v=AzRYJ_wQduY&list=PL2ux0DjE-RYf7Rzh05Y98QWroTb76yyov
If yes can you be more specific on your question on what you don't understand please.
CM.
Average Rating:



1 rating
|
Sign in to rate this
Janaki, is your question about REST Connectors in general in MCS, or specifically about adding HTTP headers to a REST Connector call via MCS?
If the later, there are 2 ways to do this:
a) For static non changing HTTP headers use the REST HTTP Header "Rules" feature:
https://docs.oracle.com/en/cloud/paas/mobile-cloud/mcsua/rest-connector-apis.html#GUID-21EBB7F1-CDD3-4812-925A-607B76A84…
b) If the HTTP headers are dynamic, instead in your NodeJS code when you call the REST connector:
service.get('/mobile/custom/incidentreport/weather/:city',
function (req, res) {
var body = {
Header: {
myHeader1:"myValue1",
myHeader2:"myValue2"
},
Body: {
GetWeather: {
CityName: req.params.city,
CountryName: 'Spain'
}
}
};
req.oracleMobile.connectors.post('globalweather', 'GetWeather', body).then(
function (result) {
console.info("result is: " + result.statusCode);
res.send(result.statusCode, result.result);
},
function (error) {
console.info("error is: " + error.statusCode);
res.send(500, error.error);
}
);
});
CM.
Average Rating:



1 rating
|
Sign in to rate this
I have gone through the documentation and video in youtube ,but i didnt get a clear idea about the REST Connectors that created with Rest URL with headers.
I also tried the REST API (google api) provided in oracle and it is working fine.Few sample API like weather api is also working fine.
I have elaborated my question.Please check it out.
Thanks& Regards,
-Janaki
Average Rating:



1 rating
|
Sign in to rate this
See: Calling MCS APIs from Custom Code
Note:
You might notice that you don’t need to worry about authentication when you send requests to MCS APIs from custom code. MCS re-uses the access token that’s passed into the custom code and takes care of authentication for you. With connectors, if you need to use different credentials for the external service, you can use
options.externalAuthorization
to pass the value to be used in the
Authorization
header for the external service.
Average Rating:



1 rating
|
Sign in to rate this
Hi Chris,
I have rest URL with authorization as one of the header parameter.When I Test the Rest Connector I am able to add the authorization as a header parameter and test it successfully.But when I test the custom API created using that connector I am getting below error.
I will also attach my Node Js code
/**
* The ExpressJS namespace.
* @external ExpressApplicationObject
* @see {@link http://expressjs.com/3x/api.html#app}
*/
/**
* Mobile Cloud custom code service entry point.
* @param {external:ExpressApplicationObject}
* service
*/
module.exports = function(service) {
/**
* The file samples.txt in the archive that this file was packaged with contains some example code.
*/
service.get('/mobile/custom/Login_Rest/login', function(req,res) {
var body = {
Header: {
"content-type": req.header.content-type,
"authorization": req.header.authorization,
"Responsibility": req.header.Responsibility,
"RespApplication": req.header.RespApplication,
"SecurityGroup": req.header.SecurityGroup,
"NLSLanguage": req.header.NLSLanguage,
"Org_Id": req.header.Org_Id
},
Body: {
username: req.params.username,
password:req.params.password
}
};
req.oracleMobile.connectors.post('TestRestAPI', '', body).then(
function (result) {
console.info("result is: " + result.statusCode);
res.send(result.statusCode, result.result);
},
function (error) {
console.info("error is: " + error.statusCode);
res.send(500, error.error);
}
);
});
};
Please clarify me below
How to pass authorization header paramter?
whether there is any error with the custom code ?
Average Rating:



1 rating
|
Sign in to rate this
Thanks for your response Tware
Still I didn't create a custom API using REST connectors successfully.
Can you please verify the steps I follow.
Entered API name and created resources with GET method.I have given two input parameters as query and Headers parameters as headers.
My Custom code is
/**
* The ExpressJS namespace.
* @external ExpressApplicationObject
* @see {@link http://expressjs.com/3x/api.html#app}
*/
/**
* Mobile Cloud custom code service entry point.
* @param {external:ExpressApplicationObject}
* service
*/
module.exports = function(service) {
/**
* The file samples.txt in the archive that this file was packaged with contains some example code.
*/
service.get('/mobile/custom/MobileLogin_Rest/userLogin', function(req,res) {
var body = {
Header: {
"Content-type": req.header.content-type,
"authorization": req.header.authorization,
"Responsibility": req.header.Responsibility,
"RespApplication": req.header.RespApplication,
"SecurityGroup": req.header.SecurityGroup,
"NLSLanguage": req.header.NLSLanguage,
"Org_Id": req.header.Org_Id
},
Body: {
P_USRNAME: req.params.P_USRNAME,
P_PASSWORD: req.params.P_PASSWORD
}
};
req.oracleMobile.connectors.post('TestRestAPI', '', body).then(
function (result) {
console.info("result is: " + result.statusCode);
res.send(result.statusCode, result.result);
},
function (error) {
console.info("error is: " + error.statusCode);
res.send(500, error.error);
}
);
});
};
And also clarify me .
Whether I have to change the authorization to options.externalAuthorization in Headers parameters?
Average Rating:



1 rating
|
Sign in to rate this
Your code should look roughly like this:
service.get('/mobile/custom/MobileLogin_Rest/userLogin', function(req,res) {
var headers = {
"Content-type": req.header.content-type,
"Responsibility": req.header.Responsibility,
"RespApplication": req.header.RespApplication,
"SecurityGroup": req.header.SecurityGroup,
"NLSLanguage": req.header.NLSLanguage,
"Org_Id": req.header.Org_Id
};
var body = {
P_USRNAME: req.params.P_USRNAME,
P_PASSWORD: req.params.P_PASSWORD
};
req.oracleMobile.connectors.post('TestRestAPI', '', body, {inType: 'json', externalAuthorization: <authorization for your external service here if needed> }, {headers: headers}).then(
function (result) {
console.info("result is: " + result.statusCode);
res.send(result.statusCode, result.result);
},
function (error) {
console.info("error is: " + error.statusCode);
res.send(500, error.error);
}
);
});
};
Average Rating:



1 rating
|
Sign in to rate this
Hi Tware,
Now getting below error
Thanks,
Average Rating:



1 rating
|
Sign in to rate this
Take a look at your logs. There should be a log message with a stack trace. That will be useful in tracking this down.
If you don't see that message, please share your identity domain name.
Average Rating:



1 rating
|
Sign in to rate this
I found that error in log in that log.Identity Domain is gse00010158.
Average Rating:



1 rating
|
Sign in to rate this
What is the error? Please include the stack trace.
Average Rating:



1 rating
|
Sign in to rate this
Hi Tware,
Below is the stack trace .Please help me.
Message Text
Custom Code Problem: request: get /mobile/custom/TransRestApi/Username caused unhandled error: ReferenceError: type is not defined at /mobile/mobile_ccc/custom_code_modules/transrestapi_1.0.0_7/transrestapi/transrestapi.js:25:36 at callbacks (/mobile/mobile_ccc/mcs-node-router/node_modules/express/lib/router/index.js:164:37) at param (/mobile/mobile_ccc/mcs-node-router/node_modules/express/lib/router/index.js:138:11) at pass (/mobile/mobile_ccc/mcs-node-router/node_modules/express/lib/router/index.js:145:5) at Router._dispatch (/mobile/mobile_ccc/mcs-node-router/node_modules/express/lib/router/index.js:173:5) at Object.router (/mobile/mobile_ccc/mcs-node-router/node_modules/express/lib/router/index.js:33:10) at next (/mobile/mobile_ccc/mcs-node-router/node_modules/express/node_modules/connect/lib/proto.js:193:15) at Object.mcsSdk (/mobile/mobile_ccc/mcs-node-router/mcs-node-server-new.js:867:9) at next (/mobile/mobile_ccc/mcs-node-router/node_modules/express/node_modules/connect/lib/proto.js:193:15) at Object.methodOverride [as handle] (/mobile/mobile_ccc/mcs-node-router/node_modules/method-override/index.js:63:14) at next (/mobile/mobile_ccc/mcs-node-router/node_modules/express/node_modules/connect/lib/proto.js:193:15) at Object.urlencoded [as handle] (/mobile/mobile_ccc/mcs-node-router/node_modules/express/node_modules/connect/lib/middleware/urlencoded.js:40:37) at next (/mobile/mobile_ccc/mcs-node-router/node_modules/express/node_modules/connect/lib/proto.js:193:15) at next (/mobile/mobile_ccc/mcs-node-router/node_modules/express/node_modules/connect/lib/proto.js:195:9) at Object.json [as handle] (/mobile/mobile_ccc/mcs-node-router/node_modules/express/node_modules/connect/lib/middleware/json.js:42:37) at next (/mobile/mobile_ccc/mcs-node-router/node_modules/express/node_modules/connect/lib/proto.js:193:15)
Be the first to rate this
|
Sign in to rate this
The top line of the stack trace tells you where the problem is:
type is not defined at /mobile/mobile_ccc/custom_code_modules/transrestapi_1.0.0_7/transrestapi/transrestapi.js:25:36
Look on line 25 of transrestapi.js. Do you see "type" there. It need to be defined before you can use it.
Average Rating:



1 rating
|
Sign in to rate this
I am facing similar issue with connector calling, tried two approaches, no success
Tried two approached, failed in both
1.
2.
Be the first to rate this
|
Sign in to rate this