Mutating a Date in v2

Please forgive the stupidity - I feel like I’m missing something extremely simple here.

Running queries in Postman as a precursor to running them from Google Apps Script and I can’t wrap my brain around what appears to be a syntax issue. Here’s the script:

{“query”:“mutation{change_column_value(board_id:XXXXXXXXX,item_id:XXXXXXXXX,column_id:"dateXXX",value:"{"date":"2020-01-09","time":"00:00:00"}"){id}}”}

Error message is as follows:
“Parse error on ":" (STRING) at [1, 98]”

Figured out the retrieving and parsing of data and can do “simple” mutations like number and text, no problem, but WOW these date columns are killing me. TIA.

I don’t know the exact issue. But I think the basic issue is that you need to include the proper escaping. The value portion should look something like this:

"{\"date\":\"2019-06-03\",\"time\":\"13:25:00\"}"

Using the documentation arguments returns “400 Bad Request” or a different parse error. I know it’s the syntax because I can make the dratted thing work in GraphQL, just not JSON. Not good at this nested objects thing.

1 Like

When you put 4 spaces before the text you post here it won’t remove the escape characters.

Can to post a mutation line that works and the one that doesn’t?

Hey there @MelissaH :wave:

I am sorry to hear that getting this to work has been somewhat arduous for you! That said, I do have to agree with @JCorrell’s insight here - it seems to be a syntax/formatting issue in this case.

Just to clarify a bit further, when you send your queries or mutations to our API, they always have to target our API URL (api.monday.com/v2) and you have to send your request as a POST request, formatted as JSON. Your mutation values also have to be formatted as JSON properly, which seems to be what is causing the issue here.

I think in your latest example, the 400 error is caused by not sending the request to the proper URL, it not being a POST request, or not being formatted as JSON. Those could also be related to network issues as well.

Let me know if this helps!

-Alex

FINALLY RESOLVED.

I was…not using enough quotation marks??? See below in case this ever comes up for someone else. I switched to a checkbox column for readability, since the problem for me was 1000% the nesting of objects, but presumably this would work for status, date, and other columns that require an object, not just a single value like numbers and text.

Google Apps Script code:

var test = JSON.stringify("{\"checked\": \"true\"}");

var mutation = JSON.stringify({'query' : 'mutation{change_column_value(board_id: XXXXXXXXX,item_id:XXXXXXXXX,column_id: "check9",value:'+test+'){id}}'});

Stackdriver log shows this result:

Aug 30, 2020, 10:24:28 AM	Info	{"query":"mutation{change_column_value(board_id: XXXXXXXXX,item_id:XXXXXXXXX,column_id: \"check9\",value:\"{\\\"checked\\\": \\\"true\\\"}\"){id}}"}

Aug 30, 2020, 10:24:29 AM	Info	Mutation response: {"data":{"change_column_value":{"id":"XXXXXXXXX"}},"account_id":XXXXXXX}

Previous attempts failed because I was doing the following:

var test = JSON.stringify({"checked": "true"});

Which fails to put quotation marks outside the curly braces and leads to a parse error.

:exclamation: :exclamation: :exclamation:EDIT: For anyone else reading this, if you are trying to mutate multiple columns and not just one - use the third code block, not the first, to set your “var test.” The extra quotation marks work on single column mutation objects, but not multi-column mutations. Devs, y’all might want to make note of this, because it took me some brute force to figure this out. The documentation for this part of the API may require another pass. It’s also odd that one mutation requires you to pass the object as a string, but the other one accepts nested objects…maybe I’m just looking at it wrong.

Thanks again for the help. I imagine this is extremely basic, but it was definitely a learning experience for me :grin:

1 Like

@MelissaH

That’s awesome, I’m glad to hear you’ve been able to find a solution to your issue here, and more importantly, that you’ve also shared what has been causing the issue. This will definitely help pave the way to a smooth experience for other users with a similar situation and I appreciate you making that journey to a successful integration easier :slight_smile:

-Alex

1 Like

Of course! So since single column mutation was a stepping stone to multi-column mutations, I did add my thoughts on that to the above.

Oh, the irony - if I had skipped what I thought was the simpler iteration and gone straight to the complex one, we could’ve saved approximately three days of hair-pulling.

Y’all might want to have another look at the differences in syntax between the two queries as well, because the extra “stuff an object in a string” step for the single-column query is not represented in GraphQL and is very hard to grok if you’re just looking at the documentation.

Thanks again - Mel signing off :slight_smile:

2 Likes