Variable (or dynamic value) in API URL

Hey everybody

I am querying an API via App Connect for some stock news and the symbol is apart of the URL, and not a traditional query parameter (e.g: ?symbol=aapl). I want the symbol to be based off of an input field so I can filter a Data View later on. Is this possible with App Connect API Source or do I have to do this using the Server Connect Add API Action?

The highlighted portion of the URL needs to be dynamic based on the input field. Does anyone have an idea on how this might be accomplished? If it isn’t possible via App Connect, some tips on doing it with Server Connect would also be great!

image

:sunglasses:

Just use the javascript expression syntax
so something like:

'stockssite.com/1.0/stock/' + symbol + '/news/'

Btw you are catching up pretty fast on Wappler, Mason :slight_smile: - good job! I wish all new users were so thoughtful on reading the docs :slight_smile:

2 Likes

@George thank you, sir! You guys have done a wonderful job on Wappler and I am trying to get a handle on it as quickly as possible. I'm having a lot of fun and finding it to be powerful and intuitive. I hope to be able to contribute support to the community in the future to help new users get comfortable, just as you all are doing for me.

Thanks @George

For symbol I created a variable named symbol and gave it the value of my input field:

image

Then I used the notation you suggested in the API Url:

'https://api.iextrading.com/1.0/' + symbol + '/news/'

image

However I am getting a connection error and it seems it doesn't like my syntax:

Hello @fatherofinvention
If your variable name symbol_search you must use it like symbol_search.value

Dont forget url must be dynamic so it will be like a dmx-bind:url=“yoururlhere” (if your api form client side)

Edit: Maybe I should re-iterate that I am using the App Connect API Data Source for this and not the Server Connect API Action. At this point I am wondering if the advice being given to me is to be applied to the Server Connect side rather the App Connect.

Hey @s.alpaslan !

Thanks for the suggestion. I tried that as well and cannot get the API Url field to resolve variables. It interprets everything I enter as a literal.

I tried creating a variable with my URL and I can see from inserting into a paragraph that it looks good:
image

Here it is inserted into a paragraph as dynamic text:
image

But when I try to use it in the API Url field, I get this error:
image

image

At this point I’m not sure if the API Url field is capable of accepting anything other than string literals.

@fatherofinvention Can you share code. ?

ah seems the url is a static value - so you have to enter just the static url there.

You can use dynamic urls - by binding the url as dynamic attribute.
I see we have missed that from the list of dynamic attributes, so I will add it in todays update.

for now just prefix the url= attribute in your code with dmx-bind:url=
then you can use expressions as values, like:

javascript syntax:
dmx-bind:url="'https://api.iextrading.com/1.0/stock/' + var.value + '/new'"

or template syntax (more easier as it doesn’t require quotes):
dmx-bind:url="https://api.iextrading.com/1.0/stock/{{var.value}}/new"

See more about app connect dynamic attributes:

and Dynamic Attributes throught the Wappler UI

1 Like

Impressive update! The dynamic URL works perfectly. Thank you @George !

1 Like

Seems like im having the same problem, next to the URL field in the API DATA SOURCE, I have a clipboard icon, i dont see how to use dynamic data.

I tried the dmx-bind above but couldnt get the api schema.

Based on the end of this thread it seems that its been patched.

Mac Version 3.9.1 (3.9.1)

Hi Tim,

Are you saying you have tried this?

To get the schema, you provide a static url, and data samples for any query parameters you might need inside the Define Schema panel. You can also provide a sample response if your api vendor makes that available.