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

July 28 - August 9 | Final Round of the Power BI Dataviz World Championships. This is your chance. Learn more

Reply
MikeWall
Frequent Visitor

Token Literal error when making POST API call

Hi

 

Wondering if anybody could spot what is wrong with the M query below. I'm trying to pass a query to an API (using POST method).

I'm getting the error 'Token Literal Expected' and when I click show error, it highlights the = sign before the let statement. So it's not very helpful. Using POST to call an API doesn't appear to be very well documented. The key pairs in the body are values from a database which contains parameters for the API. Basic authentication has been configured in settings on the data source (myurl), hence not in the query itself.

 

 

 

=let
url = "http://myurl",
body = "{
"eventID": "167",
"processID": "96",
"project": "SSL",
"version": "004.008.003.007",
"environmentDataRisingEdgeSize": "42",
"environmentDataRisingEdgeCount": "10",
"environmentDataRisingEdgeStart": "0",
"environmentDataRisingEdgeTriggerFrame": "7",
"rawEnvironmentData":"0x2B1C68002F0050B89A0730230900120100000000000000000000000000002200340000000000FE0000002E1C68002F0050B89A0742230900120100000000000000000000000000002200340000000000FE000000371C6800290050B89A0742230900120100000000000000000000000000002200340000000000FE000000441C6800290050B89A075A230900120100000000000000000000000000002200340000000000FE000000461C6800290050B89A075A230900120100000000000000000000000000002200340000000000FE0000005C1C6800380050B89A0767230900120100000000000000000000000000002200340000000000FE000000591C6800430050B8000867230900120100000000000000000000000000002200340000000000FE000000661C69004B0050B800006C230900120100000000000000008200010000002200350000000000FE000000761C69004A0050B800006C230900120100000000000000000000000000002200340000000000FE000000971C69004A0050B800007E230900120100000000000000000000000000002200340000000000FE000000",
"Start Date/Time":"2020-12-01 10:42:04.853",
"End Date/Time":"2020-12-01 10:42:06.853"
}",
Data= Web.Contents(url,[Content=Text.ToBinary(body),Headers=[#"Content-Type"="application/json"]]),
DataRecord = Json.Document(Data),
Source=DataRecord
in
Source

1 ACCEPTED SOLUTION
mahoneypat
Microsoft Employee
Microsoft Employee

Delete the = at the beginning.  Also, you may need to use double quotes as an escape character to pass the quotes to the JSON.

 

let
url = "http://myurl",
body = "{
""eventID"": ""167"",
""processID"": ""96"",
""project"": ""SSL"",
""version"": ""004.008.003.007"",
""environmentDataRisingEdgeSize"": ""42"",
""environmentDataRisingEdgeCount"": ""10"",
""environmentDataRisingEdgeStart"": ""0"",
""environmentDataRisingEdgeTriggerFrame"": ""7"",
""rawEnvironmentData"":""0x2B1C68002F0050B89A0730230900120100000000000000000000000000002200340000000000FE0000002E1C68002F0050B89A0742230900120100000000000000000000000000002200340000000000FE000000371C6800290050B89A0742230900120100000000000000000000000000002200340000000000FE000000441C6800290050B89A075A230900120100000000000000000000000000002200340000000000FE000000461C6800290050B89A075A230900120100000000000000000000000000002200340000000000FE0000005C1C6800380050B89A0767230900120100000000000000000000000000002200340000000000FE000000591C6800430050B8000867230900120100000000000000000000000000002200340000000000FE000000661C69004B0050B800006C230900120100000000000000008200010000002200350000000000FE000000761C69004A0050B800006C230900120100000000000000000000000000002200340000000000FE000000971C69004A0050B800007E230900120100000000000000000000000000002200340000000000FE000000"",
""Start Date/Time"":""2020-12-01 10:42:04.853"",
""End Date/Time"":""2020-12-01 10:42:06.853""
}",
Data= Web.Contents(url,[Content=Text.ToBinary(body),Headers=[#"Content-Type"="application/json"]]),
DataRecord = Json.Document(Data),
Source=DataRecord
in
Source

 

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

2 REPLIES 2
mahoneypat
Microsoft Employee
Microsoft Employee

Delete the = at the beginning.  Also, you may need to use double quotes as an escape character to pass the quotes to the JSON.

 

let
url = "http://myurl",
body = "{
""eventID"": ""167"",
""processID"": ""96"",
""project"": ""SSL"",
""version"": ""004.008.003.007"",
""environmentDataRisingEdgeSize"": ""42"",
""environmentDataRisingEdgeCount"": ""10"",
""environmentDataRisingEdgeStart"": ""0"",
""environmentDataRisingEdgeTriggerFrame"": ""7"",
""rawEnvironmentData"":""0x2B1C68002F0050B89A0730230900120100000000000000000000000000002200340000000000FE0000002E1C68002F0050B89A0742230900120100000000000000000000000000002200340000000000FE000000371C6800290050B89A0742230900120100000000000000000000000000002200340000000000FE000000441C6800290050B89A075A230900120100000000000000000000000000002200340000000000FE000000461C6800290050B89A075A230900120100000000000000000000000000002200340000000000FE0000005C1C6800380050B89A0767230900120100000000000000000000000000002200340000000000FE000000591C6800430050B8000867230900120100000000000000000000000000002200340000000000FE000000661C69004B0050B800006C230900120100000000000000008200010000002200350000000000FE000000761C69004A0050B800006C230900120100000000000000000000000000002200340000000000FE000000971C69004A0050B800007E230900120100000000000000000000000000002200340000000000FE000000"",
""Start Date/Time"":""2020-12-01 10:42:04.853"",
""End Date/Time"":""2020-12-01 10:42:06.853""
}",
Data= Web.Contents(url,[Content=Text.ToBinary(body),Headers=[#"Content-Type"="application/json"]]),
DataRecord = Json.Document(Data),
Source=DataRecord
in
Source

 

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Thank you for the response, it did fix the error I had, unfortunately I've since been told that the API will not handle JSON, so I'm working on converting the same code so it passes and recieves xml instead.

Helpful resources

Announcements
Fabric Community Sticker Design Challenge Barcelona Carousel

Fabric Community Sticker Challenge - Barcelona 2026

If you love stickers, then you will definitely want to check out our community sticker challenge, Barcelona edition!

July Power BI Update Carousel

Power BI Monthly Update - July 2026

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

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.