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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It 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
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors
Top Kudoed Authors