Skip to main content
Announcements
Accelerate Your Success: Fuel your data and AI journey with the right services, delivered by our experts. Learn More
cancel
Showing results for 
Search instead for 
Did you mean: 
Asavela_
Contributor
Contributor

MAKE A REST API URL CONNECTION DYNAMIC

Hello there,
I want to create a connection using the url provided:

https://API.net/api/v1/monthly/YYYY/MM ,

For the connection to be successful I have to insert values for YYYY i.e Year, MM i.e month. I want to configure my YYYY as  Year(Today()-1) and MM as Num(Month(Today), '00') cause I don't want to have to change the URL everytime I'm in a new month.
Please help, thank you.

 

Labels (1)
1 Solution

Accepted Solutions
StephenDunn
Contributor III
Contributor III

Hi Asavela,

You need a 'WITH CONNECTION' statement. First create a connection in the normal way, for example you may create a connection named 'REST_MyAPI', then the script would look something like this:

Let url = 'https://API.net/api/v1/monthly/'&(Year(Today())-1)&'/'&Num(Month(Today()),'00');

LIB Connect To 'REST_MyAPI';

RestConnectorMasterTable:
SQL
SELECT
fieldlist
FROM JSON (wrap on) "root" PK "__KEY_root"
WITH CONNECTION(URL "$(url)"
;

You can include other elements in there too, such as query headers, etc.

View solution in original post

1 Reply
StephenDunn
Contributor III
Contributor III

Hi Asavela,

You need a 'WITH CONNECTION' statement. First create a connection in the normal way, for example you may create a connection named 'REST_MyAPI', then the script would look something like this:

Let url = 'https://API.net/api/v1/monthly/'&(Year(Today())-1)&'/'&Num(Month(Today()),'00');

LIB Connect To 'REST_MyAPI';

RestConnectorMasterTable:
SQL
SELECT
fieldlist
FROM JSON (wrap on) "root" PK "__KEY_root"
WITH CONNECTION(URL "$(url)"
;

You can include other elements in there too, such as query headers, etc.