This topic is locked
[SOLVED]

 Dynamic API Query

1/31/2021 12:50:17 PM
PHPRunner General questions
S
salus1 authorDevClub member

Hello,
Is there a way to dynamically insert user-supplied parameters into an API query URL prior to calling the API?
For instance, in the URL below...
https://vpic.nhtsa.dot.gov/api/vehicles/GetParts?type=565&fromDate=1/1/2015&toDate=5/5/2015&format=json
...is there a PHPRunner method available to prompt the user, prior to calling the API, for the type, fromDate, and toDate parameters?
The underlying reason for this request is to enable users to dynamically search by Movie Title in this PHPRunner-generated view...
https://www.customdataservices.net/restapisdb/tmdb_now_playing_list.php?a=return

Sergey Kornilov admin 2/1/2021

You can point the end-user to the Advanced Search page where they can enter From and To dates. The main idea is to show them some other page first before taking them to the List page.

S
salus1 authorDevClub member 2/1/2021

Thanks Sergey. I think that would work to search the API response. I'd like to be able to adjust the parameters into the URL prior to querying the API.
In Excel I calculate the query URL and use the WEBSERVICE() function to run the query (see https://www.xlsql.net/intro.htm#sheet-3 for example).
Is it possible to emulate this dynamic approach in PHPRunner?

Sergey Kornilov admin 2/1/2021

Your understanding is incorrect. Data entered on the Advanced Search page can be passed to the REST API in order to form a dynamic request.
Use 'Insert variables' button:

https://xlinesoft.com/phprunner/docs/rest-views.htm

S
salus1 authorDevClub member 2/1/2021

Which is exactly why you get the big bucks (hopefully). Yet another amazing PHPRunner capability, see it in action...
https://www.customdataservices.net/restapisdb/rest_api_list_list.php
Click the "TMDB - Search By Title" menu option and enter some text to dynamically search the TMDB movie database (600,000+ records).
The only outstanding issue is the error caused by submitting an empty query string or clicking the "Show All" button.
Is there a way to have it error out a little more gracefully if this occurs?
Thanks!

S
salus1 authorDevClub member 2/1/2021

Sorry, never mind, eventually I'll learn to check the manual first. Working great now.
Thanks!