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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
jdalevem19
Frequent Visitor

"We cannot convert a value of type Record to type Text" when making rest api call

For the following code to access data via a rest API, I keep getting the error "We cannot convert a value of type Record to type Text". I need to use two items as part of the header part of the API call, although I don't seem to be able to do this due to only being able to get this in 'record' format. I think the same will also apply when trying to convert the items included in the 'body'. Please could someone advise on what the best solution for this is? Note- the aqs1 part is meant to be a json which forms part of the body.

 

let
    base_url = "https://api.uk.testapp.io/api",
    api_key = "testapikey123xxxx",
    
    headers = [accept = "application/json",Authorization = "Bearer" & api_key],
    
    Q1 = "{""type"":""Join"",""properties"":{""attributes"":[""attributes_itemsTitle"",""attributes_itemsSubtitle""],""collectionCode"":[""Test""],""dodiCode"":""designs_AttachmentTypes""}}"
,
    b = [
        Q = Q1,
        fileName = "name.csv",
        discriminator = "CsvExportWebRequestModel"
    ]

    ,response = Web.Contents(base_url,
      [RelativePath="/export",
         Query=[
            header=headers,
            json = (b),
           ManualStatusHandling = {400}
        ]]
    )

 

2 REPLIES 2
lbendlin
Super User
Super User

You put the headers and Query portions in the wrong place.  See example 2 Web.Contents - PowerQuery M | Microsoft Learn

Thanks for your response Ibendlin. I've changed the web.contents part to be as follows, where I've assigned the variable noted as 'b' in my previous post as the 'Query' section of the Web.Contents api request. Please could I confirm that this is correct? From the link you've sent over, I can see a few potential fields that could be used to pass this json document into the request. 

Note - I've also slightly tweaked the variable 'b' to be encased by JSON.FromValue() as shown in example 2 from the link you sent. 

jdalevem19_0-1701940242615.png

 

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

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

MayPowerBICarousel1

Power BI Monthly Update - May 2024

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

Top Solution Authors
Top Kudoed Authors