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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
jsanchezm
Frequent Visitor

API POST call not working: cannot convert a value of type Record to type Number

Hi,

I've been stumping my head quite a lot with this, and can't figure out how to solve it.

I access a REST API and I have to send it a body to filter the json records that I need to get. I have got to make the GET calls without any problem, but can't get the POST ones to work.

This is the code at the moment:

 

 

 

let
	credencial=Record.Field(GetToken2(),"token") as text,
	query = "{
	""from"":""2022-06-12T00:00:00.000Z"",
	""to"":""2022-06-12T23:59:59.000Z"",
	""onlyUnprocessed"":""false"",
	""vehicles:""null"",
	""drivers:""null"",
	""alarms:2735687,
	""severityLevels:""null""
	}",
	url = Text.Combine({"MYAPIURL/occurrencesextended?api_key=", credencial}),
	Source = Json.Document(Web.Contents(url),[Content=Text.ToBinary(query)])
in
    Source

 

 

 

But when running this query, it shows the next error:

jsanchezm_0-1657190166733.png

And I haven't been able to find any post or article that guides me to how to solve this problem. There are some that are similar in the forum, but the issue they have is not the same as mine. Anybody has any insight?

Thanks in advance for your help.

 

 

1 ACCEPTED SOLUTION
jsanchezm
Frequent Visitor

Hi once again, 

 

I managed to figure it out:

let
	credencial=Record.Field(GetToken2(),"token") as text,
	query = "{
			""from"":""2022-07-07T00:00:00.000Z"",
			""to"":""2022-07-07T23:59:59.000Z"",
			""onlyUnprocessed"":false,
			""vehicles"":""null"",
			""drivers"":""null"",
			""alarms"":2735687,
			""severityLevels"":""null""
			}",
	url = Text.Combine({"MYAPIURL?api_key=", credencial}),
	Source = Json.Document(Web.Contents(url, 
            [
                Headers=[#"Content-Type"="application/json"], 
                Content= Text.ToBinary(query)
            ]))
in
    Source

It seems it was about expliciting the application/json and some formatting enhancements in the Web.Contents() method.

Hope this can help somebody in the future, thanks to all who read my original post.

View solution in original post

1 REPLY 1
jsanchezm
Frequent Visitor

Hi once again, 

 

I managed to figure it out:

let
	credencial=Record.Field(GetToken2(),"token") as text,
	query = "{
			""from"":""2022-07-07T00:00:00.000Z"",
			""to"":""2022-07-07T23:59:59.000Z"",
			""onlyUnprocessed"":false,
			""vehicles"":""null"",
			""drivers"":""null"",
			""alarms"":2735687,
			""severityLevels"":""null""
			}",
	url = Text.Combine({"MYAPIURL?api_key=", credencial}),
	Source = Json.Document(Web.Contents(url, 
            [
                Headers=[#"Content-Type"="application/json"], 
                Content= Text.ToBinary(query)
            ]))
in
    Source

It seems it was about expliciting the application/json and some formatting enhancements in the Web.Contents() method.

Hope this can help somebody in the future, thanks to all who read my original post.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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