Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
SteelChampzz
Helper II
Helper II

GraphQL to Power Query M Script Question

Good morning every one I have a GraphQL query that I've turned into an M Script but I'm having issues in taking an "error" out the script reads as follows:
let
endpoint = "https://your-graphql-endpoint",
client_id = "your-client-id",
client_secret = "your-client-secret",
graphqlQuery = "query orders($regionCode: String!, $licenseNumber: String, $order: [OrderSortInput!], $where: OrderFilterInput) {
orders(regionCode: $regionCode, licenseNumber: $licenseNumber, order: $order, where: $where) {
items {
vendor {
name
licenseNumber
}
lineItems {
product {
strain {
name
}
categoryName
}
quantity
price
total
}
createTimestamp
}
}
}",
graphqlVariables = "{
\"regionCode\": \"wa\",
\"licenseNumber\": \"123456\",
\"order\": [{ \"poNumber\": \"DESC\" }],
\"where\": { \"updateTimestamp\": { \"gte\": \"2023-07-10\" } }
}",
tokenBody = [
grant_type = "client_credentials",
client_id = client_id,
client_secret = client_secret
],
tokenResponse = Json.Document(Web.Contents("https://your-auth-endpoint/token", [
Content = Text.ToBinary(Uri.BuildQueryString(tokenBody)),
Headers = [#"Content-Type"="application/x-www-form-urlencoded"]
])),
accessToken = tokenResponse[access_token],
headers = [
Authorization = "Bearer " & accessToken,
#"Content-Type" = "application/json"
],
body = [
query = graphqlQuery,
variables = graphqlVariables
],
result = Json.Document(Web.Contents(endpoint, [
Content = Text.ToBinary(Json.FromValue(body)),
Headers = headers
]))
in
result

 

I'm getting the error in this section:

SteelChampzz_0-1689181118570.png

and the error is saying this:

SteelChampzz_1-1689181155172.png

 

I've tried to rewrite this in so many ways but im still getting the same error.

 

Any help on how to rewrite this would be awesome or any of connector solutions that would be easier to deal with instead of inputting this into the M Script would be helpful as well.

 

Thanks to all that help.

1 REPLY 1
lbendlin
Super User
Super User

you need to double escape.  Instead of \" you need to use \""  

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.