Create new item with column values from json data

I’ve been struggling through pulling data from a website and pushing that data into Monday using Python. I have been able to pull the data from a website and convert to json, but I can’t figure out how to insert a Monday column value with the column value of my pulled data. What am I missing?

Hello @katy.mitchell and welcome to the community!

Can you please share here the script you are using and the exact response you are getting from monday’s server?

Please do not include any sensitive information such as your API token.

Looking forward to hearing from you :slightly_smiling_face:

Cheers,
Matias

Thank you @Matias.Monday! Absolutely! I’ve found a few example strings of creating a new item with column values, but I can’t seem to find exactly how to insert a column value from my df rather than a stagnant value.

Example df:
date name ord #
06/01/2023 business1 12345
05/10/2023 business2 67891
04/22/2023 business3 01112

Sample code from the Monday API page: I would want the business name from my df as the item name.

import requests
import json

apiKey = “YOUR_API_KEY_HERE”
apiUrl = “https://api.monday.com/v2
headers = {“Authorization” : apiKey}

query5 = ‘mutation ($myItemName: String!, $columnVals: JSON!) { create_item (board_id:YOUR_BOARD_ID, item_name:$myItemName, column_values:$columnVals) { id } }’
vars = {
‘myItemName’ : ‘Hello everyone!’,
‘columnVals’ : json.dumps({
‘status’ : {‘label’ : ‘Done’},
‘date4’ : {‘date’ : ‘1993-08-27’}
})
}

data = {‘query’ : query5, ‘variables’ : vars}
r = requests.post(url=apiUrl, json=data, headers=headers) # make request
print(r.json())

Hello again,

Thank you for sending that over. I have created an example for you:

Query:

mutation ($myItemName: String!, $columnVals: JSON!) {
  create_item(
    board_id: 1234567890
    item_name: $myItemName
    column_values: $columnVals
  ) {
    id
  }
}

Variables:

{
  "myItemName": "My Name",
  "columnVals": "{\"status\" : \"Done\",\"date4\":\"1993-08-27\"}"
}

I used Postman so that it would show me how that would look like using Python:

import requests
import json

url = "https://api.monday.com/v2"

payload="{\"query\":\"mutation ($myItemName: String!, $columnVals: JSON!) {\\n  create_item(\\n    board_id: 1234567890\\n    item_name: $myItemName\\n    column_values: $columnVals\\n  ) {\\n    id\\n  }\\n}\",\"variables\":{\"myItemName\":\"My Name\",\"columnVals\":\"{\\\"status\\\" : \\\"Done\\\",\\\"date4\\\":\\\"1993-08-27\\\"}\"}}"
headers = {
  'Authorization': 'MYAPIKEYHERE',
  'Content-Type': 'application/json',
}

response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)

I hope that helps!

Cheers,
Matias

Aha! Thank you! I figured out my problem. I was parsing my json data incorrectly. Once I assigned the variables to the json data, I was able to pull them into my mutation. :slight_smile:

1 Like

@matias me again! I’ve finally got my set up pulling my json lists and creating a new item on my Monday board, but I just ran into the issue related to this post: Create Multiple items at once - monday Apps & Developers / Feature Requests - API and Apps Framework - monday Community Forum.

My json list has info to create about 10 items with column values. I’m trying this “create item1” and “create item2” to try and get them to create multiple items using one mutation, but it’s just not working. Here is a snapshot of my python query that will successfully create 1 new item for me:

query2 = ‘mutation ($myItemName: String!, $columnVals: JSON!) { create_item (board_id:XXXXXXX, item_name:$myItemName, column_values:$columnVals) { id } }’
vars = {
‘myItemName’ : f’{address}‘,
‘columnVals’ : json.dumps({
‘text10’ : f’{datech}‘,
‘text’ : f’{builder}‘,
‘text1’ : f’{surface}‘,
‘text7’: f’{newdate}‘,
‘text9’ : f’{oridate}'})}

data = {‘query’ : query2, ‘variables’ : vars}
r = requests.post(url=apiUrl, json=data, headers=headers)
print(r.json())

Hello again @katy.mitchell,

Which error are you getting?

I created another example and used Postman to see how it would look like for Python:

import requests
import json

url = "https://api.monday.com/v2/"

payload="{\"query\":\"mutation ($boardId: Int!, $myItemName: String!, $columnVals: JSON!) {\\n  createItem1: create_item(board_id: $boardId, item_name:$myItemName, column_values: $columnVals) {\\n    id\\n    name\\n  }\\n  createItem2: create_item(board_id: $boardId, item_name:$myItemName, column_values: $columnVals) {\\n    id\\n    name\\n  }\\n}\",\"variables\":{\"myItemName\":\"My Name\",\"boardId\":1234567890,\"columnVals\":\"{\\\"Status\\\" : \\\"Done\\\",\\\"date4\\\":\\\"1993-08-27\\\"}\"}}"
headers = {
  'Content-Type': 'application/json',
  'Authorization': 'MYAPIKEY',
}

response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)

Does this help?

If not, please let me know what error message you see from monday’s server so we can take a look!

Cheers,
Matias

1 Like