Upload files on column from monday API using PHP

Upload files on column from url by the help of monday API

{

"query": "mutation($file: File!){ add_file_to_column(item_id:1691630609, column_id: \"files\", file: $file) { id }}",

"variables[file]":"@DSC_0139.jpeg" 

}
I am using this code in postman

DSC_0139.jpeg file available in my …/postman/file/ DSC_0139.jpeg

and Very important point is my all files uploaded on AWS s3 storage so how can i use these file for uploading
Thanks
Preetam kumar joshi

@preetamkumarjoshi

Thanks for reaching out and joining our community. As mentioned before over email, you will not be able to upload files to monday.com via URL. You can only send files to our API from local storage by sending the file itself in bytes.

The solution I can currently recommend is downloading the file from AWS servers, then creating the file’s octet stream and sending that to monday.com as part of a multipart-form/data request.

-Alex

Hi @AlexSavchuk
Thanks Alex, i will do it in my php code but as of now
as you can see in image i have added the file from local storage
But issue is same
Is there may be any permission issue ?
Thanks
Preetam

@preetamkumarjoshi

Based on the code you are showing, you are just sending the file path as a variable. This is not something our API will accept.

Perhaps the following snippet in JS can help clarify further:

Code example - uploading files with variables using Node1

-Alex

Hi @AlexSavchuk

Could you please send me your PHP_curl request code of postman ?
and please please give me example of image add in curl request I have no idea how can I add the local file in variables[file]

Thanks
preetam kumar joshi

@preetamkumarjoshi

Here’s a PHP-cURL request as well for you, generated from Postman:

<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => 'https://api.monday.com/v2/file',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_POSTFIELDS => array('query' => 'mutation ($file: File!) { add_file_to_update (file: $file,update_id:UpdateIDHere) { id } }
','variables[file]'=> new CURLFILE('filepath/file.jpg')),
  CURLOPT_HTTPHEADER => array(
    'Authorization: yourApiKey'
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;

Here’s one with using variables for Item and Column IDs:

<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => 'https://api.monday.com/v2/file',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_POSTFIELDS => array('query' => 'mutation ($file: File!, $item_id: Int!, $column_id: String!) { add_file_to_column ( item_id:$item_id, column_id: $column_id, file: $file) { id}}','variables' => '{"item_id":yourItemId, "column_id": "columnId"}','map' => '{"image":"variables.file"}','image'=> new CURLFILE('/filepath/file.jpg')),
  CURLOPT_HTTPHEADER => array(
    'Authorization: yourAPIkey'
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;

I hope this helps!

-Alex

Alex,
I am using this code
$curl = curl_init();

	curl_setopt_array($curl, array(
	  CURLOPT_URL => 'https://api.monday.com/v2/file',
	  CURLOPT_RETURNTRANSFER => true,
	  CURLOPT_ENCODING => '',
	  CURLOPT_MAXREDIRS => 10,
	  CURLOPT_TIMEOUT => 0,
	  CURLOPT_FOLLOWLOCATION => true,
	  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
	  CURLOPT_CUSTOMREQUEST => 'POST',
	  CURLOPT_POSTFIELDS => array('query' => 'mutation ($file: File!, $item_id: Int!, $column_id: String!) { add_file_to_column ( item_id:$item_id, column_id: $column_id, file: $file) { id}}','variables' => '{"item_id":1691757704, "column_id": "files"}','map' => '{"image":"variables.file"}','image'=> new CURLFILE('C:/Users/shree/Pictures/DSC_0139.jpeg')),
	  CURLOPT_HTTPHEADER => array(
	    'Authorization: MY_AUTH_KEY'
	  ),
	));
	
	$response = curl_exec($curl);
	
	curl_close($curl);
	echo $response;die;

Nothing happened from this code for me, is my image path correct or something other error?

@preetamkumarjoshi

I’ve just checked our logs and I do not see any errors, and it seems like the request has gone through without issues. Could you clarify what the response from using this code was?

Here’s another example for you:
PHP Example to upload files from Bas de Bruin

-Alex

Hi Alex,

You guy amazing and the monday.com is really really good, I have successfully uploaded files from curl

Alex your helping nature really appreciable, I am so happy to work with you

but I need to think for remote file upload without download at my end
because if I will do like download and then add, which is so much time consuming, one more point is I have multi upload file that could consume more time

I will try to create blob and others

it is possible to do like that?, or you have any suggestions for me and monday.com users :slight_smile:

Thanks
Preetam kumar joshi

1 Like

@preetamkumarjoshi

Ah, amazing! I’m really glad to hear you were able to find a solution to this now.

If you don’t mind me asking, is there any chance you could share what was the fix for you? I’m really curious!

In terms of uploading a file from a remote location, as mentioned, this is not possible. I think you’ve mentioned before that you are using AWS - if so, you could attempt to send the Binary data of your file from AWS to monday.com, as this is what our platform will expect. To be transparent with you, I can not confirm whether this solution will work in practice, though.

Binary data - AWS API

Uploading multiple files is not an option at all, I’m afraid, and there isn’t any workaround I can suggest here. I’ll definitely pass that on as a feature request, thoguh.

-Alex

Hi @AlexSavchuk

Hope you are well, I was forget to see monday, I get the email from monday and then i remembered to reply

there was the image path issue, when we was runing the mutation query in postmain there is configuration for files( where to pick files)

And when I was run this query in my php it’s run successfully

Thanks
Preetam kumar joshi

Hello @preetamkumarjoshi!

Thank you for the reply :slightly_smiling_face:

Maybe your experience will be useful to other users :muscle:

Cheers,
-Matias