How to attach a file to HubSpot contact through APIs, in Power Automate

With this article, the issues and solutions I am trying to address are:

  1. How to use HubSpot APIs
  2. How to upload a file to HubSpot
  3. How to make association between a Contact and the uploaded file
  4. How to achieve all of these using Power Automate

On a high level, below is the list of API tasks we have to do to achieve this. We have to make requests to three calls (one less if you have Customer ID already).

High level Power Automate flow

See below the high level flow I have created to demonstrate:

Prerequisites

  1. Basic knowledge in HubSpot. We would be interacting the CRM Contacts and Library
  2. Good knowledge in Power Automate
  3. A HubSpot account – Sandbox / Developer
  4. Create a Private App in HubSpot
  5. Get an Access Token
  6. Create a sample contact in HubSpot (for testing)
  7. Create a folder in the HubSpot Library (optional)

Detailed Flow

In this example, I am using a HTTP Request Trigger, which starts when we POST a file and a email-id (I used it to represent a customer in HubSpot contact form). I am doing some

Set the stage

For those struggling to get few items from the POST’ed content, find below details for your reference.

Using Postman to trigger a Power Automate HTTP flow

A. Get File content

triggerOutputs()['body']['$multipart'][0]['body']

B. Get filename

Honestly, I am not sure if there is a straight forward method available. This is my way of parsing filename from the Content-Disposition string:

// Input sample: "headers": {
//        "Content-Disposition": "form-data; name=\"email\"",
//        "Content-Length": "25"
//      }

// Power fx
trim(concat(split(split(triggerOutputs()['body']['$multipart'][0]['headers']['Content-Disposition'], 'filename="')[1], '"')[0]))

C. Get Email

triggerOutputs()['body']['$multipart'][1]['body']['$content']

HubSpot API Calls

Since the APIs for fetching Contact ID and Uploaded File ID are independent tasks, I am executing them in parallel.

A. Upload file, and get file id

I have used only minimum number parameters to avoid the confusion. I am uploading the file to a folder in the library.

Find the POST’ing JSON script for the Body. I see many people are struggling to make this correct.

{
  "$content-type": "multipart/form-data",
  "$multipart": [
    {
      "headers": {
        "Content-Disposition": "form-data; name=\"folderPath\""
      },
      "body": "/Sample Folder"
    },
    {
      "headers": {
        "Content-Disposition": "form-data; name=\"file\"; filename=\"@{variables('Filename')}\""
      },
      "body": @{variables('file')}
    },
    {
      "headers": {
        "Content-Disposition": "form-data; name=\"options\""
      },
      "body": {
        "access": "PRIVATE"
      }
    }
  ]
}

Upon successful upload, you will be receiving a JSON response with File ID.

B. Get the Customer ID of a contact using email as parameter.

This is a straight forward task. Just call the API using GET. Example: https://api.hubapi.com/crm/v3/objects/contacts/john@mathew.com?idProperty=email

C. Create Contact-File association

Once you have FileID and Contact ID, now you can POST a create-note API call to https://api.hubapi.com/crm/v3/objects/notes

Below is the JSON body you have to use:

{
    "properties": {
        "hs_timestamp": "2024-07-30T10:30:00.000Z",
        "hs_attachment_ids": "<File ID>"
    },
    "associations": [
        {
            "to": {
                "id": "<Customer ID>"
            },
            "types": [
                {
                    "associationCategory": "HUBSPOT_DEFINED",
                    "associationTypeId": 10
                }
            ]
        }
    ]
}

Note: associationTypeId is the magic number which tells the API to make Contact-File association. Please check the documentation for more association types.

Find the Power Automate action view:

Verify if the flow has worked

Go to HubSpot, select contact and you should be able to see the file attached.

Additionally, if you go to the Library -> Files -> Sample Folder, you can see the same file appearing there.

Power Automate: POST a file to trigger a HTTP flow and upload to SharePoint

My use case here was to store the resumes uploaded by candidate in a website directly in a SharePoint list.

Below is the high level flow the process, created in Power Automate (same you can do in Azure Logic Apps as well with similar steps)

image

Here is the output, i.e., data and file uploaded to SharePoint/Office 365

image

The HTTP call is expected to be made from the external application such as a web page but for the purpose of testing, here is the Postman screen used:

image

Detailed flow

Let us start with an HTTP Request Trigger. You will get a URL which looks like in the below screenshot. This is the URL you will be using. By default this will be using anonymous auth, but you can secure it using few methods, like this one.

image

Parsing Json

This is an optional step. I wanted to pass some parameters also in addition to the file upload, but I chose not to send individually but as a json string. Since it is a Json string, I have to parse it to extract values from it.

