Watch the video on YouTube: https://youtu.be/W6mj5JzugBY

How easy is it to integrate ServiceNow with external APIs? VERY EASY it turns out! Watch this video to see how I used a CATALOG ITEM, FLOW DESIGNER and one custom ACTION to request images from OpenAI’s DALL·E 2. It doesn’t take much to bring this together and at the end of the video, you will have enough information to create your own integration! #servicenow #openai #dalle2 #ai #artificialintelligence #integrations #flowdesigner

Generate Image code:

(function execute(inputs, outputs) {
  //Setup input variables
  var response = inputs.rest_payload;
  var attachment_record = inputs.requested_item;
  
  //Parse the response payload to an object
  var result = global.JSON.parse(response);

  //Loop through the JSON object and create an image attachment for each item in the array
  for (var i in result.data) {
    //JSON structure from DALL-E {"created": 1234356,"data": [ {"b64_json":"content","b64_json":"content"...}]}
    var image_num = i + 1;
    var fileName = 'image' + image_num + '.png';
    var contentType = 'image/png';
    var base64EncodedContent = result.data[i].b64_json;
    var attachment = new GlideSysAttachment();
    var agr = attachment.writeBase64(attachment_record, fileName, contentType, base64EncodedContent);
  }  
  
})(inputs, outputs);