Hi all
I got a situation where the URL is changing from time to time. It contains parameters related to a specific comsumption.
The BaseURL is not changing : https://api.broadsign.com:XXXXXX
The URLPath will change (in read): /rest/schedule/v8/by_reservable?domain_id=YYYYYYY&id=ZZZZZZZ
I called the OnBeforeRequest action to change before the execution.
Now my problem are :
1) Shall I change it in the request or CustomizedRequest ?
2) I tried to have a global variable set in Client Variables and to assign it, but I can't find the "Client Variable" in the resource list to assign to:
Hi Steven,
As only Id which will change so you can use it as input parameter to your API method.
Please check attached oml which I am using one of public currency conversion API and send base currency and convert to currency as parameters. I hope this will be similar to what you are trying to implement and helps you.
To add up on Mostafa answer, let me state the following:
- When you consume a REST API, you can specify URL variables, like {environment}, {domain}, etc. that will be replaced at "call time" with the corresponding input values. Once you define these variables as such, OutSystems will create the required number of input parameters (so, again, OutSystems can replace the variables with the passed values at runtime).
- It seems to me that what you're looking for is a bit different. Meaning, it's still a variable, but it doesn't serve the purpose that {variables} in REST URL's have. It's more of a setting than an actual variable.
- I suggest one of two approaches:
1, preferred) Define the REST URL with the variables as OS intended (in your case {domain_id}) and then encapsulate the call to the REST method. This encapsulation will only take the inputs that should behave as, well, variables and inside said encapsulation do the necessary logic to fill out the settings. Something like:
client.callMethod(id) and your callMethod action would have callREST(domain, id). I know this is a bit of high code, but should help.
2, possible) Use the OnBeforeRequest to modify the request URL, but you need to make sure the settings part of the URL are known at the server level (so you can actually get them). You can't use a Client variable for that, since the name says it all: it's a client variable, not a server variable. If the CampaignId is set at the client level (which seems like something that could totally come from the server), you'll need to pass that as well.
Let me know if this helps.
Hello Steven,
I am not sure if I understand what you are trying to implement correctly.
But you can add two parameters domain_id and Id as input parameters to your consumed API and when you use API method just assign values of two input parameters to values you want to use same as you are using server or client actions which have parameters.
Hi Mostafa,
Thanks for your prompt reply.
I do not need to have to parameters, my domain is not going to change but ID is changing each time.
So I need one variable to hold the input from the user, so that I can append this variable along with the URL before the request.
Hi @Steven Tung
You need to make API query parameter dynamic
You can use url like this.
rest/schedule/v8/by_reservable?domain_id={YYYYYYY}&id={ZZZZZZZ}
It will make domain_id and id dynamic.
Thanks
Arun
Hi Mostafa
Great thanks for your sample, it was beautifully set. I can find all my problem in dealing with the dynamic URL.
I do need to use OnBeforeRequest action to complicate the thing. I simply need to have an input parameter for GetReaservableID method will do, then define this variable type into URL.
In the base URAL, I have this variable encapsulated with curly bracket. Whenever I call the API function with input parameter, the system will retrieve data accordingly.
For all fixed parameter such as Bearer Token, I can store it in the Site Properties.
I would like to thank Armando and Arun messages as well. You guys are genius.
In my Scenario, I am having Two API for consumption with same attribute, and I want to Consume that both API in the same response.
I am accepting Path URL from the screen.
Issue: One Data is Append Successfully but Another API data is not