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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
vbharakhada
Frequent Visitor

how to pass json in body in API call to get data (GraphQl)

Hi

I'm able to get the data in Postman using Graphql for Jira APIs. I need to get the data in Power query editor through API call.
Every time I'm trying it gives me an error like " Bad JSON passed in body".

{
	"info": {
		"_postman_id": "c77632df-55ce-483f-a902-d1798c919b43",
		"name": "graphQl",
		"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
		"_exporter_id": "24457230"
	},
	"item": [
		{
			"name": "graphQl Copb",
			"request": {
				"auth": {
					"type": "basic",
					"basic": [
						{
							"key": "username",
							"value": "",
							"type": "string"
						},
						{
							"key": "password",
							"value": "",
							"type": "string"
						}
					]
				},
				"method": "POST",
				"header": [
					{
						"key": "Content-Type",
						"value": "application/json"
					},
					{
						"key": "Authorization",
						"value": "Basic cHZhbGFAYXNpdGUuY29tOnlpYWZkNEVyS2ZJaW5RWDFjZmZ3MEEwRA=="
					}
				],
				"body": {
					"mode": "graphql",
					"graphql": {
						"query": "query UserDetails($userId: String!, $cloudId: String!) {\r\n  CloudUser(userId: $userId, cloudId: $cloudId) {\r\n    id\r\n    fullName\r\n    isCurrentUser\r\n    title\r\n    department\r\n    companyName\r\n    location\r\n    timezone\r\n    email\r\n    phoneNumber\r\n  }\r\n}\r\n",
						"variables": "{\n  \"cloudId\": \"\",\n  \"userId\": \"5ef277e48624070abc52add2\"\n}"
					}
				},
				"url": {
					"raw": "https://asitehelpdesk.atlassian.net/gateway/api/directory/graphql?q=UserDetails",
					"protocol": "https",
					"host": [
						"asitehelpdesk",
						"atlassian",
						"net"
					],
					"path": [
						"gateway",
						"api",
						"directory",
						"graphql"
					],
					"query": [
						{
							"key": "q",
							"value": "UserDetails"
						}
					]
				}
			},
			"response": []
		}
	]
}

 

vbharakhada_0-1712554913845.png


Please help to get the data in power query editor.


hi @dufoq3  Please can you also check, If it is possible.

1 REPLY 1
v-jingzhan-msft
Community Support
Community Support

Hi @vbharakhada 

 

Not sure if this would work. You may give it a try. 

let
  api_url = "https://asitehelpdesk.atlassian.net/",
  relative_path = "gateway/api/directory/graphql",
  Username = "your_username",
  Password = "your_password",
  EncodedCredentials = "Basic " & Binary.ToText(Text.ToBinary(Username & ":" & Password), BinaryEncoding.Base64),
  body = "{""query"": ""query UserDetails($userId: String!, $cloudId: String!) {#(cr)#(lf)  CloudUser(userId: $userId, cloudId: $cloudId) {#(cr)#(lf)    id#(cr)#(lf)    fullName#(cr)#(lf)    isCurrentUser#(cr)#(lf)    title#(cr)#(lf)    department#(cr)#(lf)    companyName#(cr)#(lf)    location#(cr)#(lf)    timezone#(cr)#(lf)    email#(cr)#(lf)    phoneNumber#(cr)#(lf)  }#(cr)#(lf)}#(cr)#(lf)"", ""variables"": {""cloudId"": """", ""userId"": ""5ef277e48624070abc52add2""}}",
  Response = Json.Document(
    Web.Contents(
      api_url,
      [
        RelativePath = relative_path,
        Query = [q = UserDetails],
        Headers = [#"Content-Type" = "application/json", #"Authorization" = EncodedCredentials],
        Content = Text.ToBinary(body)
      ]
    )
  )
in
  Response

Or

let
  api_url = "https://asitehelpdesk.atlassian.net/",
  relative_path = "gateway/api/directory/graphql",
  // Username = "your_username",
  // Password = "your_password",
  // EncodedCredentials = "Basic " & Binary.ToText(Text.ToBinary(Username & ":" & Password), BinaryEncoding.Base64),
  body = "{""query"": ""query UserDetails($userId: String!, $cloudId: String!) {#(cr)#(lf)  CloudUser(userId: $userId, cloudId: $cloudId) {#(cr)#(lf)    id#(cr)#(lf)    fullName#(cr)#(lf)    isCurrentUser#(cr)#(lf)    title#(cr)#(lf)    department#(cr)#(lf)    companyName#(cr)#(lf)    location#(cr)#(lf)    timezone#(cr)#(lf)    email#(cr)#(lf)    phoneNumber#(cr)#(lf)  }#(cr)#(lf)}#(cr)#(lf)"", ""variables"": {""cloudId"": """", ""userId"": ""5ef277e48624070abc52add2""}}",
  Response = Json.Document(
    Web.Contents(
      api_url,
      [
        RelativePath = relative_path,
        Query = [q = UserDetails],
        Headers = [#"Content-Type" = "application/json", #"Authorization" = "Basic cHZhbGFAYXNpdGUuY29tOnlpYWZkNEVyS2ZJaW5RWDFjZmZ3MEEwRA=="],
        Content = Text.ToBinary(body)
      ]
    )
  )
in
  Response

 

Best Regards,
Jing
If this post helps, please Accept it as Solution to help other members find it. Appreciate your Kudos!

Helpful resources

Announcements
Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

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

Jan NL Carousel

Fabric Community Update - January 2025

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

Top Solution Authors
Top Kudoed Authors