Problem formatting my query

doing lots of other queries, but i’m having trouble formatting a change_multiple_column_values query.

posting this json:

{“query”:“mutation { change_multiple_column_values ( board_id: 655318672, item_id: 662694544, column_values: \”{\“date4\”: {\“date\”: \“2020-08-04\”},\“next_arr__days_7\”: \“9\”,\“property_id\”: \“1289\”,\“person\”: {\“id\”: null},\“numbers2\”: \“1.50\”,\“departing_rez\”: \“5146\”,\“status\”: {\“index\”: 1}}\") { id } }"}

returns:

[errors] => Array
(
[0] => stdClass Object
(
[message] => Parse error on “: {” (STRING) at [9, 28]
[locations] => Array
(
[0] => stdClass Object
(
[line] => 9
[column] => 28
)
)
)
)

putting the mutation text above on try it yourself doesn’t work UNLESS i remove the \ from the \" at the beginning and end of the column_values. so this does not work:

mutation { change_multiple_column_values ( board_id: 655318672, item_id: 662694544, column_values: \"{\“date4\”: {\“date\”: \“2020-08-04\”},\“next_arr__days_7\”: \“9\”,\“property_id\”: \“1289\”,\“person\”: {\“id\”: null},\“numbers2\”: \“1.50\”,\“departing_rez\”: \“5146\”,\“status\”: {\“index\”: 1}}\") { id } }

returns Parse error on “\\” (error) at [1, 121]

but this does:

Preformatted text

mutation { change_multiple_column_values ( board_id: 655318672, item_id: 662694544, column_values: “{\“date4\”: {\“date\”: \“2020-08-04\”},\“next_arr__days_7\”: \“9\”,\“property_id\”: \“1289\”,\“person\”: {\“id\”: null},\“numbers2\”: \“1.50\”,\“departing_rez\”: \“5146\”,\“status\”: {\“index\”: 1}}”) { id } }

but changing the \"'s to " on the post doesn’t work either. doesn’t return anything (gets an http code 400.) so i can make it work on try it yourself, but not in my code (php cURL)

i must be missing something simple…

HI there @barrycox :wave:

I’m sorry to hear you are having some trouble set this up correctly, but it does seem like we’re almost there from where I stand :slight_smile: Since you are able to get the try-it-yourself result to work, I would say your JSON formatting is on point in this query:

mutation { change_multiple_column_values ( board_id: 655318672, item_id: 662694544, column_values: “{\“date4\”: {\“date\”: \“2020-08-04\”},\“next_arr__days_7\”: \“9\”,\“property_id\”: \“1289\”,\“person\”: {\“id\”: null},\“numbers2\”: \“1.50\”,\“departing_rez\”: \“5146\”,\“status\”: {\“index\”: 1}}”) { id } }

One thing that I’ve noticed in the very first query that you are trying to send is that the whole query is formatted as JSON, whereas I believe only the column values you are trying to send should be formatted as such. Does that make sense?

EDIT: Turns out I was not entirely correct about this, since the whole request body is JSON.

@dipro has helped me out here and his insight is that the quotes inside quotes should be double-escaped:
{“query”:"mutation { change_multiple_column_values ( board_id: 655318672, item_id: 662694544, column_values: "{\“date4\”: {\“date\”: …

To save some hassle, we recommend using GraphQL variables to handle this. That way, you’ll be able to send the column values as JSON and the app will do the escaping for you. There is more information on this topic in our tutorials as well:

Also, here is a helpful post that might help:
cURL examples for API v2

-Alex

thanks. i like the variables approach. i think i am close but i’m getting a 500 internal server error but no other clue.

here’s what i am posting:
{“query”:“mutation ($columnVals: JSON!) { change_multiple_column_values ( board_id: 677637367, item_id: 678046909, column_values:$columnVals) { id } }”,“variables”:{“columnVals”:{“cleaning_date”:{“date”:“2020-08-12”},“departure_date”:{“date”:“2020-08-12”},“next_arr__days_”:null,“text3”:“1321”,“numbers7”:“0.00”,“text”:“5030”,“status”:{“index”:1}}}}

if i change columnVals anywhere to ‘fubar’ i get error Variable $columnVals is declared by but not used, so i think i’m getting through with proper formatting.

i looked at each column name in detail to make sure they’re correct. i also tried with just “text3”:“1321” and get a 500. same result on api workbench.

i thought perhaps a scopes issue, so checked off all scopes for testing. i can create items and groups… just not change_multiple_column_values.

ideas for troubleshooting a 500?

1 Like

May be this would help in formatting query if you are in javascript land (stringify twice):

let boardId = 655318672;
let itemId = 662694544;

let model = {
  date4: {
    date: '2020-08-04',  
  },
  next_arr__days_7: 9,
  property_id: 1289,
  person: {
    id: null
  },
  numbers2: 1.50,
  departing_rez: 5146,
  status: {
    index: 1
  }
}

let query = `
  mutation {
    change_multiple_column_values 
      (board_id: ${boardId}, 
       item_id: ${itemId},
       column_values: ${JSON.stringify(JSON.stringify(model))})
  }`;

console.log(query);

In chrome inspector it would be as follows

Hey again @barrycox,

To be transparent with you, the 500 Server Error is most often related to the formatting of the API call you are sending. To me, it seems like your status label index might need to be escaped properly. You will always need to send all of the data you are trying to mutate within the Platform formatted as a JSON string with proper escaping as well. To me personally, the Date and Status column JSON formatting was always the most tricky somehow, so I’d recommend taking this 1 step at a time before so that you can make sure parts of your query are correct, and then build on top of that.

What do you think? Let me know.

@stackpond thanks so much for the helpful suggestion! :slight_smile: I appreciate your help here.

-Alex

i agree. that’s why i sent this screenshot of a very very simplified version which doesn’t work on the try-it-yourself.

if it’s a syntax error, can you point it out?

i tried variables as {“columnVals”:{“text3”:“1321”}} and {“columnVals”:{“text3”:1321}}.

@stackpond, thanks for the response. i’m coding in php sending curls, but can’t get it to work on the try-in-yourself board either…

@barrycox sorry for the delay in my response on this!

How about using something like the below on the try-it-yourself page?

mutation {
change_column_value (board_id:yourboardid, item_id:youritemid, column_id:“yourcolumnid”, value: “{“personsAndTeams”:[{“id”:userid,“kind”:“person”}]}”)
{id}}

This should be a working query to assign a person to an item within a board:

It seems like in the query you are attempting to send, there is no column ID for the platform to store the data in, so that might be one of the reasons you are getting a 500 in that case. What do you think?

Let me know :slight_smile:

-Alex