Change BaseURL in OnBeforeRequestAdvanced
Question
Application Type
Reactive

Hi All-

I'm currently trying to make a REST call to various internal services.  These services are all secured via NTLM, so I'm having to use OnBeforeRequestAdvanced to get my credentials into the web request.  This seems to be working fine.

However, I also need to call various endpoints, based on some data.  For example, clicking on row 1 will call https://server1/api/example.  But Clicking on row 2 will call https://server2/api/example.

I've tried throwing the following code in the OnBeforeRequestAdvanced method I'm calling:

RestRequest context = RestRequest.GetCurrent();
var headers = context.GetRequestHeaders();
var baseUrl = headers["X-REST-BaseUrl"];
var newUrl = Regex.Replace(context.GetRequestURL(), @"^.+?[^\/:](?=[?\/]|$)", baseUrl);
GenericExtendedActions.LogMessage(AppInfo.GetAppInfo().OsContext, "Replacing Original URL: " + context.GetRequestURL() + "\nWith URL: " + newUrl, "UpdateBaseUrlFromHeader");
context.SetRequestURL(newUrl);

I see the log doing the replacement fine...but in the integrations tab (logging in ServiceCenter), it's calling the API with the original URL.

Any help is greatly appreciated.  
Thanks!

--John

Sorry for trying all possible solutions :D But this link that I found and I already in the past tried to do this can it help you?

Can it change the endpoint?

https://www.outsystems.com/forums/discussion/40371/how-to-covert-rest-api-base-url-to-site-property/

Hi John,

Any particular reason for doing the replacement inside an extension?

Within the OnBeforeRequest you can also perform the same replacement logic:

IG

Hi Ivo-

Thanks for the reply.  Yes, I've used the OnBeforeRequest to do this several times.  However, I'm having to use NTLM for authentication, which is forcing me into the OnBeforeRequestAdvanced route.


Hello, @John there are already discussions about this topic, and there were a lot of answers saying that right now is not possible. But there is a workaround https://www.outsystems.com/forums/discussion/53738/input-parameter-for-onbeforereqeustadvanced-soap/#Post221446

Let me know if this what you are looking for! :)

Regards,

Márcio C.

Thanks for the reply.  I have seen that post, and I've even seen an official OutSystems post showing how to customize the endpoint via Integration for SOAP.  Unfortunately, the API's are completely different for REST, and they don't seem to have an equivalent method.

Sorry for trying all possible solutions :D But this link that I found and I already in the past tried to do this can it help you?

Can it change the endpoint?

https://www.outsystems.com/forums/discussion/40371/how-to-covert-rest-api-base-url-to-site-property/

No need to apologize, the more solutions the better!

Going down the rabbit hole on that thread I see an OutSystems staff member stating this:

"OnBeforeRequestAdvanced since the C#/Java correspondent Request objects are already created at that point and the url is readonly in them."

So...it would seem that the platform doesn't support what I need to do.

Back to the drawing board.

Thanks!

It's ok!! That's why that was a lot of answers saying that right now is not possible. Maybe this could be something to be worked on!

Regards,

Márcio C.

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.