NOW Experience - Proxy HTTP Calls

royjustus
Tera Contributor

I've been trying to get the HTTP request proxy to work and so far it's working perfectly in the instance once deployed but I suspect there's something wrong with my proxy configuration because it's not authenticating when I run "now-cli develop". 

now-cli.json is:

 

{

  "development": {
    "proxy": {
      "origin": "https://dev100***service-now.com",
      "headers": {
        "Authorization": "Basic SGFoYSB5b3UgdGhpbmsgdGhpcyB3b3VsZCBiZSBteSByZWFsIHBhc3N3b3J"
      },
      "proxies": ["*"]
    },
}​
 
 
modified
 
and my code (which works in-instance) is:
 
 
const fetchUserEffect = createHttpEffect('/api/now/table/sys_user?sysparm_limit=1', {
    method: 'GET',
    successActionType: USER_FETCH_SUCCESS,
    errorActionType: USER_FETCH_ERROR
});
 ​
 
 What am I missing here? I've tried with and without batching and verified the username and password.
 
Console shows 401 error, packet inspection in fiddler confirms the Auth header is missing. If I add Authorization directly in the index.js then fiddler shows it in the outbound request but the instance gives the same response.
 
Any ideas?
1 ACCEPTED SOLUTION

Roen
Kilo Expert

Hey royjustus!

I just successfully did a GET call from my now-cli project after hours and hours of pain.

What I have come to realize is that now-cli completely ignores the now-cli.json file and anything you do in it except if you change your port, then it gets confused.

What I did to solve the problem. Is that I had to add my instance to the api request, AS WELL AS adding cors anywhere from heroku to get around cors errors.

I ALSO directly added my authorization into the header in the request, as again, the now-cli ignores the .json file. Atleast when in develop mode.

const fetchUserEffect = createHttpEffect(
	"https://cors-anywhere.herokuapp.com/https://dev11111.service-now.com/api/now/table/sys_user?sysparm_limit=10",
	{
		method: "GET",
		successActionType: "USER_FETCH_SUCCESS",
		errorActionType: "USER_FETCH_ERROR",
		batch: false,
		headers: {
			Authorization: "Basic bmljZXVzZXJuYW1laGVyZ3dvcmRoZXJl=",
		},
	}
);

This went straight through and was accepted.

 

instance id and auth key has been changed.

 

 

 

View solution in original post

14 REPLIES 14

Michael Grondin
Kilo Expert

I have almost the same problem. For me httpEffect does not work at all either locally or deployed. The actions are never dispatched and there no http request sent. Apparently there is something wrong with the ui-http-effect package since we are not the only ones with issues..

For now I replaced it with the other example that uses the fetch function and that works fine! Although I could not make it work locally since the fetch method uses a relative url which is sent on the same host/port and when running locally the proxy does not work with the same port (I think you saw my question here).

royjustus
Tera Contributor

Yeah so for my the actions do get dispatched (key is to put the dispatch call in the view) minimal code is: 

const USER_FETCH_SUCCESS = 'USER_FETCH_SUCCESS'
const USER_FETCH_ERROR = 'USER_FETCH_ERROR'

const view = (state, {updateState, dispatch}) => {
	console.log("Trying");
	dispatch("USER_FETCH_REQUESTED");
	console.log("Tried");
	return (<div>holder</div>);

};

const fetchUserEffect = createHttpEffect('/api/now/table/sys_user?sysparm_limit=1', {
	method: 'GET',
	successActionType: USER_FETCH_SUCCESS,
	errorActionType: USER_FETCH_ERROR,
	batch: false
});

createCustomElement('x-8011-card', {
	renderer: {type: snabbdom},
	view,
	styles,
    actionHandlers: {
        'USER_FETCH_REQUESTED': fetchUserEffect,
        [USER_FETCH_SUCCESS]: ({action, updateState}) => {console.log("USER_FETCH_SUCCESS");},
        [USER_FETCH_ERROR]: ({action, updateState}) => {console.log("USER_FETCH_ERROR");}

	}
	
});

Interestingly the proxy config I specified seems to just work, the 401 response I'm getting comes from the ServiceNow Server so it's figuring that part out. Really the only major remaining issue for me is that the authorization headers don't get added. (See attachment for headers on the response object)

Regards,

Roy

Did you figure out why your data request was not being properly authenticated?  I'm having the same issue, the request is being sent to the instance but I'm getting a 401 back.

 

royjustus
Tera Contributor

No luck yet. I'm working around it by just repeatedly deploying to my instance instead of developing locally if I need the data connections to work. 

Hopefully someone can shed some light on the situation.