How to upload PDF file by using UiPath HTTP Request through Monday.com API

How To Use UiPath HTTP Request Activity For A GraphQL API Endpoint?

After reading above article, I am able to get, add, edit data in Monday.com through UiPath HTTP Request

I am able to upload files as well, however, my .pdf file converted to .file after sending upload request to Monday, therefore,

my question is how to upload PDF file by using UiPath HTTP Request through Monday.com API, and make sure the file is still a .pdf file but not .file

My current approach is converting my local file to base64 string, then place it in the api query

Below is the feedback on my approach from Monday.com support
"(uploading files base64 encoded) and unfortunately, this is not officially supported, this is why all files are uploaded with the same generic data name and no file extension is added, because there is no way to specify this information in a base64 encoded file string unless is specifically handled in the server end that receives the file.

the officially supported method to do so is with multipart/form-data requests, which does send this information as part of the request. You can check the documentation about it here."

My second question is how to convert local file path to multipart/form-data without using invoke code, curl, postman, or vb.net?

Hello, have you tried the solution mentioned here? How to send a Body type "Form Data" using POST in a HTTP Request - #2 by Mateus_Cruz

Hi @yikwen.goo
Thanks for the quick response!

I simply create content-type in headers, and place file in attachments property as mentioned in that post but result in 400 status.

Can you share more about on how to apply that in my situation? :pray:

Hmm perhaps to isolate the problem could you try to make the API call via Postman? So that we can see if it’s a problem with the UiPath robot sending the request, or is it the request itself that’s having a problem.

Hello Max! To upload a PDF file to Monday.com using UiPath HTTP Request activity, you can follow these steps:

  1. Obtain an API key from Monday.com: You’ll need an API key with appropriate permissions to upload files to your Monday.com account. If you don’t have one, you can generate it from the Monday.com developer settings.
  2. Create a new request in UiPath: In UiPath Studio, drag and drop an HTTP Request activity onto your workflow.
  3. Configure the HTTP Request activity:
  • Set the “Method” property to “POST”.
  • Set the “Endpoint” property to the Monday.com API URL for file uploads, which is https://api.monday.com/v2/file.
  1. Add headers:
  • Click on the “Headers” property to open the Headers Collection Editor.
  • Add a new header with the key “Authorization” and the value “YOUR_API_KEY”, replacing “YOUR_API_KEY” with the API key you obtained from Monday.com.
  1. Build the request body:
  • Create a new Dictionary variable to hold the request body parameters.
  • Add a key-value pair to the dictionary with the key “query” and the value as a JSON string containing the necessary information. For example:
{
  "query": "mutation ($file: File!) { add_file_to_column (file: $file, item_id: YOUR_ITEM_ID, column_id: YOUR_COLUMN_ID) { id } }",
  "variables": {
    "file": null
  }
}

    • Replace “YOUR_ITEM_ID” with the ID of the item in Monday.com where you want to upload the file, and “YOUR_COLUMN_ID” with the ID of the column in that item where the file should be uploaded.
  1. Read the PDF file as bytes:
  • Use the Read PDF Text or Read PDF with OCR activity to read the PDF file as a byte array.
  • Store the resulting byte array in a variable.
  1. Update the request body:
  • Update the “variables.file” value in the request body dictionary with the byte array obtained from the PDF file.
  1. Convert the request body to JSON:
  • Use the Serialize JSON activity to convert the request body dictionary to a JSON string.
  • Store the JSON string in a variable.
  1. Set the request body in the HTTP Request activity:
  • Set the “Body” property of the HTTP Request activity to the JSON string variable created in the previous step.
  1. Send the HTTP request:
  • Execute the HTTP Request activity to send the request to Monday.com.
  1. Process the response:
  • Handle the response from Monday.com as needed in your workflow. The response may contain information about the uploaded file, such as the file ID.

Make sure to customize the API endpoint, headers, query, and other parameters according to your specific requirements and the Monday.com API documentation.

Hi @samuc4

Thanks for the informative reply!
This looks so close to the solution for my scenario. Can you please help me on some details?

-Is this the correct dictionary variable? (Dictoinary<String,JsonObject>)
-Need to initialize it? If yes, may I ask how?

I got this error by placing the example value you provided in the default of Dictoinary<String,JsonObject>
image

-Is it possible to replace it with a string variable and how?

-Do you mean to use File.ReadAllBytes(FileVariable)? Does it requires to convert to base64 string?

-Do you mean to replace the “null” in dictionary to the pdf byte variable?

-Can you show the steps in detail for this?

Thanks for your time :pray:

Hi @mlellison ,
Please use Add Parameter and Attachment property of the HttpRequest activity to pass the data.
Refer below screenshot for example.

Hi Amit,

Thanks for the quick response!

I have tried your suggested method but result in 400 status with below error message
“Unsupported query”

Can you please help me with 2 follow up questions
1.) what is the value of the query parameter?

2.) about attachment, I just needed to use variables[file]? Do I need to create any variable with specific type or else?

Hi @mlellison ,

Below is the details.

  1. “mutation add_file($file: File!) {add_file_to_column (item_id: <your_id>, column_id:”“files”" file: $file) {id}}"
  2. It’s your choice you can either pass variable holding path of the file. For e.g. in my example I am passing the full path of the file directly.

Hi Amit,

Thank you so much! It works!

May I ask what does variables[file] means? Is it just a random name? What happen if I use something else like attachment[pdf]?

One more question is where to find that query, seems not found in doc?

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.