Forum Discussion
Easy POST requests with Power BI and Power Query using Json.FromValue - Errors
Dear ImkeF,
With reference to your topic in your blog: "Easy POST requests with Power BI and Power Query using Json.FromValue" - https://www.thebiccountant.com/2018/06/05/easy-post-requests-with-power-bi-and-power-query-using-json-fromvalue/#comment-2938
Firstly thank you the great help with this!
I seem to be getting some issues with my solution:
let
Source = (Records) =>
let
Key = “{API Key}”, //this is the API for the live environment
CompanyID = “XXXXXX”, //this is the company code
Method = “DetailedLedgerTransaction”, //this is from the Sage Accounting API Specification
WebAddress = “https://accounting.sageone.co.za/api/2.0.0/”, //This is the webaddress for the live environment
url = Json.Document(Web.Contents(WebAddress & Method & “/Get?apikey=” & Key & “&CompanyID=” & CompanyID)),
header = [#”Content-Type”=”application/json”,#”Accept”=”application/json”], //not sure about this header???
body = Json.FromValue([ Inactive = [ true ], Active = [ true ], FromAccount = {“”}, ToAccount = {“”}, IncludeNoTax = [ true ], FromDate = {“2021-12-30”}, ToDate = {“2021-12-30”}]),
Source = Json.Document(Web.Contents(url,[Headers = header,Content=body])
in
Source
in
Source
I get a "not allowed" error.
Any idea why I might be getting this?
Thanks in advance!
6 Replies
- AnonymousNot applicable
Hi Ryan_OC ,
//I get a "not allowed" error.
Could you please post the full error message?
Best Regards,
Gao
Community Support TeamIf there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!
How to get your questions answered quickly -- How to provide sample data
- Ryan_OCHelper I
Hi Gao,
The error message is as such:
An error occurred in the ‘Query1’ query. DataSource.Error: Web.Contents failed to get contents from 'https://accounting.sageone.co.za/api/2.0.0/DetailedLedgerTransaction/Get?apikey={API KEY}&CompanyID={Company ID}' (405): Method Not Allowed
Details:
DataSourceKind=Web
DataSourcePath=https://accounting.sageone.co.za/api/2.0.0/DetailedLedgerTransaction/Get
Url=https://accounting.sageone.co.za/api/2.0.0/DetailedLedgerTransaction/Get?apikey={API KEY}&CompanyID={Company ID}Does this help?
- Ryan_OCHelper I
- ImkeFCommunity Champion
Hi Ryan_OC ,
I am surprised about all the hightlighted brackets in your code. Usually, I would expect to see "simple" strings in those positions:let
Source = (Records) =>
let
Key = “{API Key}”, //this is the API for the live environment
CompanyID = “XXXXXX”, //this is the company code
Method = “DetailedLedgerTransaction”, //this is from the Sage Accounting API Specification
WebAddress = “https://accounting.sageone.co.za/api/2.0.0/”, //This is the webaddress for the live environment
url = Json.Document(Web.Contents(WebAddress & Method & “/Get?apikey=” & Key & “&CompanyID=” & CompanyID)),
header = [#”Content-Type”=”application/json”,#”Accept”=”application/json”], //not sure about this header???
body = Json.FromValue([ Inactive = [ true ], Active = [ true ], FromAccount = {“”}, ToAccount = {“”}, IncludeNoTax = [ true ], FromDate = {“2021-12-30”}, ToDate = {“2021-12-30”}]),
Source = Json.Document(Web.Contents(url,[Headers = header,Content=body])
in
Source
in
Source