I’m a contractor trying to fix a breaking issue in a company’s tool. The original developer is no longer with the company and I’m trying my best to fix their issue that seems to be in pipedream. I think that something is wrong with the mutation code but I can’t figure out what’s wrong with the error message I’m getting.
The code:
// To use previous step data, pass the `steps` object to the run() function
import { axios } from "@pipedream/platform"
export default defineComponent({
props: {
monday: {
type: "app",
app: "monday",
},
},
async run({ steps, $ }) {
// Use the correct trigger step name (e.g. "trigger") instead of "trigger"
// throughout the code
const payType = steps.trigger.event.body.event.columnValues.status5.label.text
const projectName = steps.trigger.event.body.event.columnValues.project_name.value
const nameOfResource = steps.trigger.event.body.event.columnValues.text7.value
const projectNumber = steps.trigger.event.body.event.columnValues.text4.value
const date = steps.trigger.event.body.event.columnValues.date.date
const time = steps.trigger.event.body.event.columnValues.date.time
const nameProjectNumber = `${nameOfResource} - ${projectNumber}`
console.log({nameProjectNumber});
let itemExists;
const finditem = await axios($, {
url: `https://api.monday.com/v2`,
method: `POST`,
headers: {
'Content-Type': 'application/json',
'Authorization': `${this.monday.$auth.api_key}`,
'API-Version': '2023-10'
},
data: {
"query": `query {boards(ids: [4929395518]) {items_page(query_params: {rules: [{column_id: "name", compare_value: ["${nameProjectNumber}"]}]}) {items {group {title id}id name column_values {id text value}}}}}` }
})
console.log('line 65 finditem', finditem.data.boards[0].items_page)
const itemfound = finditem.data.boards[0].items_page.items[0]
console.log(itemfound)
// Find Group
let groupName
if (itemfound) {
console.log('item found')
groupName = itemfound.group.title
console.log(groupName)
}
function isSingleDigit(number) {
if (number >= 0 && number <= 9) {
return `0${number}`
}
return number
}
const mondayAPI = async (query, variables) => {
if (variables != null) {
return await axios($, {
url: `https://api.monday.com/v2`,
method: `post`,
headers: {
'Content-Type': 'application/json',
'Authorization': `${this.monday.$auth.api_key}`,
},
data: JSON.stringify({
query: query,
variables: variables
})
})
}
return await axios($, {
url: `https://api.monday.com/v2`,
method: `post`,
headers: {
'Content-Type': 'application/json',
'Authorization': `${this.monday.$auth.api_key}`,
},
data: {
"query": query
}
})
}
const newDate = `${date}T${time}`
console.log(newDate)
console.log(date)
const newDateObject = new Date(newDate)
const convertedDateObject = newDateObject
console.log(convertedDateObject)
const convertedDateObjectHours = convertedDateObject.getUTCHours()
const convertedDateObjectMinutes = convertedDateObject.getUTCMinutes()
const convertedDateObjectMonth = convertedDateObject.getUTCMonth() + 1
const convertedDateObjectDay = convertedDateObject.getUTCDate()
const convertedDateObjectYear = convertedDateObject.getUTCFullYear()
const finalStartDate = `${convertedDateObjectYear}-${isSingleDigit(
convertedDateObjectMonth
)}-${isSingleDigit(convertedDateObjectDay)} ${isSingleDigit(
convertedDateObjectHours
)}:${isSingleDigit(convertedDateObjectMinutes)}:00`
const bookingId = steps.trigger.event.body.event.pulseId
const bookedHours = steps.trigger.event.body.event.columnValues.numbers.value
const classNumber = steps.trigger.event.body.event.columnValues.class_.value
const hrMap = {
100: 31916830,
120: 31916830,
130: 31916830,
190: 31916830,
210: 32172430,
215: 32172430,
220: 32172430,
225: 32172430,
230: 32172430,
235: 32172430,
240: 32172430,
245: 32172430,
255: 32172430,
265: 32172430,
275: 32172430,
450: 32172430,
475: 32172430,
480: 32172430,
490: 32172430,
510: 32172430,
600: 31918535,
685: 31918535,
690: 31918535,
785: 31918535,
790: 31918535,
885: 31918535,
890: 31918535,
900: 31916830,
}
const hrAssignment = hrMap[parseInt(classNumber)]
const queryForUsers = `mutation {
create_item(
board_id: 4929395518,
item_name: "${nameProjectNumber}",
column_values: "{\"text__1\": \"${projectName}\", \"connect_boards\": {\"item_ids\": [${bookingId}]}, \"numbers\": \"${bookedHours}\", \"date\": \"${finalStartDate}\", \"class4\": \"${classNumber}\", \"people\": \"${hrAssignment}\", \"ba_status\": \"Pending\" }",
create_labels_if_missing: true
) {
id
}
}`
console.log(queryForUsers)
if (itemfound != null) {
// If project number == 'TBD', create a new row or update existing
if (projectNumber === 'TBD') {
let value
const itemFoundProjectName = itemfound.column_values.find(x => x.id === 'text__1').text
console.log(itemFoundProjectName)
console.log(projectName)
if (itemFoundProjectName === projectName) {
console.log('existing TBD Entry group')
const existingEntry = itemfound
const oldHourState = existingEntry.column_values.find(
(x) => x.id === "numbers"
).value
const linkedPulsIDState = JSON.parse(
existingEntry.column_values.find(
(x) => x.id === "connect_boards"
).value
)
console.log(itemfound)
console.log(linkedPulsIDState)
console.log('here')
console.log(itemfound)
console.log(existingEntry)
console.log(linkedPulsIDState)
const newHourState = parseInt(JSON.parse(oldHourState)) + bookedHours
const newLinkedPulseIDState = []
if (Object.keys(linkedPulsIDState).length !== 0) {
for (let item of linkedPulsIDState.linkedPulseIds) {
if ("linkedPulseId" in item) {
newLinkedPulseIDState.push(item.linkedPulseId)
}
}
}
newLinkedPulseIDState.push(bookingId)
console.log(newLinkedPulseIDState)
// change existing booking agreement
const changeMultipleColumnsQuery = `mutation {
complexity {
before
after
}
change_multiple_column_values (
item_id: ${existingEntry.id},
board_id: 4929395518,
column_values: "{\"numbers\": ${JSON.stringify(newHourState)}, \"connect_boards\": {\"item_ids\": ${JSON.stringify(newLinkedPulseIDState)}}}"
) {
id
}
}`
const value = await mondayAPI(changeMultipleColumnsQuery)
console.log('processed query')
console.log(value)
} else {
console.log('new entry')
value = await mondayAPI(queryForUsers)
console.log(value)
const addBookingAgreementQuery = `mutation {
complexity {
before
after
}
change_multiple_column_values (
item_id: ${steps.trigger.event.body.event.pulseId},
board_id: 4499094121,
column_values: "{\"text76\" : \"${value.data.create_item.id.toString()}\"}"
) {
id
}
}`
console.log(addBookingAgreementQuery)
const addBookingIDToResourceBooking = await mondayAPI(addBookingAgreementQuery)
console.log(addBookingIDToResourceBooking)
}
return
}
// If item is in the "Completed" group, make a new entry
if (groupName === 'Completed') {
console.log('new entry')
const value = await mondayAPI(queryForUsers)
console.log(value)
const addBookingAgreementQuery = `mutation {
complexity {
before
after
}
change_multiple_column_values (
item_id: ${steps.trigger.event.body.event.pulseId},
board_id: 4499094121,
column_values: "{\"text76\" : \"${value.data.create_item.id.toString()}\"}"
) {
id
}
}`
console.log(addBookingAgreementQuery)
const addBookingIDToResourceBooking = await mondayAPI(addBookingAgreementQuery)
console.log(addBookingIDToResourceBooking)
return
}
// Otherwise, update existing booking
const existingEntry = itemfound
const oldHourState = existingEntry.column_values.find(
(x) => x.id === "numbers"
).value
const linkedPulsIDState = JSON.parse(
existingEntry.column_values.find(
(x) => x.id === "connect_boards"
).value
)
console.log(itemfound)
console.log(linkedPulsIDState)
console.log('here')
console.log(itemfound)
console.log(existingEntry)
console.log(linkedPulsIDState)
const newHourState = parseInt(JSON.parse(oldHourState)) + bookedHours
const newLinkedPulseIDState = []
if (Object.keys(linkedPulsIDState).length !== 0) {
for (let item of linkedPulsIDState.linkedPulseIds) {
if ("linkedPulseId" in item) {
newLinkedPulseIDState.push(item.linkedPulseId)
}
}
}
newLinkedPulseIDState.push(bookingId)
console.log(newLinkedPulseIDState)
// change existing booking agreement
const changeMultipleColumnsQuery = `mutation {
complexity {
before
after
}
change_multiple_column_values (
item_id: ${existingEntry.id},
board_id: 4929395518,
column_values: "{\"numbers\": ${JSON.stringify(newHourState)}, \"connect_boards\": {\"item_ids\": ${JSON.stringify(newLinkedPulseIDState)}}}"
) {
id
}
}`
const value = await mondayAPI(changeMultipleColumnsQuery)
console.log('processed query')
console.log(value)
const addBookingAgreementQuery = `mutation {
complexity {
before
after
}
change_multiple_column_values (
item_id: ${steps.trigger.event.body.event.pulseId},
board_id: 4499094121,
column_values: "{\"text76\" : \"${value.data.change_multiple_column_values.id.toString()}\"}"
) {
id
}
}`
console.log(addBookingAgreementQuery)
const addBookingIDToResourceBooking = await mondayAPI(addBookingAgreementQuery)
console.log(addBookingIDToResourceBooking)
} else {
// If no existing item found, create a new booking
console.log('new Booking')
const value = await mondayAPI(queryForUsers)
console.log(value)
console.log(value.data.create_item.id)
const addBookingAgreementQuery = `mutation {
complexity {
before
after
}
change_multiple_column_values (
item_id: ${steps.trigger.event.body.event.pulseId},
board_id: 4499094121,
column_values: "{\"text76\" : \"${value.data.create_item.id.toString()}\"}"
) {
id
}
}`
console.log(addBookingAgreementQuery)
const addBookingIDToResourceBooking = await mondayAPI(addBookingAgreementQuery)
console.log(addBookingIDToResourceBooking)
}
// Return the trigger data (rename if your step is different)
return steps.trigger.event
},
})
The error that I’m experiencing:
AxiosError - Request failed with status code 400
{"errors":[{"message":"parsing error: syntax error: expected R_PAREN, got \": \"","locations":[{"line":5,"column":34}],"extensions":{"code":"PARSING_ERROR"}},{"message":"parsing error: syntax error: expected R_CURLY, got \": \"","locations":[{"line":5,"column":34}],"extensions":{"code":"PARSING_ERROR"}},{"message":"parsing error: syntax error: expected definition","locations":[{"line":5,"column":34}],"extensions":{"code":"PARSING_ERROR"}},{"message":"parsing error: syntax error: expected definition","locations":[{"line":5,"column":38}],"extensions":{"code":"PARSING_ERROR"}},{"message":"parsing error: syntax error: expected definition","locations":[{"line":5,"column":50}],"extensions":{"code":"PARSING_ERROR"}},{"message":"parsing error: syntax error: expected definition","locations":[{"line":5,"column":54}],"extensions":{"code":"PARSING_ERROR"}},{"message":"parsing error: syntax error: expected definition","locations":[{"line":5,"column":68}],"extensions":{"code":"PARSING_ERROR"}},{"message":"parsing error: syntax error: expected definition","locations":[{"line":5,"column":73}],"extensions":{"code":"PARSING_ERROR"}},{"message":"parsing error: syntax error: expected definition","locations":[{"line":5,"column":81}],"extensions":{"code":"PARSING_ERROR"}},{"message":"parsing error: syntax error: expected definition","locations":[{"line":5,"column":100}],"extensions":{"code":"PARSING_ERROR"}},{"message":"parsing error: syntax error: expected definition","locations":[{"line":5,"column":107}],"extensions":{"code":"PARSING_ERROR"}},{"message":"parsing error: syntax error: expected a StringValue, Name or OperationDefinition","locations":[{"line":5,"column":111}],"extensions":{"code":"PARSING_ERROR"}},{"message":"parsing error: syntax error: expected definition","locations":[{"line":5,"column":112}],"extensions":{"code":"PARSING_ERROR"}},{"message":"parsing error: syntax error: expected definition","locations":[{"line":5,"column":116}],"extensions":{"code":"PARSING_ERROR"}},{"message":"parsing error: syntax error: expected definition","locations":[{"line":5,"column":120}],"extensions":{"code":"PARSING_ERROR"}},{"message":"parsing error: syntax error: expected a StringValue, Name or OperationDefinition","locations":[{"line":5,"column":124}],"extensions":{"code":"PARSING_ERROR"}},{"message":"parsing error: syntax error: Numbers must not have non-significant leading zeroes","locations":[{"line":5,"column":128}],"extensions":{"code":"PARSING_ERROR"}},{"message":"parsing error: syntax error: Numbers must not have non-significant leading zeroes","locations":[{"line":5,"column":131}],"extensions":{"code":"PARSING_ERROR"}},{"message":"parsing error: syntax error: expected a StringValue, Name or OperationDefinition","locations":[{"line":5,"column":135}],"extensions":{"code":"PARSING_ERROR"}},{"message":"parsing error: syntax error: expected a StringValue, Name or OperationDefinition","locations":[{"line":5,"column":137}],"extensions":{"code":"PARSING_ERROR"}},{"message":"parsing error: syntax error: Numbers must not have non-significant leading zeroes","locations":[{"line":5,"column":138}],"extensions":{"code":"PARSING_ERROR"}},{"message":"parsing error: syntax error: expected a StringValue, Name or OperationDefinition","locations":[{"line":5,"column":140}],"extensions":{"code":"PARSING_ERROR"}},{"message":"parsing error: syntax error: Numbers must not have non-significant leading zeroes","locations":[{"line":5,"column":141}],"extensions":{"code":"PARSING_ERROR"}},{"message":"parsing error: syntax error: expected definition","locations":[{"line":5,"column":143}],"extensions":{"code":"PARSING_ERROR"}},{"message":"parsing error: syntax error: expected definition","locations":[{"line":5,"column":147}],"extensions":{"code":"PARSING_ERROR"}},{"message":"parsing error: syntax error: expected definition","locations":[{"line":5,"column":153}],"extensions":{"code":"PARSING_ERROR"}},{"message":"parsing error: syntax error: expected a StringValue, Name or OperationDefinition","locations":[{"line":5,"column":157}],"extensions":{"code":"PARSING_ERROR"}},{"message":"parsing error: syntax error: expected definition","locations":[{"line":5,"column":160}],"extensions":{"code":"PARSING_ERROR"}},{"message":"parsing error: syntax error: expected definition","locations":[{"line":5,"column":164}],"extensions":{"code":"PARSING_ERROR"}},{"message":"parsing error: syntax error: expected definition","locations":[{"line":5,"column":170}],"extensions":{"code":"PARSING_ERROR"}},{"message":"parsing error: syntax error: expected a StringValue, Name or OperationDefinition","locations":[{"line":5,"column":174}],"extensions":{"code":"PARSING_ERROR"}},{"message":"parsing error: syntax error: expected definition","locations":[{"line":5,"column":182}],"extensions":{"code":"PARSING_ERROR"}},{"message":"parsing error: syntax error: expected definition","locations":[{"line":5,"column":186}],"extensions":{"code":"PARSING_ERROR"}},{"message":"parsing error: syntax error: expected definition","locations":[{"line":5,"column":195}],"extensions":{"code":"PARSING_ERROR"}},{"message":"parsing error: syntax error: expected definition","locations":[{"line":5,"column":199}],"extensions":{"code":"PARSING_ERROR"}},{"message":"parsing error: syntax error: expected definition","locations":[{"line":5,"column":206}],"extensions":{"code":"PARSING_ERROR"}},{"message":"parsing error: syntax error: expected definition","locations":[{"line":6,"column":9}],"extensions":{"code":"PARSING_ERROR"}},{"message":"parsing error: syntax error: expected a StringValue, Name or OperationDefinition","locations":[{"line":6,"column":33}],"extensions":{"code":"PARSING_ERROR"}},{"message":"parsing error: syntax error: expected definition","locations":[{"line":6,"column":35}],"extensions":{"code":"PARSING_ERROR"}},{"message":"parsing error: syntax error: expected a StringValue, Name or OperationDefinition","locations":[{"line":7,"column":7}],"extensions":{"code":"PARSING_ERROR"}},{"message":"parsing error: syntax error: expected a StringValue, Name or OperationDefinition","locations":[{"line":10,"column":5}],"extensions":{"code":"PARSING_ERROR"}}],"account_id":11622012}