Mutation giving error

I am trying to build a Power BI Report that can modify information on Monday.com.

The below query works to get information from a board:
“{”“query”": ““query { boards(ids: ####) {activity_logs(limit: 1000) {event, entity, data, created_at, user_id, id}, name, id} }””}"

The below mutation is giving me an error message:
"{“query”: ""mutation change_simple_column_value (board_id: ####, item_id: ####, column_id: ““column””, value: ““1"”) {} “”}”

Error Message:

DataSource.Error: Web.Contents failed to get contents from ‘https://api.monday.com/v2’ (400): Bad Request
Details:
DataSourceKind=Web
DataSourcePath=https://api.monday.com/v2
Url=https://api.monday.com/v2

Any tips are appreciated. I am an absolute beginner when it comes to GraphQL.

Hey-ho @mark.mccoy :wave:

Glad to hear that querying is working well for you! That’s aweosme.

I’d love to clarify the kind of value you are attempting to change - is it a number column value within a board? Have you tested this mutation in the API Playground?

Having a little more context to what you are hoping to accomplish would be awesome right off the bat!

Here’s how a mutation looks like in Postman when sending an HTTP request to adjust Numebrs column value:

Perhaps the following API Mutation might help reformat your Power BI request too:

{"query" :"mutation{ change_simple_column_value (board_id:1045147004, item_id:1045147008, column_id:\"numbers\", value:\"3\") {id name}}"}

I hope this helps :slight_smile:

-Alex

Thanks for the reply Alex.

I am trying to add a text value to a column based off information in a Power BI report.

The below query works for me in the API playground:

mutation { change_simple_column_value(board_id: 929960697, item_id: 1006655013, column_id: “text3”, value: “New Value”) {id, name}}

Below is the entire Power Query M code. This file returns the error message in my original post.

Web.Contents(
https://api.monday.com/v2”,

[
Headers=[
#“Method”=“GET”,
#“Content-Type”=“application/json”,
#“Authorization”=“Bearer " & Key
],
Content = Text.ToBinary(”{"“query”": ““mutation { change_simple_column_value(board_id: 929960697, item_id: 1006655013, column_id: ““text3"”, value: “new value””) {id, name}}””}")
]
)

Hi @mark.mccoy!

Hmm I would try changing the method to POST (all calls to our API will require the POST method) just right off the bat.

Additionally, a 400 error indicates bad syntax. Is there a reason why you use two pairs of double quotes in your query string?

-Helen

Hi @Helen,

Thanks for the reply. I updated the Method to Post. Double quotes in M language is how strings are escaped.

Web.Contents(
"https://api.monday.com/v2",
[
Headers=[
#"Method"="POST",
#"Content-Type"="application/json",
#"Authorization"="Bearer " & Key
],
Content = Text.ToBinary("{""query"": ""mutation { change_simple_column_value(board_id: 929960697, item_id: 1006655013, column_id: ""text3"", value: ""new value"") {id, name}}""}")
]
)

The above code gives me the below error message.

DataSource.Error: Web.Contents failed to get contents from 'https://api.monday.com/v2' (400): Bad Request Details:
DataSourceKind=Web
DataSourcePath=https://api.monday.com/v2
Url=https://api.monday.com/v2

My first thought is that it is not parsing the strings properly.

Hi @mark.mccoy,

I agree-- I think that might be the case as well!

Do you mind trying to replicate this query in your Developer’s Playground in your monday.com account to see if it’s working there? Maybe the answer is a lot more simple than we think.

-Helen

Hi @Helen,

mutation { change_simple_column_value(board_id: 929960697, item_id: 1006655013, column_id: “text3”, value: “new value”) {id, name}}

The above query returns the expected result below.

{
“data”: {
“change_simple_column_value”: {
“id”: “1006655013”,
“name”: “This is a new item”
}
},
“account_id”: 1292737
}

Hi Mark,

Okay that’s good! It sounds like the issue here may just be related to the M language. I’m honestly not familiar with this language, so I’m not sure what the formatting should be.

However, if I were you, I would probably try the query in single quotes, and see if that throws an error for me.

Out of curiosity, why are you using Text.ToBinary() before the query? Is this necessary for M?

Thanks!
Helen

Not sure if you’ve been able to solve this one yet @mark.mccoy!

After some additional investigation, it looks like maybe the reason Power BI won’t work with monday.com is because it seems to only work with RESTful APIs, and monday.com’s is GraphQL?

Thanks for the reply @Helen.

This project got pushed to back burner last week, apologies for not responding sooner.

The code cannot run with single quotes due to the way strings are escaped in Power Query. Text.ToBinary() is being used because content requires binary input.
Neither of these should be causing an error because they are both present in the code I provided that works.

My understanding is that GraphQL is simply a HTTP Post request. I am able to query Monday’s API and get the needed data. I ran into an issue when trying to change data.

The below returns the intended data:

Web.Contents(
https://api.monday.com/v2”,
[
Headers=[
Method=“POST”,
#“Content-Type”=“application/json”,
#“Authorization”=“Bearer " & Key
],
Content=Text.ToBinary(”{"“query”": ““query { boards(ids: 929960697) {activity_logs(limit: 1000) {event, entity, data, created_at, user_id, id}, name, id} }””}" )
]
)

The graphQL bit is:

{“query”: “query { boards(ids: 929960697) {activity_logs(limit: 1000) {event, entity, data, created_at, user_id, id}, name, id} }”}

The below is calling the API for a mutation.

Web.Contents(
https://api.monday.com/v2”,
[
Headers=[
Method=“POST”,
#“Content-Type”=“application/json”,
#“Authorization”=“Bearer " & Key
],
//GraphQL Query
Content=Text.ToBinary(”{"“query”": "“mutation { change_simple_column_value(board_id: 929960697, item_id: 1006655013, column_id: “& ColumnID &”, value: “& value &”) {id, name}} “”}” )
]
)

The GraphQL is:

{“query”: "mutation { change_simple_column_value(board_id: 929960697, item_id: 1006655013, column_id: “text3”, value: “new value”) {id, name}} "}

What I am struggling to understand is why an identical piece of code other than the graphql query returns a 400 error code, when the first returns the intended data. Is there something wrong how my mutation query is structured? I have tested it in the API playground and it changed the value as intended.

No problem Mark!

Hmm that is indeed quite strange. If it’s working in your API playground, then there is nothing wrong with the mutation query you’re sending.

From a quick search online, it looks like the issue here might actually be pertaining to your headers. What happens if you remove the “&” between Bearer and your actual key? It’s confusing that you’re only getting this error when mutating though.

Is it possible for you to install something like Fiddler to troubleshoot your Power BI code?

Hi Helen,

Thanks for the suggestion of using Fiddler I’ll have to look into that.

The “&” is concatenating the strings "Bearer " and the variable Key I am storing my API token in.

1 Like

Sure! Let me know if Fiddler gives you any more insight into the error.

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