Forum Discussion

Ryan_OC's avatar
Ryan_OC
Helper I
3 years ago

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

  • ImkeF's avatar
    ImkeF
    Community Champion

    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.

  • Anonymous's avatar
    Anonymous
    Not applicable

    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

  • ImkeF's avatar
    ImkeF
    Community 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

     



    • Ryan_OC's avatar
      Ryan_OC
      Helper I

      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