Starting December 3, join live sessions with database experts and the Microsoft product team to learn just how easy it is to get started
Learn moreGet certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now
Hi
I have a JWT token and need to pass it along with my POST request to a REST endpoint like so:
let
url = "https://test.my-website.com/graphql",
token = "express:sess=ey....",
Source = Web.Contents(
url,
[
Headers=[
#"Method"="POST",
#"Content-Type"="application/json",
#"Cookie"=token,
],
Content=Text.ToBinary("{""query"": ""{ allData( $filter: [FilterInput]){ allData(filter: $filter) {
field1
field2
} }""}")
]
),
#"JSON" = Json.Document(Source)
in
JSON
If I run the same in Postman and pass the token in the header with "Cookie" as name of the header entry and "express:sess=ey...." as the value, it works all fine.
When I do the same in the advanced editor of a "Blank Query" data source, I get "Expression.Error: Access to the resource is forbidden."
Looking at the Query diagnostics, the server returned: Message: The remote server returned an error: (403) Forbidden.
I followed this tutorial to send a GraphQL query: https://www.linkedin.com/pulse/connect-powerbi-graphql-endpoint-amir-khan/
How does Power Bi blank query works differently compared to Postman? Is it using a different encoding or something?
Any help is much appreciated.
Thanks
Solved! Go to Solution.
Thanks Gao,
I managed to solve my problem and it had nothing to do with the authentication. Using a cookie like the example below works just fine.
The actual problem was the graphql part which had incorrect formatting. I was mislead by the error message.
If anyone wants to send a graphql request from power bi with actual variables, this is how it worked for me:
let
url = "https://my-website.com/graphql",
token = "express:sess=ey... [replace this value with you Cookie ]",
body = "{ ""query"": ""query allParameter($filter: [FilterInput]) { allParameter(filter: $filter) { parameterId } }"", ""variables"": {""filter"": []} }",
response = Web.Contents(
url,
[
Headers=[
#"Method"="POST",
#"Content-Type" = "application/json",
#"Cookie"=token
],
Content=Text.ToBinary(body)
]
),
jsonResponse = Json.Document(response)
in
jsonResponse
Thanks Gao,
I managed to solve my problem and it had nothing to do with the authentication. Using a cookie like the example below works just fine.
The actual problem was the graphql part which had incorrect formatting. I was mislead by the error message.
If anyone wants to send a graphql request from power bi with actual variables, this is how it worked for me:
let
url = "https://my-website.com/graphql",
token = "express:sess=ey... [replace this value with you Cookie ]",
body = "{ ""query"": ""query allParameter($filter: [FilterInput]) { allParameter(filter: $filter) { parameterId } }"", ""variables"": {""filter"": []} }",
response = Web.Contents(
url,
[
Headers=[
#"Method"="POST",
#"Content-Type" = "application/json",
#"Cookie"=token
],
Content=Text.ToBinary(body)
]
),
jsonResponse = Json.Document(response)
in
jsonResponse
Hi @bender1234 ,
Ensure Correct Token Format: Double-check the format of your JWT token. Ensure it's correctly formatted and includes the necessary prefix (usually "Bearer") if required by your endpoint. For JWT tokens, the header is typically passed as an "Authorization" header rather than a "Cookie".
Use Authorization Header: If your endpoint expects a JWT token for authentication, it's more common to use the "Authorization" header instead of "Cookie". Here's an adjusted example:
let
url = "https://test.my-website.com/graphql",
token = "Bearer ey....",
Source = Web.Contents(
url,
[
Headers = [#"Method" = "POST", #"Content-Type" = "application/json", #"Authorization" = token],
Content = Text.ToBinary(
"{""query"": ""{ allData( $filter: [FilterInput]){ allData(filter: $filter) {
field1
field2
} }""}"
)
]
),
JSON = Json.Document(Source)
in
JSON
Best Regards,
Gao
Community Support Team
If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!
How to get your questions answered quickly -- How to provide sample data in the Power BI Forum
Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.
User | Count |
---|---|
35 | |
17 | |
12 | |
11 | |
9 |
User | Count |
---|---|
44 | |
27 | |
16 | |
14 | |
13 |