1

Using NODE, I'm using the request module to GET request to a site I've already auth'd to. They passed me a sessionID so I can make REST calls and interact with the data.

I'm struggling to make GET request and pass the cookies correctly. I continue to get a STATUS: 500 even though I know the site works correctly. Its somewhere in how I'm passing the cookie I think.

MY CODE


var sessionID = "49CD32C2BD250FF3C5078FB977936350";
var request = require('request');

param = {
    "header": {
        "Accept": "application/json"
    ,   "Cookie": "customer=CHEESEHEAD;JSESSIONID="+ sessionID
    }
}

request.get('https://cheesehead.autodeskplm360.net/api/rest/v1/workspaces', {form: param}, function(err, response){

    if(err){
       console.log(err);
    } else if (response.statusCode == 500) {

    console.log('Response Status Code: ' + response.statusCode + ' Internal Error')     
    } else {
    console.log('Status Code: ' + response.statusCode)

    console.log(response.body)
  }
});

1 Answer 1

1

You are passing the headers as form parameter to request call. You should pass all object as a request parameters.

var sessionID = "49CD32C2BD250FF3C5078FB977936350";
var request = require('request');

options = {
    "method":"GET",
    "url": "'https://cheesehead.autodeskplm360.net/api/rest/v1/workspaces'",
    "headers": {
        "Accept": "application/json"
    ,   "Cookie": "customer=CHEESEHEAD;JSESSIONID="+ sessionID
    }
}

request(options, function(err, response){

    if(err){
       console.log(err);
    } else if (response.statusCode == 500) {

    console.log('Response Status Code: ' + response.statusCode + ' Internal Error')     
    } else {
    console.log('Status Code: ' + response.statusCode)

    console.log(response.body)
  }
});
Sign up to request clarification or add additional context in comments.

Comments

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.