Created
September 27, 2019 20:27
-
-
Save zuzannamj/939f64f4b02b29ba586448bb4732c6ac to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%%[ | |
var @apikey, @url, @response | |
set @apikey = Lookup("NASAapi","apikey","id","apod") // keep your apikey in a Data Extension | |
set @apikey = "7Apb3QN7qVsXPuPDcSZBKAPf8twca03C5w4Oxuyc" // or hardcode it into your CloudPage | |
set @url = concat('https://api.nasa.gov/planetary/apod?api_key=',@apikey) | |
set @response = HTTPGET(@url,false,0,@CallStatus) | |
]%% | |
<script runat="server" language="javascript"> | |
Platform.Load("Core","1"); | |
//Get the @response variable from AMPscript | |
var response = Variable.GetValue("@response"); | |
//Parse JSON | |
var json = Platform.Function.ParseJSON(response); | |
//Set the @hdurl variable to be accessible in AMPscript | |
Variable.SetValue("@hdurl",json.hdurl); | |
</script> | |
<img style="height:100vh" src="%%=v(@hdurl)=%%"> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment