How to use add_file_to_column in VB.NET (API Call)

Hi there.

I’m using https://api.monday.com/v2 to create items from my VB.NET code. I was managed to do that without any problem. Now I need to upload some files to monday.com using APIs.

I found this article Accessing and upload files using the GraphQL API.

But couldn’t find any VB.NET or C# examples for add_file_to_column. Can somebody share a VB.NET or C# code sample for the add_file_to_column API call?

Thanks in advance.
Din

1 Like

Hi @dinithij,

Welcome to the community!

I don’t have an example in VB or C# for you sorry as I don’t work with these languages, however you only need to make a POST request to https://api.monday.com/v2/file

You should be able to complete this in the same way that you have created a new item, you simply need to change the endpoint and the variables that you are passing.

1 Like

Thank you for your reply Mitchell. Yes I did a POST request to https://api.monday.com/v2/file. My problem is attaching the file and query.

Thanks
Din

Hey there @dinithij :wave:

To be transparent with you, I do not use VB.net or C# myself, but I will definitely be on the lookout throughout the community to see if there are any helpful resources I could pass here. If I’ll find anything relevant to your request, I’ll reply to this thread :slight_smile:

In case you do get this to work using C# and VB.NET, that would be a simply incredible resource to share, if you don’t mind. :slight_smile:

-Alex

Thanks for the input Alex. I still couldn’t make it work. Please share if you find any sample and I will definitely post here if I get this work with C#/VB.NET.

Thanks
Din

I managed to upload files with below C# code

var client = new RestClient(“https://api.monday.com/v2/file”);
var request = new RestRequest(Method.POST);
request.AddHeader(“Authorization”, “XXXXXXXXX”);
request.AddHeader(“Content-Type”, “multipart/form-data”);
request.AddFile(“variables[file]”, “C:/test.txt”);
request.AddParameter(“query”, “mutation($file: File!) {add_file_to_column(file: $file,item_id:XXXXXXX,column_id:"files") {id}}”);
IRestResponse response = client.Execute(request);

When I try to use the same code converted to VB.NET

Dim client2 = New RestClient(“https://api.monday.com/v2/file”)
Dim request2 = New RestRequest(Method.POST)
request2.AddHeader(“Authorization”, “XXXXXXX”)
request2.AddHeader(“Content-Type”, “multipart/form-data”)
request2.AddFile(“variables[file]”, “C:/test.txt”)
request2.AddParameter(“query”, “mutation($file: File!) {add_file_to_column(file: $file,item_id:XXXXXXXX,column_id:”“files”“) {id}}”)
Dim response2 As IRestResponse = client2.Execute(request2)

I received an error {“error_message”:“Unsupported query”,“status_code”:400}

I tried with escape "\ and that gave the same error with VB.NET.

Does anyone have an idea of what’s wrong here?

Thanks
Din

1 Like

@dinithij

Thank you for posting the above examples, I’m sure other community members will find those helpful!

Just to reiterate on the other community post you’ve had about this issue, you will need to properly declare your API request first. I believe that is the issue you are facing here, based on the error code:

Let me know if this helps.

-Alex

I managed to fix my issue. It is due to Rest Client version I had.

So If any one need VB.NET/C# code for add_file_to_column, You can use below code.

C#
var client = new RestClient(“https://api.monday.com/v2/file”);
var request = new RestRequest(Method.POST);
request.AddHeader(“Authorization”, “XXXXXXXXX”);
request.AddHeader(“Content-Type”, “multipart/form-data”);
request.AddFile(“variables[file]”, “C:/test.txt”);
request.AddParameter(“query”, “mutation($file: File!) {add_file_to_column(file: $file,item_id:XXXXXXX,column_id:“files”) {id}}”);
IRestResponse response = client.Execute(request);

VB.NET
Dim client2 = New RestClient(“https://api.monday.com/v2/file”)
Dim request2 = New RestRequest(Method.POST)
request2.AddHeader(“Authorization”, “XXXXXXX”)
request2.AddHeader(“Content-Type”, “multipart/form-data”)
request2.AddFile(“variables[file]”, “C:/test.txt”)
request2.AddParameter(“query”, “mutation($file: File!) {add_file_to_column(file: $file,item_id:XXXXXXXX,column_id:”“files”“) {id}}”)
Dim response2 As IRestResponse = client2.Execute(request2)

Thanks
Din

2 Likes

@dinithij

That is incredible!! Thanks so much for sharing this, I really appreciate it! :slight_smile: I am also really glad to hear you were able to figure out the issue here.

-Alex