How to dynamically create an array with a variable number of inputs from Webhook

I have a webhook that arrives with upto 3 images uploaded by the user to my site. It then passes these images from the webhook to ChatGPT to analyse them.

The issue I have is the maximum images allowed by my site are 3, however if less than 3 are uploaded I get an error. It expects 3 regardless, so I need to configure this to accept 3 or less.

I guess I need to build a count on the images received in the webhook and build an array dynamically on each submission to pass to the ChatGPT Image analysis.

At the moment I configure the ChatGPT Image analysers manually with image data as I dont fully understand the Array syntax it is asking for. Any advice on best logic and components to use appreciated.

I have attached the current Webhook and ChatGPT config.


Hi,

I’d like to suggest a solution for your issue:

  1. Create an array in the following format:

    [
        { 
            "imageUploadType": "imageData", 
            "imageFileData": <image-file-binary-data> 
        }
    ]
    
  2. Next to the “Images” field, you’ll see a “Map” switch. Enable it and use your created array in the object field.

Hope it can help…

1 Like

first of all great job on uploading blob images to make. it took me a while to get that and understand how to work with it!

Assuming that if user uploads only one image it will be always passed in as image0, second as image2…

The easy way to do it is to create a filter and check that the image object exists, run the gpt only if it does. There are other ways that may be more elegant depending what you do afterwards.

btw, if you do want to create an array, you can do something like this (i did it for up to 100 images, works fine):

the slice is there to get rid of the first item… as it would just get in a way.

1 Like

Thanks, I created a “Create” variable and then a “Set variable” in an effort for it to populate it with the information collected from the Webhook. Shots below, is there a specific syntax for the variable value to populate the array please? (or direct me to some reading if this is something I need to research myself)


Hi,
I’m not sure that this is the best way, but that’s what I’m familiar with.
I attach a blueprint that can be an example for this approach.
Hope, it will help you.

blueprint (6).json (10.7 KB)

1 Like