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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Anonymous
Not applicable

Service Refresh issue - web.contents with API key and parameters in the URL

Hello,


Firstly, I have gone through a multitude of blog posts and forum entries, but could not apply the resolution to my case, so I would really appreciate some guidance from you, more experienced folks.

In Short, I have an API call that retrieves a token, then a second one that returns a table and this works fine in PBI desktop, but on service I am unable to create a dataflow or schedule a refresh, as the URL has parameters and it is not static, when the scan happens.

 

This is how my original query bit  with the second call that returns the table, using the key from the first call (working on desktop):

Value in the Header bit is the API key; StartDate_string & EndDate_string are from - to date parameters

BASEURL marks where the URL is, as I cannot provide that here.

 

Source2 = Json.Document(Web.Contents("BASEURL?dataType=Futures&startDate=" & StartDate_string & "&endDate=" & EndDate_string & "&includeProperties=ALL", [Headers=[Cookie="JSESSIONID="&Value , Accept="application/json"]])),

 

This is how I attempted to rewrite it for PBI service. I am not even sure if I needed to split the URL at all (and whether my split is correct), in order to use the RelativePath argument, but it seemed like it would not work otherwise.

 

Source2 = Json.Document(
Web.Contents("BASEURL",
[
RelativePath="SECOND_URLBIT",
Query=
[
dataType="Futures",
startDate=StartDate_string,
endDate=EndDate_string,
includeProperties="ALL"
]
]
), [Headers=[Cookie="JSESSIONID="&Value , Accept="application/json"]])),

 

I would greatly appreciate any help, also any suggestion if this approach is not the best, as I have not used API connections much this far. The current error message that I receive is the following, although I am positive, the re-building I am attempting is also not flawless.

 

Expression.Error: We cannot convert a value of type Record to type Number.
Details:
Value=[Record]
Type=[Type]

1 ACCEPTED SOLUTION
v-eachen-msft
Community Support
Community Support

Hi @Anonymous ,

 

You don't need to put "Headers" out of Web.Contents(). Like "RelativePath" and "Query", "Headers" is also a parameter of Web.Contents().

Here is the document for more details.

https://docs.microsoft.com/en-us/powerquery-m/web-contents

According to this document, "Headers" will return a record, I think this is the reason for showing "We cannot convert a value of type Record to type Number".

So you could refer to the following codes:

 

Source2 = Json.Document(
Web.Contents("BASEURL",
   [
    RelativePath="SECOND_URLBIT",
    Query=
          [
           dataType="Futures",
           startDate=StartDate_string,
           endDate=EndDate_string,
           includeProperties="ALL"
          ],
    Headers=
          [
           Cookie="JSESSIONID="&Value, 
           Accept="application/json"
          ]
   ]
   ))

 

 

Community Support Team _ Eads
If this post helps, then please consider Accept it as the solution to help the other members find it.

View solution in original post

1 REPLY 1
v-eachen-msft
Community Support
Community Support

Hi @Anonymous ,

 

You don't need to put "Headers" out of Web.Contents(). Like "RelativePath" and "Query", "Headers" is also a parameter of Web.Contents().

Here is the document for more details.

https://docs.microsoft.com/en-us/powerquery-m/web-contents

According to this document, "Headers" will return a record, I think this is the reason for showing "We cannot convert a value of type Record to type Number".

So you could refer to the following codes:

 

Source2 = Json.Document(
Web.Contents("BASEURL",
   [
    RelativePath="SECOND_URLBIT",
    Query=
          [
           dataType="Futures",
           startDate=StartDate_string,
           endDate=EndDate_string,
           includeProperties="ALL"
          ],
    Headers=
          [
           Cookie="JSESSIONID="&Value, 
           Accept="application/json"
          ]
   ]
   ))

 

 

Community Support Team _ Eads
If this post helps, then please consider Accept it as the solution to help the other members find it.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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

Top Solution Authors