0

I am trying to do query to find a account using rest services of the target application name hexion. When I am running it is giving Invalid uri error. The url that I tested in postman is like below https://ekaa-dev1.fa.us6.oraclecloud.com/crmRestApi/resources/11.13.18.05/accounts?q=OrganizationName = Hexion

and in postman I am getting response too. But I feel somewhere in my code I am doing some syntax error but not able to find that

//nodejs v4.2.6

console.log("Hello, World!");
var Request = require("request");
var serviceUserName="[email protected]";
var password="Welcome01";
var personalDataURL="https://ekaa-dev1.fa.us6.oraclecloud.com/crmRestApi/resources/11.13.18.05/accounts";
var option1 = {
        uri:  personalDataURL,
        qs: {
            q:{OrganizationName:"Hexion"}
             },
        headers: {
            "Authorization" : auth,
            "Content-Type": 'application/json',
            "Accept":'application/json'
        }

    };

var auth = `Basic ` + new Buffer(serviceUserName+`:`+password).toString(`base64`);

Request.get(option1, { json: true },
     (error, response, body) => {
         console.log(response);
             //console.log(response.url);
         if (error) { return console.log(body,error); }
  console.log(body.url);
  console.log(body.explanation);
     });

I expect it to return response after successful get Please let me know error, I have changed the auth credentials so once you find anything to be corrected let me for the above code, I will try with right credentials and update you

4
  • What is the error content? Commented Jul 25, 2019 at 12:34
  • @Flo Error: Invalid URI "/"] Commented Jul 25, 2019 at 12:36
  • @Flo: do you find anything suspicious on the code that you want me try correcting it out Commented Jul 25, 2019 at 12:44
  • Anyone can help here Commented Jul 26, 2019 at 3:55

1 Answer 1

1

request.get method expects first parameter as url, but you are passing options1 obj, it couldn't find url hence it is giving error "Invalid uri /". You can append query parameter to url OR use querystring npm

var personalDataURL= "https://ekaa-dev1.fa.us6.oraclecloud.com/crmRestApi/resources/11.13.18.05/accounts?q=OrganizationName=Hexion"
    request({
        headers: {
                "Authorization" : auth,
                "Content-Type": 'application/json',
                "Accept":'application/json'
            },
        uri: personalDataURL,
        method: 'GET'
      }, function (err, res, body) {
        //it works!
      });

For more details, refer request

Sign up to request clarification or add additional context in comments.

3 Comments

it is throwing error as below Hello, World! internal/modules/cjs/loader.js:573 throw err; ^ Error: Cannot find module 'request' at Function.Module._resolveFilename (internal/modules/cjs/loader.js:571:15) at Function.Module._load (internal/modules/cjs/loader.js:497:25) at Module.require (internal/modules/cjs/loader.js:626:17) at require (internal/modules/cjs/helpers.js:20:18) at Object.<anonymous> (/home/jdoodle.js:4:15)
at Module._compile (internal/modules/cjs/loader.js:678:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:689:10) at Module.load (internal/modules/cjs/loader.js:589:32) at tryModuleLoad (internal/modules/cjs/loader.js:528:12) at Function.Module._load (internal/modules/cjs/loader.js:520:3) Command exited with non-zero status 1
You need to install request npm by executing "npm i request --save" command

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.