Skip to main content

Hello Monday.com, I need your help!

I’m sending two post req from java

first req is creating ticket

second req tries to upload file(screenshot) on created_item but with no success


Below is my second req code and i also added first and second requested query datas and responses from the server.


public static String updateDefect( String itemID, File file) {

HttpURLConnection connection = null;

String targetURL = “https://levank707.monday.com/v2”;

String query3 = “{"query":"mutation{add_file_to_column(file: “+file+”, "

+ “item_id:”+itemID+”, column_id: "files") {id}}";


  try {
//Create connection
URL url = new URL(targetURL);
connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type",
"application/json");
connection.setRequestProperty("Content-Type",
"multipart/form-data");

connection.setRequestProperty("Content-Length",
Integer.toString(query3.getBytes().length));
connection.setRequestProperty("Content-Language", "en-US");
connection.setRequestProperty("Authorization",token );

connection.setUseCaches(false);
connection.setDoOutput(true);

//Send request
DataOutputStream wr = new DataOutputStream (
connection.getOutputStream());
wr.writeBytes(query3);
wr.close();
System.out.println("\\n\\nThe request of adding files to ticket " +"\\n\\n" + query3);

//Get Response
InputStream is = connection.getInputStream();
BufferedReader rd = new BufferedReader(new InputStreamReader(is));

StringBuilder response = new StringBuilder(); // or StringBuffer if Java version 5+
String line;
while ((line = rd.readLine()) != null) {
response.append(line);
response.append('\\r');
System.out.print("\\n\\n the response of adding files to ticket" + "\\n\\n"+ response);

}
rd.close();
return response.toString();
} catch (Exception e) {
e.printStackTrace();
return null;
} finally {
if (connection != null) {
connection.disconnect();
}
}

}}


reqs and responses


The request for creating ticket


{“query”:“mutation {create_item (item_name:"TestCase0got failed due to some assertion or exception. device name:iPhone11",board_id:1249501957){id}}”,“variables”:{}}


The response of created ticket


{“data”:{“create_item”:{“id”:“1260998189”}},“account_id”:8845295}


The request of adding files to ticket


{“query”:"mutation{add_file_to_column(file: /var/folders/v4/8yb367ws17945wp809g_xcgc0000gn/T/screenshot1211423245607493504.png, item_id:1260998189, column_id: “files”) {id}}


the response of adding files to ticket


{“errors”:r{“message”:“No query string was present”}],“account_id”:8845295}

Hi @levank!


It sounds like the issue you’re running into here is trying to upload a file on a newly created item. When you do, you see the error message you posted above, right?


Just to make sure we’re on the same page-- you’ve verified that your column ID is correct (i.e. you’ve activated Developer’s Mode to see your column ID), and your file is a local file right?


Is this behavior only affecting newly created items? Or is it any time you try to upload a file to your board?


All of this will allow us to better understand the scope of the issue and where it’s coming from.


Thanks!


Hi @Helen thanks for your response.


Yes, I have seen column_id in files drop down list after activated developer mode from Monday labs and it is “files”.


I have this kind error on the old one items also.


and yes I’m trying to upload screenshot from my local project.


to be honest, I want to create item with title and attached screenshot, so because of I’m not able to do it in one query, first I’m creating new item and then I’m trying to upload screenshot on that item


I’m curious to learn: are you seeing this same behavior if you try and replicate it in Postman for example?


I would definitely recommend following the structure specified by my colleague in this post here to see if that helps.


@Helen

I tried and its same, then I tried @AlexSavchuk query it was not same but I faced some html error


here is full response log. full log · GitHub


Oh! Apologies, I missed this the first time around, but I see you’re sending a POST request to the wrong endpoint.


It should be either https://api.monday.com/v2/file or https://api.monday.com/v2.


Do you mind giving these a try?


JAVA

https://api.monday.com/v2

query → {"query":"mutation{add_file_to_update(file:“+file+”, "

+ “update_id:”+itemID+“) {id}}}”


response → {“errors”:e{“message”:“No query string was present”}],“account_id”:8845295}


https://api.monday.com/v2/file

query → {"query":"mutation{add_file_to_update(file:“+file+”, "

+ “update_id:”+itemID+“) {id}}}”

response → 404


POSTMAN


https://api.monday.com/v2


query: mutation add_file($update_id:Int!, $file: File!) {add_file_to_update(update_id: $update_id, file:$file) {id}}

variables: {“update_id”:1262644561}

map: {“image”:“variables.file”}

image: (image path)


response

{

“errors”: p

{

“message”: “Variable file of type File! was provided invalid value”,

“locations”: i

{

“line”: 1,

“column”: 36

}

],

“value”: null,

“problems”: l

{

“path”: ,

“explanation”: “Expected value to not be null”

}

]

}

],

“account_id”: 8845295


https://api.monday.com/v2/file


query: mutation add_file($update_id:Int!, $file: File!) {add_file_to_update(update_id: $update_id, file:$file) {id}}

variables: {“update_id”:1262644561}

map: {“image”:“variables.file”}

image: (image path)


response

{

“error_message”: “Internal server error”,

“status_code”: 500

}


Hey @levank,


I’m sorry to hear you are having issues with this one! I’ve just tried to upload a File to an update using Postman, and that worked without issues for me:



Based on the error, it seems like the image you are sending isn’t being recognized as a file? Could you try using a different file in this case to see if that has any effect? Also, just to make sure, you create an item, then add an update to it via the API, and afterward, send the File to the update? Have you tried using the Files column instead of updates here?


In general, when sending a file, you will need to approach the request as a multipart/form-data request. You will not be able to send the file directly inside the query, and instead, you will need to split up the request in 4 parts if you are using variables:



  • Your query;

  • Your GraphQL variables;

  • An object called “map” that will be used as the reference for variables.file;

  • Then, the actual file.


Does that make a bit more sense?


-Alex


@Helen @AlexSavchuk I fixed this issue. please close the ticket


Thank you for your effort for helping me


@AlexSavchuk Oh sorry, one more question. can we set file description with api? and if it possible to upload file with with description in one req


or can we set “start conversation” with api also


Hi @levank,


Sadly there currently is no ability to set the file description with the API mutations offered.


However, you can definitely create an update using the create_update() method, and then in a separate call, add the file to this newly created update afterwards.


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