Rating column from PHP to API Monday : Can't reach to create an item with value into rating column

While creating a Monday API to connect our server to Monday board,
I want to create an item with values for each colums.
Problem : it works for every colum except for the rating one. I 've tried many syntax but no one works.
The official doc at Rating doesn’t help.
Does anybody know how to do it ?
Here is the code :

$column_values = [
    'name' => 'xxxxxxxxxx',
    'person' => '20985745',
    'status' => '14',
//    'classement' => '5',
//    'classement' => '5/5',
//    'classement' => "{\"rating\":1}",
//    'classement' => "{\"rating\":1\"}",
//    'classement' => "{rating:1}",
//    'classement' => rating:1',
//    'classement' => {'rating:1'},
//    'classement' => "{\"rating:1\"}",
//    'classement' => 'rating 1',
    'classement' => 'rating\:1',
    'date' => '2021-09-01 16:30:00',
    'texte' => 'Bonjour',
    'statut_1' => '1',
    'personnes' => '20791487',
    'lien_internet' => 'http://google.fr salut' 
 ];

Rating takes an object with a key string and a value string
Try this.

'classement' => {\"rating\" : \"1\"}

The rating object needs a number, not a string. So, I guess

'classement' => {\"rating\" : 1}

should do the job.

Hello kolaai, " 'classement' => '{\"rating\" : \"1\"}', doesn’t work…

Sorry, I was quoting from the documentation example

Hi @basdebruin , I tried your suggestion such as :

    'classement' => '{\"rating\" : 1}',

and even

    'classement' => {\"rating\" : 1},

and it doesn’t work either.

Thanks for trying to help…

1 Like

This one works in my API playground. I propose you test it from there and make the necessary adjustments

mutation {change_column_value (item_id: 1111111111, board_id: 222222222, column_id: "rating", value: "{\"rating\": 2}") {id}}

When you want to combine with create_item this one works in the API playground

mutation { create_item (item_name: "New item", board_id: 22222222, column_values: "{\"rating\": {\"rating\": 2}}") {id}}

Hi @big.th and everyone on this thread,

Thank you @kolaai and @basdebruin for your help here!

I believe the issue is as Bas stated, you need two rating keys in the column value that you’re sending. One is the column ID rating and the other is the key for the JSON you’re sending.

I see that there is a mistake in our documentation and the value should be an Int, not a String. Going to fix it now.

Let us know if this still does not work for you!

Thanks @basdebruin, indeed it works in graphQL but still not from my PHP function. I keep working on it…

@big.th

I’m glad to hear @basdebruin’s suggestion was a step in the right direction, at least for the GraphQL playground! If you’d like, you can share your Python code with us here as well, and we could try tinkering and fine-tuning it to a working state from there.

Here’s what Postman outputs for a Python - Requests code snippet:

import requests
import json

url = "https://api.monday.com/v2"
payload = json.dumps({
  "query": "mutation { create_item (item_name: \"New item\", board_id: boardId, column_values: \" {\\\"rating\\\": {\\\"rating\\\": 2}} \") {id}}"
})
headers = {
  'Authorization': 'yourApiKey',
  'Content-Type': 'application/json',
}
response = requests.request("POST", url, headers=headers, data=payload)
print(response.text)

Finally, I’ve just found !!! I post it here so it can help…

 $array = [
     'classement' => [ "rating" => 1 ],
 ];
2 Likes

@big.th

Amazing, i’m glad you were able to sort this out :slight_smile:

Hope your development is a smooth sail from here on out. :motor_boat:

-Alex

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