Forum Discussion
Not being able to access data via API Post Request
- 5 years ago
Hi ziyabikram96
Including Content in your request makes the Web.Contents perform a POST, for example:
Source = Json.Document(Web.Contents(url,[ Headers = [#"Content-Type"="application/json"], Content = Text.ToBinary(body) ] ))I don't know exactly what you need to provide in the request (e.g. API Auth,Headers) as I don' t know the API,but this should get you started. Post back if you need further assistance.
regards
Phil
Hi ziyabikram96
Including Content in your request makes the Web.Contents perform a POST, for example:
Source = Json.Document(Web.Contents(url,[
Headers = [#"Content-Type"="application/json"],
Content = Text.ToBinary(body)
]
))
I don't know exactly what you need to provide in the request (e.g. API Auth,Headers) as I don' t know the API,but this should get you started. Post back if you need further assistance.
regards
Phil
Hi PhilipTreacy
I've got a similar issue, i can run all these in postman with no issues, but PQ causes no end of problems. this is what i have, but it throws errors DataSource.Error: Web.Contents failed to get contents from 'https://myapidomain.com/v0/auth/code' (500): Internal Server Error
and
Expression.Error: We cannot convert a value of type Binary to type Text. Details: Value=[Binary] Type=[Type]
let
apiBaseUrl = #"API URL",
apiEmail = #"API Email",
accessCode = #"Access Code",
AuthUrl = apiBaseUrl & "/auth/code",
RawBody = "{
""meta"": {},
""data"": {
""email"": """ & apiEmail & """,
""code"": """ & accessCode & """
}
}",
Response = Web.Contents(
AuthUrl,
[
Headers = [
#"Content-Type" = "application/json",
#"Accept" = "application/json",
#"Accept-Language" = "en",
#"User-Agent" = "PostmanRuntime/7.32.0" // mimic Postman
],
Content = Text.ToBinary(RawBody, TextEncoding.Utf8)
]
),
ResponseText = Text.FromBinary(Response, TextEncoding.Utf8),
Parsed = Json.Document(ResponseText),
AccessToken = Parsed[data][access_token]
in
AccessToken