How do I create a new item via the API with the Assigned To field set to a specific user?

I’m trying to use the Monday.com API to create a new item with the Assigned To field prepopulated with a specific user.

I can currently create new items via the API without the Assigned To field set but with other fields set with the following type of query:

mutation {
    create_item (
        board_id: xxxxxxxxx,
        group_id: "some-group-id",
        item_name: "Testing",
        column_values: "{\"text0\":\"Some text\",\"text1\":\"Some other text\"}"
    ) {
        id
    }
}

The problem I think I’m having is that the column_values value is already an escaped JSON string, and within that, I’d have to add another (escaped?) JSON string for the Assigned To field.

At this point, I’ve tried every combination I can think of, but nothing seems to work. Here’s an example of what I’ve tried:

mutation {
    create_item (
        board_id: xxxxxxxxx,
        group_id: "some-group-id",
        item_name: "Testing",
        column_values: "{\"text0\":\"Some text\",\"text1\":\"Some other text\",\"people\":\"{\\\"personsAndTeams\\\":[{\\\"id\\\":xxxxxxxx,\\\"kind\\\":\\\"person\\\"}]}\"}"
    ) {
        id
    }
}

That does not work though.

If it matters, I’m currently just testing this with Postman and trying to send the data with a GraphQL body set like the above examples, and while the first example without the Assigned To field set works and correctly creates a new item, the second one doesn’t.

What am I missing / doing wrong? Thank you.

After much trial and error, I finally gave up on trying to do what I was doing, and I ended up doing the create_item call without adding the Assigned To field bit, and once that was done, I took the returned ID of the new item and made a second API call with the change_column_value to update the existing item. That seemed to work.

1 Like

I had similar issues and got my code to work eventually. lessons i learned was to not expect the API to be handling data properly :slight_smile: you’re probably on the right track with escaping. try different combinations in the playground if you’re not already, cause you will get more verbose errors then running node inspector, if you’re using js on the server.

One way I’ve personally tackled this before is (depending where you are running this code) is to use things like the JSON encode library in Python. This will make it so you can use variables and not need to worry about escaping :slight_smile:

-Daniel

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