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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

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
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

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

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

Top Solution Authors
Top Kudoed Authors