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

Data Days is here! Join us now for 60+ days of learning, challenges, and connection. Learn more

Reply
cmcosker
New Member

JSON POST Syntax issues

Hi, I'm having issues with this JSON POST request. I feel like I am just missing something obvious, would someone be able to assist? Thanks!

 

let
api_key = "XXXXXXXX",
startdate = DateTimeZone.From("2023-06-16T13:46:11.043Z"),
days_range =Text.From(7),
LoginURL = "YYYYYYY",
PostBody = [#"LocationIds"= 0 , #"Date"= startdate, #"Range"= days_range, #"MaxPerDay"= 0, #"LimitOverLaps"= false],
PostHeader = [#"auth_token" = api_key, #"Content-Type" = "application/json"],
JSONHeader = Json.FromValue(PostHeader),
JSONBody = Json.FromValue(PostBody),
out = Json.Document(Web.Contents(LoginURL,[Content=JSONBody,Headers=PostHeader]))

in
out

 

The error I receive:

DataSource.Error: Web.Contents failed to get contents from 'YYYYYYYY' (400): Bad Request
Details:
DataSourceKind=Web
DataSourcePath=YYYYYYYY
Url=YYYYYYYYY

1 REPLY 1
v-jingzhang
Community Support
Community Support

Hi @cmcosker 

 

Do the headers you passed have the correct names? Especially "auth_token"? Are you able to use other API tools to test the same API and get a response successfully?

 

Perhaps you can try

let
  api_key = "XXXXXXXX",
  startdate = DateTimeZone.From("2023-06-16T13:46:11.043Z"),
  days_range = Text.From(7),
  LoginURL = "YYYYYYY",
  PostBody = [
    LocationIds = 0,
    Date = startdate,
    Range = days_range,
    MaxPerDay = 0,
    LimitOverLaps = false
  ],
  PostHeader = [#"auth_token" = api_key, #"Content-Type" = "application/json"],
  JSONBody = Json.FromValue(PostBody),
  out = Json.Document(Web.Contents(LoginURL, [Content = JSONBody, Headers = PostHeader]))
in
  out

  

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

Helpful resources

Announcements
Fabric Data Days is here Carousel

Fabric Data Days 2026

Don't miss out on Data Days, June 15 through August 7. Learn Fabric, Power BI, SQL, AI and more.

May Power BI Update Carousel

Power BI Monthly Update - May 2026

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

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.