Forum Discussion

ViralGajjar2904's avatar
ViralGajjar2904
Frequent Visitor
2 years ago

I want to use first API response in another Query without call it second time

I am creating new session in below query which name is Create_Session.

let
    BaseURL = BaseURLPara,
    body = "{""sessionId"":null}",
    Source = Json.Document(Web.Contents(BaseURL,
[
RelativePath = "/testAPI/session/create_session",
Content = Text.ToBinary(body),
        Headers = [#"Content-Type" = "application/json"]
    ])),
    newSessionID = Source[data][newSessionID]
in
    newSessionID

This created SessionId I want to pass in below new Query but when I refresh all then /testAPI/session/create_session call two times in backend.I do not want to call /testAPI/session/create_session in below query because I already pass Sessionid using variable (Createsession) then why /testAPI/session/create_session call in below Query?

let
    BaseURL=BaseURLPara,
    Createsession=Create_Session,
    body="{""sessionId"": """ & Createsession & """,
    ""isSearch"": false,
    ""keyword"": """",
    ""exploreType"": 2}",
    Source=Json.Document(Web.Contents(BaseURL,
[
RelativePath="/testAPI/explorer/location_hierarchy",
Content=Text.ToBinary(body),
                Headers=[#"Content-Type"="application/json"]
        ])),
    #"Converted to Table" = Record.ToTable(Source),
    Value = #"Converted to Table"{1}[Value],
    #"Converted to Table1" = Record.ToTable(Value),
    Value1 = #"Converted to Table1"{0}[Value],
    #"Parsed JSON" = Json.Document(Value1),
    #"Converted to Table2" = Record.ToTable(#"Parsed JSON"),
    #"Expanded Value" = Table.ExpandListColumn(#"Converted to Table2", "Value"),
    #"Expanded Value1" = Table.ExpandRecordColumn(#"Expanded Value", "Value", {"EntID", "EntityName", "Name", "Description", "Type", "Icon", "Room"}, {"EntID", "EntityName", "Name.1", "Description", "Type", "Icon", "Room"}),
    #"Expanded Room" = Table.ExpandListColumn(#"Expanded Value1", "Room"),
    #"Expanded Room1" = Table.ExpandRecordColumn(#"Expanded Room", "Room", {"EntID", "EntityName", "Name", "Description", "Type", "Icon", "Floor"}, {"EntID.1", "EntityName.1", "Name.2", "Description.1", "Type.1", "Icon.1", "Floor"}),
    #"Expanded Floor" = Table.ExpandListColumn(#"Expanded Room1", "Floor"),
    #"Expanded Floor1" = Table.ExpandRecordColumn(#"Expanded Floor", "Floor", {"EntID", "EntityName", "Name", "Description", "Type", "Icon", "HasChildren"}, {"EntID.2", "EntityName.2", "Name.3", "Description.2", "Type.2", "Icon.2", "HasChildren"}),
    #"Renamed Columns1" = Table.RenameColumns(#"Expanded Floor1",{{"EntID", "Parent ID"}, {"Name.1", "Site Name"}, {"Type", "Room Type"}, {"Name.2", "Room Name"}, {"Name.3", "Floor Name"}}),
    #"Removed Columns" = Table.RemoveColumns(#"Renamed Columns1",{"Description", "Icon", "Description.1", "Icon.1", "Description.2", "Icon.2"})
in
    #"Removed Columns"

2 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi ViralGajjar2904 ,

     

    -- Power Query is not suitable for write back, as it will by default execute queries multiple times: The first execution is to retrieve metadata in order to create a query execution plan. After that it will execute the execution plan.
    There is no way you can suppress that.

     

    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