Forum Discussion

Hap76's avatar
Hap76
Frequent Visitor
4 years ago
Solved

GraphQL mutation from Power Query

Working in Excel Power Query. I can query data just fine in Power Query from a GraphQL API. But now I'm trying send to an API with a GraphQL mutation. Something causes it to duplicate the record on the endpoint:

 

 

 

 

 

let
    Source = Web.Contents(
	"https://api.######.com/v2",
	[
		Headers=[
			#"Method"="POST",
			#"Content-Type"="application/json",
			#"Authorization"=APIKey
		],
		Content=Text.ToBinary("{""query"": ""mutation { create_item (board_id:#####, group_id:#####, item_name:wazoo) { id } }""}")
	]
    ),
    #"JSON" = Json.Document(Source)
in
   #"JSON"

 

 

 

 

 

The #JSON line is from a version where I'm actually fetching the JSON. I don't really need it since I'm not parsing here, only sending/updating. So I tried to just returned Source in the let statement. This seems to fire the mutation query only once (yay!) but it throws an error in Excel, because Excel wants something to do.

 

The M:

 

 

 

 

let
    Source = Web.Contents(
	"https://api.######.com/v2",
	[
		Headers=[
			#"Method"="POST",
			#"Content-Type"="application/json",
			#"Authorization"=APIKey
	],
     Content=Text.ToBinary("{""query"": ""mutation { create_item (board_id:#####, group_id:new_group51930, item_name:wazoo) { id } }""}")
	]
    )
 in
       Source

 

 

 

 

I'm trying to learn how to work with APIs within Power Query. Info out there is sparse, appreciate any help and resources!

  • The design goal of Power Query M is to take data from a source and transform it into a tabular format that can be consumed by Excel or Power BI, or a Parquet-style dataflow.  Nowhere in the design specifications is there a place for "talking back to the data source" (the available options are more like unintended consequences of some of the design decisions).  Unlike SSIS and Informatica  Power Query is more of a one-way street.

5 Replies

    • Hap76's avatar
      Hap76
      Frequent Visitor

      Interesting, thanks. When you say "That's not what it is designed for", are you suggesting the M language is not suitable for working with APIs? Or SQL Inserts/Updates for that matter? That's suprising- and quite a blow to my future plans. Surely these issues could be handled in a custom connector, no?

      • lbendlin's avatar
        lbendlin
        Icon for Super User rankSuper User

        The design goal of Power Query M is to take data from a source and transform it into a tabular format that can be consumed by Excel or Power BI, or a Parquet-style dataflow.  Nowhere in the design specifications is there a place for "talking back to the data source" (the available options are more like unintended consequences of some of the design decisions).  Unlike SSIS and Informatica  Power Query is more of a one-way street.