image

This is the sample input I have. Refer to postman screenshot above.

{

"position": "Java Developer",

"firstname": "Praveen",

"lastname": "Nair",

"email": "praveennnn@abcdef.com",

"phone": "+9715555555",

"urls": ["http://www.google.com", "https://www.adfolks.com"]

}

Create SharePoint List row

Creating a list row and attaching the file is a two step process. First we have to create the row, then using that ID, we have to attach the uploaded file.

image

Final notes

The last send-mail component you see is just to notify someone in recruitment team that there is a job application logged in SharePoint. Same you can achieve using SharePoint notification features so you may ignore it.

I found that getting filename from the uploaded payload is not so straightforward in Power Automate (someone correct me if I am wrong), but anyways I did’nt need that because the logic I had to use here is to create a custom filename using the candidate’s name and adding the extension we get from the content-type.

Automating Bayzat leave calendar to post daily list in Microsoft Teams group

I was wondering if I can have a feature to post who-are-all-on-planned-leave list daily in the HR/leaders group in Microsoft Teams. Searched for a plugin in the marketplace, and tried to find a API also. Finally, contacted the Bayzat support and found they don’t have a developer API available at the moment. Then I went though the normal HTTP calling methods and found it worked well. Sharing with you, hoping someone will find this useful in future.

Here is the Adaptive Card output you get in Teams:

image

This is the high level view of the Power Automate App Flow

image

Details:

Step 1 – Get the authentication access token

This token is required for you to get access to any APIs/URLs. Use the login API for this:

image

Step 2 – Read the Leave Calendar

My requirement is only to read one single day, so I am passing utcNow()

image

Step 3 – Modify the response data as per your requirement

My requirement is small that, I need only list of people marked OOO for this particular day

image

Step 4 – Post to Microsoft Teams

I chose to post the data in Teams as an Adaptive Card, so I am posting in that format

image

Contact me if you need some clarifications. Make sure to add sufficient validations to make this flow error free.

Power Automate: Send daily bugs report in Microsoft Teams from Azure DevOps Boards

You can simply change same to send a mail notification too, instead of Teams.

Sample output on Teams:

image

Development Steps:

Step 01 – Create query in Azure DevOps board for Bugs

I would start with a Recurrence Trigger (schedule). Check always the Time zone of the trigger will happen on GMT.

Step 01 – Schedule

I would start with a Recurrence Trigger (schedule). Check always the Time zone of the trigger will happen on GMT.

image_thumb[2]

Step 02 – Initialize Azure DevOps URL (optional)

I am using this url for hyper linking in the output, which can be considered optional.

image

Step 03– Get bug list from DevOps boards

I suggest you to create a ‘query’ first which returns filtered ‘bug’ results. Below is the query have created and saved for this example blog.

image

Next, get the results from this query:

image

Step 04 – HTML’ize

I wanted to format the Bugs list content as a table and, MS Teams message supports HTML. So I will create a header and assign it to a new variable.

image

Step 05– Convert rows to HTML rows

Next step creates each row from DevOps boards query to corresponding <TR>s. You can choose to omit or add any columns as per your requirement.

image

Step 06 – Close HTML table

Once the rows are added to HTML table, I would close it and add also any footer notes.

image

Step 07– Post message in Teams

Finally, send the message to Teams. I have used a group chat in my case. Additionally I am using a ‘condition’ component also to check if the list is empty so it can directly ‘terminate’ the flow instead of posting an empty table in Teams.

image

Flow view:

This is what my simple Power Automate flow looks like:

image

Power Automate: Send daily status post in Microsoft Teams from a SharePoint List

Assuming you have a “List” in SharePoint and you want to post a summary/or list as-it-is to a chat group in Microsoft Teams. You can simply change same to send a mail notification too, instead of Teams.

Output in Teams:

image

Development Steps:

Step 01 – Schedule

I would start with a Recurrence Trigger (schedule). Check always the Time zone of the trigger will happen on GMT.

image

Step 02 – Get list items from SharePoint

Choose the site address and list name

image

Step 03 – HTML’ize

I wanted to format the SharePoint List content as a table and, MS Teams message supports HTML. So I will create a header and assign it to a new variable.

image

Step 04 – Convert SharePoint rows to HTML rows

Next step creates each row from SharePoint to corresponding <TR>s. You can choose to omit or add any columns as per your requirement.

image

Step 05 – Close HTML table

Once the rows are added to HTML table, I would close it and add also any footer notes.

image

Step 06 – Post message in Teams

Finally, send the message to Teams. I have used a group chat in my case.

image

Flow view:

This is what my simple Power Automate flow looks like:

image