Uploading a file to a column with the Api

hi @pwolter
Welcome to the community. Although I did not do file upload in any of my Node projects (yet) I struggled some time ago with a PHP project.

$eol = “\r\n”;

$header = array(
‘User-Agent’ => MONDAY_TEAM . ’ GraphQL Client’,
‘Authorization’ => get_field(‘mondaykey’, ‘user_’ . get_current_user_id()),
‘Content-Type’ => ‘multipart/form-data; boundary=’ . $boundary
);

//We need to build the body from scratch because it is multipart with boundaries
//Take care of the extra empty lines (twice $eol) before the actual query and file, otherwise an error 500 is returned

$body = ‘–’ . $boundary . $eol;
$body .= ‘Content-Disposition: form-data; name=“query”’ . $eol . $eol;
$body .= 'mutation ($file: File!) {add_file_to_column (item_id: ’ . $item_id . ‘, column_id: file, file: $file) {id}}’ . $eol;
$body .= ‘–’ . $boundary . $eol;
$body .= ‘Content-Disposition: form-data; name=“variables[file]”; filename="’ . $upload[‘name’] . ‘"’ . $eol;
$body .= 'Content-Type: ’ . $upload[‘type’] . $eol . $eol;
$body .= file_get_contents($upload[‘value’]);
$body .= $eol . ‘–’ . $boundary . ‘–’;

$response = wp_remote_post( MONDAY_URL . ‘file/’, [‘headers’ => $header, ‘body’ => $body] );

Maybe this snippet help you.

Are you trying to upload a JSON in the file column? (Content-Type)