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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

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
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.