Hey Monday-Team,
I’m having trouble adding a file to a column one by one with cURL.
I’m using the the following example and can successfully add a file to a column:
// Connect the API and send the file.
$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":' . $item_id . ', "column_id": "' . $column_id . '"}',
'map' => '{"application/pdf":"variables.file"}',
'application/pdf' => new \CURLFILE( $file )
),
CURLOPT_HTTPHEADER => array(
'Authorization: ' . $token
),
) );
$response = curl_exec( $curl );
curl_close( $curl );
What I’m trying to do now is the exact same thing, but with an array of files.
So for each iteration I set the column_id and the path to the file and run a new cURL connection:
foreach ( $file_entry as $column_id => $file ) {
// Connect the API and send the file.
$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":' . $item_id . ', "column_id": "' . $column_id . '"}',
'map' => '{"application/pdf":"variables.file"}',
'application/pdf' => new \CURLFILE( $file )
),
CURLOPT_HTTPHEADER => array(
'Authorization: ' . $token
),
) );
$response = curl_exec( $curl );
curl_close( $curl );
}
A key/value pair of the array looks like this:
[02-Aug-2022 11:01:18 UTC] file
[02-Aug-2022 11:01:18 UTC] /sites/mywebsite.com/files/wp-content/uploads/wp_dndcf7_uploads/wpcf7-files/myfile.pdf
But once I send the cURL request within the iteration I’m always getting the following error:
"{\"error_code\":\"ChangeColumnValueError\",\"status_code\":400,\"error_message\":\"no implicit conversion of Symbol into Integer\",\"error_data\":{\"error_reason\":\"automations.history.failed_trigger_details.error_reason.change_column_value_failed\"}}"
Any help is greatly appreciated,
Patrick