Forum Discussion

this_is_pk's avatar
this_is_pk
Regular Visitor
2 years ago

Date as Request Header in API

Hello all,

 

I am new to PBI and looking for some help here.

I am using a GET method to pull the data through API. According to the API documentation a dynamic bearer token is requried for every api call. I was able to fetch the token and when i was able to use it in the Request Headers for API URL. However according to the API documentation a Date Header is required which is UTC timezone to be sent along with Authorization token as Request Headers. Below is the code that i am using. 

 

Source = Value.Metadata(
Web.Contents(BaseURL,

[
Headers=[Authorization = Bearertoken, Date = TodaysDate
]
)),

 

However when i use Date in the Request Header the PBI is throwing an error 

 

Expression.Error: The 'Date' header must be modified using the appropriate property or method.
Parameter name: name
Details:
Sun, 05 May 2024 07:12:37 GMT

 

According the API Documentation the Header name should exactly match to the text whcih is "Date". I tried multiple options but nothing worked out. I also tried in Postman and when i use Date as Header it is working fine and when i change the Date name to any other name such as "Dates" (adding "s" at the end) even in postman i see 401 unauthorized error. I am not sure how to handle this.  Any help is greatly appreciated. 

6 Replies

  • Can you show the header for the successful Postman request?  Maybe the date format is expected to be in ISO-8601.

    • this_is_pk's avatar
      this_is_pk
      Regular Visitor

      It is not the date format that is causing the issue. Its the header (such as column header) . 

      For example Date = Sun, 05 May 2024 02:55:55 GMT - this is the format mentioned in API documentation. 

       

      The format for date i have is correct but when i use the name "Date" the M query is returning errors. 

       

       

       

      Error that i am getting is below

       

       

      • lbendlin's avatar
        lbendlin
        Super User

        Try without the space.  I don't think that is the right date format, btw.

  • bisted's avatar
    bisted
    Frequent Visitor

    Hi, did you ever resolve this, as I'm having the same issue, with both Date and Host in the header.