• [Wébinaire 13 novembre 2025] Comment l’IA optimise la performance marketing in HubSpot ?

    S'inscrire

APIs & Integrations

HemanthKotha
Membre

invoke an external API to send the record's data and the uploaded File (Image)

Résolue

Hi All,

I have a use case where the user fills out and submits the form along with a File upload (Image). Now the record is saved in the HubSpot with the Uploaded File (Image) as a property. 

Problem: Now I have to sync this record's data (along with the Uploaded Image) to an External system. 

The solution can be:
Use a Custom Coded action to read the data and the Image file in the workflow's Webhook to call an external API.

Could you please let me know if this is a feasible solution? If not, please suggest a better approach.


Thanks a million!


0 Votes
2 Solutions acceptées
evaldas
Solution
Expert reconnu | Partenaire solutions Platinum
Expert reconnu | Partenaire solutions Platinum

invoke an external API to send the record's data and the uploaded File (Image)

Résolue

I am not very familiar with Python and have not used it in this context, but you could try:

 

import requests
import base64

response = requests.get(file_url)
encoded_string = base64.b64encode(response.content)

 

However, if the external system expects a file object instead of base64 string, you could also try using BytesIO:

 

import requests
from io import BytesIO

def processFile(fileUrl):
   response = requests.get(fileUrl)
   file_bytes = BytesIO(response.content)
   external_system.upload(file_bytes)
   

 

Ultimately depends on how the external system is able to process and store files.

 

✔️ Did this post help answer your query? Help the community by marking it as a solution.

Voir la solution dans l'envoi d'origine

0 Votes
HemanthKotha
Solution
Membre

invoke an external API to send the record's data and the uploaded File (Image)

Résolue

Hi @evaldas Thanks for the solution.

Here is what I have tried: Reading and encoding a file. It works.

const axios = require('axios'); // For making HTTP requests.

exports.main = async (event, callback) => {

    try {
        // Example: Get contact properties from the event
        const contactId = event.object.objectId;
        const contactEmail = event.inputFields['email'];
        const file = event.inputFields['uploadedFile'];

        const response = await axios.get(file, {
            responseType: 'arraybuffer',
        });
        const base64Image = Buffer.from(response.data, 'binary').toString('base64');
      
        // Payload to send to the external system
        const payload = {
            id: contactId,
            email: contactEmail,
            filename: "uploaded-image.png", // Replace with desired file name.
            filetype: "image/png", // Replace with the correct MIME type if different.
            content: base64Image, // Base64 encoded content.
        };


        callback({
            outputFields: {
                status: "Success",
                payload: payload,
            },
        });
    } catch (error) {
        console.error("Error posting data: ", error);

        // Return error response
        callback({
            outputFields: {
                status: "Error",
                message: error.message,
            },
        });
    }
};

 

Voir la solution dans l'envoi d'origine

5 Réponses
evaldas
Expert reconnu | Partenaire solutions Platinum
Expert reconnu | Partenaire solutions Platinum

invoke an external API to send the record's data and the uploaded File (Image)

Résolue

Hi @HemanthKotha,

 

Yes, you could utilize the Custom Coded Action in a workflow to be triggered when someone submits a form in HubSpot. 

 

In this Custom Coded Action you could retrieve the contact's data via the Contacts API and then utilize the external API to pass that retrieved data into your destination.

 

Files are only referenced in the contact property and are actually uploaded to the file manager during form submission, so you may also need to utilize the Files API to retrieve the file. If that file upload is set to private, then you will need to utilize the signed URL endpoint to access it.

 

Hope this helps!

✔️ Did this post help answer your query? Help the community by marking it as a solution.

0 Votes
HemanthKotha
Membre

invoke an external API to send the record's data and the uploaded File (Image)

Résolue

Hi @evaldas, Thanks for your reply and for pointing me in the right direction when it comes to reading the files.

However, I need to read the file(Image) and post it to an external system. 

As we can use Python in the Coded Actions, Does the following sample code make sense to read the file and encode?

import base64
with open("yourfile.ext", "rb") as image_file: encoded_string = base64.b64encode(image_file.read())

Where 'yourfile.txt' is the URL of the file. 


Maybe we can pass this endoded_string as a parameter to the external system and they will decode it to recreate the image.

Could you let me know your thoughts on this, please?


Best,
Hemanth





0 Votes
evaldas
Solution
Expert reconnu | Partenaire solutions Platinum
Expert reconnu | Partenaire solutions Platinum

invoke an external API to send the record's data and the uploaded File (Image)

Résolue

I am not very familiar with Python and have not used it in this context, but you could try:

 

import requests
import base64

response = requests.get(file_url)
encoded_string = base64.b64encode(response.content)

 

However, if the external system expects a file object instead of base64 string, you could also try using BytesIO:

 

import requests
from io import BytesIO

def processFile(fileUrl):
   response = requests.get(fileUrl)
   file_bytes = BytesIO(response.content)
   external_system.upload(file_bytes)
   

 

Ultimately depends on how the external system is able to process and store files.

 

✔️ Did this post help answer your query? Help the community by marking it as a solution.

0 Votes
HemanthKotha
Solution
Membre

invoke an external API to send the record's data and the uploaded File (Image)

Résolue

Hi @evaldas Thanks for the solution.

Here is what I have tried: Reading and encoding a file. It works.

const axios = require('axios'); // For making HTTP requests.

exports.main = async (event, callback) => {

    try {
        // Example: Get contact properties from the event
        const contactId = event.object.objectId;
        const contactEmail = event.inputFields['email'];
        const file = event.inputFields['uploadedFile'];

        const response = await axios.get(file, {
            responseType: 'arraybuffer',
        });
        const base64Image = Buffer.from(response.data, 'binary').toString('base64');
      
        // Payload to send to the external system
        const payload = {
            id: contactId,
            email: contactEmail,
            filename: "uploaded-image.png", // Replace with desired file name.
            filetype: "image/png", // Replace with the correct MIME type if different.
            content: base64Image, // Base64 encoded content.
        };


        callback({
            outputFields: {
                status: "Success",
                payload: payload,
            },
        });
    } catch (error) {
        console.error("Error posting data: ", error);

        // Return error response
        callback({
            outputFields: {
                status: "Error",
                message: error.message,
            },
        });
    }
};

 

evaldas
Expert reconnu | Partenaire solutions Platinum
Expert reconnu | Partenaire solutions Platinum

invoke an external API to send the record's data and the uploaded File (Image)

Résolue

 @HemanthKotha - glad to hear it works and thanks for sharing

✔️ Did this post help answer your query? Help the community by marking it as a solution.

0 Votes