Generate Images in SharePoint with OpenAI API DALL-E and Power Automate

2 minute read

Generate Images in SharePoint with OpenAI API DALL-E and Power Automate


In SharePoint, images play an important role in standing out your content. We often need sample images to support the news and articles. OpenAI API DALL-E is the best fit in this case to generate images related to any topic.

In this article, we will explore how OpenAI API DALL-E can be combined with Power Automate to generate images in SharePoint.

Get the API Key

Follow the below steps to get the API key to work with Open AI APIs.

  1. Navigate to OpenAI. Sign up, or register to proceed.

  2. From your profile, select View API Keys.

  3. Click + Create new secret key to create one. Note down the secret key for future use.

OpenAI Images - API Reference

OpenAI provides valuable documentation on generating images.

Create image

An image can be generate by using below API:


Pass the minimum request body as follows:

  "prompt": "<prompt>",
  "n": [n],
  "size": [size]

The request body parameters can be explained as follows:

  • prompt (required): string representing description of the image to generate. (Maximum 1000 characters)
  • n (optional): Number of images to generate between 1 to 10. Defaults 1.
  • size (optional): Size of the image to generate. Allowed values: 256x256, 512x512, or 1024x1024. Defaults 1024x1024.

Below sample request will generate 3 images of duck swimming in the pond.

  "prompt": "duck swimming in the pond",
  "n": 3,
  "size": "1024x1024"

We will use these APIs to generate the image and upload it to SharePoint using Power Automate.

Power Automate

We will now develop a Power Automate flow to make a request to OpenAI API DALL-E to generate the images, which then can be uploaded to SharePoint.

Follow the below steps to set up the Power Automate flow:

  1. We will start by creating an instant cloud flow and add manual inputs as follows:
    • prompt: description of the image(s) to generate.
    • Number of files: Number of images to generate.
    • File Name: Format to follow for the file name. (e.g. input of duck-swim will generate images as duck-swim-1, duck-swim-2, and so on based on value specified for the Number of files parameter).

  2. In the next step, we will use HTTP action to post the request to OpenAI API. This will help us to get the image URLs from OpenAI.

    The sample response output is generated as follows:

         "created": 1682092329,
         "data": [
             "url": ""
             "url": ""
             "url": ""
  3. Run the flow manually to see the result. Copy the Body from the output of the HTTP request.
  4. Now, we will use Parse JSON action to extract the output.

  5. In the next step, let us initialize a variable named varFileNumber of type integer to name the files with incremental value.

  6. Using the Apply to each action, we will iterate through each image URL generated by OpenAI API DALL-E.

  7. In the next step, use the Create file action of SharePoint to create a file from URL returned by OpenAI DALL-E API. Increment the variable varFileNumber to generate incremental value for the file name.

    The file name is generated with below formula:

     concat(triggerBody()['text_1'], '_', variables('varFileNumber'), '.png')

Note: You may use RegEx to extract out the actual file name generated from the OpenAI.

End Result

After running the Power Automate, the sample images will be generated in the SharePoint document library as follows.


OpenAI DALL-E API can be used effectively to generate sample images related to any topic. This feature can be combined with Power Automate to generate images in SharePoint.


Leave a comment