Name is required.
Email address is required.
Invalid email address
Answer is required.
Exceeding max length of 5KB

Environnement variable

I use a Python script get a datetime in Snowflake then i convert it in a format to be able to put this variable when i call the API ( so it becomes dynamic and i dont need to change it manually). Here is a part of my script:

from datetime import datetime

#Get last_import datetime

cursor = context.cursor()
cursor.execute('SELECT MAX("datetime") FROM "AGP_DWH"."PUBLIC"."REPORT_STATUS_SUMMARY_TEST_DWH"')
result = cursor.fetchone()[0]
last_import = result.strftime("%Y-%m-%dT%H:%M:%S")
context.updateVariable('starting_date', 'last_import')
print last_import
print starting_date

And there are the result of the print:
2019-06-07T19:00:00
last_import

How can i update the value of my starting_date environnement variable with the value of last_import so i'll get 2019-06-07T19:00:00 store and not last_import ...

3 Community Answers

Matillion Agent  

Arawan Gajajiva —

Hi Maxim -

I believe you should not have the last_import variable wrapped in single quotes in the context.updateVariable line of your code. By wrapping it in single quotes, it’s being treated as a string and not as a reference to your variable.

As such, I think you need to update this line from:

context.updateVariable('starting_date', 'last_import')

To this:

context.updateVariable('starting_date', last_import)

Can you try that out and see if that resolves your issue?

Best regards,
Arawan


Matillion Agent  

Kalyan Arangam —

Hi maxim

Glad to know it’s working now.

Please see the following link on how to pass parameters into api profiles

https://redshiftsupport.matillion.com/customer/en/portal/articles/2763313-using-parameters-with-api-profiles

Hope that helps

Best
Kalyan


Maxim Morin-Gagnon —

Yes its working thx,

Now if i want to use that environnement variable in my API profile how do you write it, i pretty much tried everything, [] {} nothing and still not able to run this. This is my call

"http://agp.fonivacloud.com:8080/api/reportagentstatussummary.json?start_date=2019-06-06T00:00:00&end_date=2019-06-06T09:00:00&step=hourly&aggregate=agent"

I want both environnement variables to replace the start_date and end_date so this become dynamic

Post Your Community Answer

To add an answer please login