0

I am trying to add data to Data Extension using SSJS Script through Automation Studio.

1.I want to HTTP GET(ThirdParty's recomend) 2.I want to catch response(JSON) and add data to Dataextension

How can I do?

<script runat="server">
Platform.Load("Core","1");
var url = 'https://api.zipaddress.net/?zipcode=';
var response = HTTP.Get(url);
</script>
7
  • 1
    Can you post your current SSJS code, and let us know exactly where you are stuck? Your question is very broad, as it covers both integrating with external API, parsing JSON and upserting to a DE – Lukas Lunow Oct 19 '19 at 6:19
  • @LukasLunow Thank you for comment. First, I want to integrating with external API. However I can't check my response. How do I check API status? – Janet222 Oct 19 '19 at 7:10
  • Hi @Janet222, the easiest way to check the response is to write it, eg. Write(Stringify(response));. You can also use try/catch for debugging. – zuzannamj Oct 19 '19 at 8:13
  • Hi @zuzannamj Thank you for comment. If I write Write(Stringify(response)); How can I see String data ? – Janet222 Oct 19 '19 at 10:00
  • Develop code on a CloudPage first, before moving it into Automation Studio. Write() will write to HTML, that is display results on screen – zuzannamj Oct 19 '19 at 10:58
3

Here's a working example of an HTTP.Get call, parsing the response and writing it to a Data Extension. You can modify it for your needs and add exception handling.

Data Extension name: "Log"

JSON attribute logged: "explanation"

Script:

<script runat="server">
  Platform.Load("Core","1.1.1");
  try{

var apikey = ""; //pass apikey
var url = "https://api.nasa.gov/planetary/apod?api_key=";
var response = HTTP.Get(url +apikey);
var content = Platform.Function.ParseJSON(response.Content);
var log = DataExtension.Init("Log");
log.Rows.Add({explanation:content.explanation});

      }catch(e){
    Write(Stringify(e));
  }
</script>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.