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
Ryan_OC
Helper I
Helper I

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-jso... 

 

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 6
ImkeF
Super User
Super User

Hi @Ryan_OC 
that depends on the specifications of your API / which endpoint you want to address. 
You have to look that up in our API documentation.

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

ImkeF
Super User
Super User

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

 



Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

Thanks @ImkeF. To Be honest, I'm not sure about them at all... perhaps thats why I'm getting the errors? 

What would you expect to see?

 

Thanks

v-cgao-msft
Community Support
Community Support

Hi @Ryan_OC ,

 

//I get a "not allowed" error.

Could you please post the full error message?

 

Best Regards,
Gao

Community Support Team

 

If 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

Hi Gao, 

 

Any response here... I'm pretty desperate! 

 

@ImkeF Any chance you could weigh in here... ?

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?

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
Top Kudoed Authors