# REST API, Postman, and Excel Power Query Editor

**URL:** <https://www.epiusers.help/t/rest-api-postman-and-excel-power-query-editor/122923>\
**Category:** Kinetic ERP\
**Tags:** e10\
**Created:** [February 4, 2025, 6:39pm UTC](https://www.epiusers.help/t/rest-api-postman-and-excel-power-query-editor/122923 "2025-02-04T18:39:14Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![NateS](https://www.epiusers.help/user_avatar/www.epiusers.help/nates/32/18519_2.png) [@NateS](https://www.epiusers.help/u/NateS)\
**Post date:** [February 4, 2025, 6:39pm UTC](https://www.epiusers.help/t/rest-api-postman-and-excel-power-query-editor/122923/1 "2025-02-04T18:39:14Z")

</div>

I have a BAQ in Epicor with two parameters. I can call it from Postman and Swagger Help without a problem. I can also call it from Postman without a problem. But I cannot get it to work in Power Query Editor from Excel.

I have an API created and the BAQs are assigned to the scope. The scope is applied to the API. I also have an integration user account for just this purpose. I can’t figure out how to replicate my settings from Postman into Power Query Editor.

From Postman:  
Setup with Basic Auth pointing to integration user account.  
Also passing in API key in header:  
x-api-key={{ApiKey}}  
Those start and end dates are also parameters.  
{{Host}}/api/v2/odata/VTAERO/BaqSvc/EarnedHours5/Data?StartDate=‘2025-02-03’&EndDate=‘2025-02-04’

In Excel Power Query Editor I have this code:

```auto
let
    StartDate = Date.ToText(StartDate, "yyyy-MM-dd"),
    EndDate = Date.ToText(EndDate, "yyyy-MM-dd"),
    ApiKey = apikey,
        
    // URL with API Key as query parameter
    URL = "{{MyServer}}/api/v2/odata/VTAERO/BaqSvc/EarnedHours5/Data?startDate=" & StartDate & "&endDate=" & EndDate & "&ApiKey=" & ApiKey,

    // Fetch data using Web.Contents
    Source = Json.Document(Web.Contents(URL)),

    // Assuming the returned data is a JSON array, convert it into a table
    SourceTable = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error),

    #"Changed Type" = Table.TransformColumnTypes(SourceTable, {
        {"LaborDtl_PayrollDate", type date}, 
        {"Calculated_ProdEarnedHours", type number}, 
        {"Calculated_EmpEff", type number}, 
        {"LaborDtl_EarnedHrs", type number}, 
        {"LaborDtl_LaborQty", type number}, 
        {"LaborDtl_BurdenHrs", type number}, 
        {"LaborDtl_LaborHrs", type number}
    })
in
    #"Changed Type"

```

I keep getting “Access to the resource is forbidden.” I have setup the power query data source as basic with the integration account credentials. I also tried it with just the API key. It didn’t like it either way. I must be missing something important.

I can get the data to work if I only use basic auth and use my own creds. But I don’t want to include my cred s in a file I share on the network. Instead, I want anyone that opens it to be able to update the file from Epicor with the built-in creds. I feel like I have done this once before, but I couldn’t find a solution that works.

Thanks for your time!  
Nate

---

<div class="post-metadata">

**Author:** ![CSmith](https://www.epiusers.help/user_avatar/www.epiusers.help/csmith/32/50752_2.png) [@CSmith](https://www.epiusers.help/u/CSmith)\
**Post date:** [February 4, 2025, 6:47pm UTC](https://www.epiusers.help/t/rest-api-postman-and-excel-power-query-editor/122923/2 "2025-02-04T18:47:19Z")

</div>

Try this post

> [@Finally figured out how to tie live BAQ's to Excel!](https://www.epiusers.help/t/finally-figured-out-how-to-tie-live-baqs-to-excel/120779/12):
>
> p function used below: let Source = (paramName) =\> (Excel.CurrentWorkbook(){[Name=paramName]}[Content]{0}[Column1]) in Source API v2 OData request let Headers = [#"Authorization"="Basic " & p("Base64Auth") , #"X-API-Key"=p("x\_api\_key") , #"Content-Type"="text/plain"], paramQuery="BAQ\_Name", Source = OData.Feed(p("Uri\_Protocol") & "://" & p("Server\_FQDN") & "/" & p("Epicor\_Instance") & "/" & "api/v2/odata/" & p("Company") & "/" & p("Servi…

---

<div class="post-metadata">

**Author:** ![NateS](https://www.epiusers.help/user_avatar/www.epiusers.help/nates/32/18519_2.png) [@NateS](https://www.epiusers.help/u/NateS)\
**Post date:** [February 4, 2025, 6:59pm UTC](https://www.epiusers.help/t/rest-api-postman-and-excel-power-query-editor/122923/3 "2025-02-04T18:59:29Z")

</div>

I used the code in that post to modify my code to create the following.

```auto
let
    // Encode Basic Authentication manually (username:password in Base64)
    Base64Auth = "Basic " & Binary.ToText(Text.ToBinary("datapuller:mypassword"), BinaryEncoding.Base64),

    // API Key
    ApiKey = "myapikey",

    // Headers
    Headers = [
        #"Authorization" = Base64Auth,
        #"X-API-Key" = ApiKey,
        #"Content-Type" = "text/plain"
    ],

    // Query Parameter
    paramQuery = "EarnedHours5",

    // Fetch Data
    Source = OData.Feed("https://myserver/api/v2/odata/VTAERO/BaqSvc/" & paramQuery & "/Data?", Headers, [Implementation = "2.0"])
in
    Source

```

But I keep getting the “Please specify how to connect” error and when I click to edit my credentials it brings up the anonymous odata feed connection.

---

<div class="post-metadata">

**Author:** ![CSmith](https://www.epiusers.help/user_avatar/www.epiusers.help/csmith/32/50752_2.png) [@CSmith](https://www.epiusers.help/u/CSmith)\
**Post date:** [February 4, 2025, 7:16pm UTC](https://www.epiusers.help/t/rest-api-postman-and-excel-power-query-editor/122923/4 "2025-02-04T19:16:40Z")

</div>

Only my phone will try looking once not in meetings.

---

<div class="post-metadata">

**Author:** ![kananga](https://www.epiusers.help/user_avatar/www.epiusers.help/kananga/32/80812_2.png) [@kananga](https://www.epiusers.help/u/kananga)\
**Post date:** [February 4, 2025, 7:25pm UTC](https://www.epiusers.help/t/rest-api-postman-and-excel-power-query-editor/122923/5 "2025-02-04T19:25:07Z")

</div>

I’d like to figure this out as well, but… Any credentials that grant access are an entry point, basic auth or API key. Scope can optionally be different between user account and API key, but that would depend on security manager activity.

So, I’ve been setting these things up with integration user accounts, and I don’t grant them access to anything but an access scope. Anyone who tries being clever and logging in with stored credentials won’t get anywhere, but I don’t want employees to potentially waste time finding that out so I paste in the hashed authorization string (looks like, `basic <hashed username and pw>`). For the record - a foolproof way to get that (or check your work) is, log in to your default Swagger instance and snoop through the requests in your browser’s developer tools.

That scopes the basic auth to the same access as the access scope’s API key. A security manager could grant the user account broad access that isn’t accessible to an API key. Not perfect. Could be worse; if a security manager is doing this, you have bigger problems anyway.

Just to pile on, here’s a copy of my own M language starter that I keep up my sleeve.

```auto
_fromDate = Date.ToText(Date.AddDays(Date.EndOfMonth(Date.AddMonths(DateTime.Date(DateTime.LocalNow()), -2)), 1), [Format="MM-dd-yyyy"])
,_throughDate = Date.ToText(Date.EndOfMonth(Date.AddMonths(DateTime.Date(DateTime.LocalNow()), -1)), [Format="MM-dd-yyyy"])
,Source = Json.Document(
    Web.Contents(
        "https://centralusdtapp<server id>.epicorsaas.com/SaaS<instance id>/api/v2/odata/<company number>/BaqSvc"
        ,[
            RelativePath="<baq name>/Data"
            ,Query=[
                FromDate=_fromDate
                ,ThroughDate=_throughDate
            ]
            ,Headers=[
                Authorization="<auth string>"
                , #"X-API-Key"="<key>"
            ]
        ]
    )
)

```

PS - keep an eye on that account’s locked out status, the error is the same for bad auth as it is for locked out!

---

<div class="post-metadata">

**Author:** ![Olga](https://www.epiusers.help/letter_avatar_proxy/v4/letter/o/57b2e6/32.png) [@Olga](https://www.epiusers.help/u/Olga)\
**Post date:** [February 4, 2025, 9:48pm UTC](https://www.epiusers.help/t/rest-api-postman-and-excel-power-query-editor/122923/6 "2025-02-04T21:48:28Z")

</div>

Excel always knows better how OData URL should look like so it rewrites it all the time. You are on prem so you can look in IIS log to find correspondant http call and see how it was changed.

---

<div class="post-metadata">

**Author:** ![jkane](https://www.epiusers.help/user_avatar/www.epiusers.help/jkane/32/57624_2.png) [@jkane](https://www.epiusers.help/u/jkane)\
**Post date:** [February 4, 2025, 9:56pm UTC](https://www.epiusers.help/t/rest-api-postman-and-excel-power-query-editor/122923/7 "2025-02-04T21:56:36Z")

</div>

Can Excel do V2 connections? I thought there was an issue with them?

---

<div class="post-metadata">

**Author:** ![kananga](https://www.epiusers.help/user_avatar/www.epiusers.help/kananga/32/80812_2.png) [@kananga](https://www.epiusers.help/u/kananga)\
**Post date:** [February 4, 2025, 10:11pm UTC](https://www.epiusers.help/t/rest-api-postman-and-excel-power-query-editor/122923/8 "2025-02-04T22:11:47Z")

</div>

V2 is no problem. V1 needs a little massaging since the methods are practically all POST. Power query / Power BI will POST from M but there isn’t an easy button for it that I’ve seen. I haven’t looked very hard though, I write most of my M in the editor.

I leave V1 alone unless there’s no other option. What could go wrong? Imagine intending to read with PUSH syntax and typo’ing in a write endpoint by mistake! Unlikely but not impossible. Completely not an issue in V2 since read methods are GET and the M syntax is explicitly different for GET and POST.

---

<div class="post-metadata">

**Author:** ![CSmith](https://www.epiusers.help/user_avatar/www.epiusers.help/csmith/32/50752_2.png) [@CSmith](https://www.epiusers.help/u/CSmith)\
**Post date:** [February 5, 2025, 9:20am UTC](https://www.epiusers.help/t/rest-api-postman-and-excel-power-query-editor/122923/9 "2025-02-05T09:20:31Z")

</div>

Try this:

 ![image](https://www.epiusers.help/uploads/default/original/3X/9/2/923b9e72b7049596ae8d91f902554ae461057a81.png)

```auto
// p function
let
    Source = (paramName) => (Excel.CurrentWorkbook(){[Name=paramName]}[Content]{0}[Column1])
in
    Source

// ODataCall Info
let
    // Encode Basic Authentication manually (username:password in Base64) : Change appropriately
    Base64Auth = "Basic " & Binary.ToText(Text.ToBinary("datapuller:mypassword"), BinaryEncoding.Base64),

    // API Key : Change appropriately
    ApiKey = "myapikey",

    // Headers
    Headers = [
        #"Authorization" = Base64Auth,
        #"X-API-Key" = ApiKey,
        #"Content-Type" = "text/plain"
    ],

    // Query Name
    paramQuery = "EarnedHours5",

    // Query Parameter(s)
    startDate = if (p("WeekStartDate") = null) then "" else "&startDate="&Date.ToText(DateTime.Date(p("WeekStartDate")),"yyyy-MM-dd") ,
    endDate = if (p("WeekEndDate") = null) then "" else "&endDate="&Date.ToText(DateTime.Date(p("WeekEndDate")),"yyyy-MM-dd") ,

    // Fetch Data with params
    Source = OData.Feed("https://myserver/api/v2/odata/VTAERO/BaqSvc/" & paramQuery & "/Data?" & startDate & endDate, Headers, [Implementation = "2.0"])
in
    Source

```

EDIT: Forgot to say you should have 2 named cells, WeekStartDate and WeekEndDate where you enter parameters. The p() function will grab them from your worksheet.

---

<div class="post-metadata">

**Author:** ![CSmith](https://www.epiusers.help/user_avatar/www.epiusers.help/csmith/32/50752_2.png) [@CSmith](https://www.epiusers.help/u/CSmith)\
**Post date:** [February 5, 2025, 10:59am UTC](https://www.epiusers.help/t/rest-api-postman-and-excel-power-query-editor/122923/10 "2025-02-05T10:59:10Z")

</div>

> [@NateS](#):
>
> “Please specify how to connect”

Global permissions: {Anonymous}  
https ://server/Instance/api/v2/odata  
 ![image](https://www.epiusers.help/uploads/default/original/3X/c/4/c4910f2916d21c62fb15fc156fd8aa0a4999f15c.png)

This should be sufficient to get it working.

---

<div class="post-metadata">

**Author:** ![NateS](https://www.epiusers.help/user_avatar/www.epiusers.help/nates/32/18519_2.png) [@NateS](https://www.epiusers.help/u/NateS)\
**Post date:** [February 5, 2025, 2:20pm UTC](https://www.epiusers.help/t/rest-api-postman-and-excel-power-query-editor/122923/11 "2025-02-05T14:20:12Z")

</div>

Thank you for getting me there! This is what I ended up with:

1. I realized I didn’t need parameters, and just ran the BAQ for a year range.
2. My M code:

```auto
let
    Base64Auth = "Basic " & Binary.ToText(Text.ToBinary("datapuller:MYACTUALPASSWORD"), BinaryEncoding.Base64),
    ApiKey = "MYACTUALAPIKEY",

    Headers = [
        #"Authorization" = Base64Auth,
        #"X-API-Key" = ApiKey,
        #"Content-Type" = "text/plain"
    ],

    paramQuery = "EarnedHours5ThisYear",

    Source = OData.Feed("https://MYACTUALSERVER/api/v2/odata/VTAERO/BaqSvc/" & paramQuery & "/Data?", Headers, [Implementation = "2.0"])
in
    Source

```

1. The data source had to be OData feed, anonymous.
2. I think that pointing the permissions to https ://server/Instance/api/v2/odata was also important.

Initially this didn’t work, but I “Close & Loaded”, and it seems to have connected properly! Awesome!

I also choose to refresh on open, so now as long as the content is enabled, any user should be able to see up to date information when opening the excel file. Thank you so much!

OK. Yeah, I am hard coding both an API key, and user creds into my M code, but I am not a hacker and I don’t know how to do it better! No one here will ever dive deep enough to find those creds, and if they did, I don’t think they could use them for anything nefarious. My user creds are an integration account, so I don’t feel much is at risk. The API key also has an access scope limiting its reach to only a couple of BAQs.

I am happy to leave this solution right here, but I am curious, what could I do better?

---

<div class="post-metadata">

**Author:** ![Evan\_Purdy](https://www.epiusers.help/user_avatar/www.epiusers.help/evan_purdy/32/69101_2.png) [@Evan\_Purdy](https://www.epiusers.help/u/Evan_Purdy)\
**Post date:** [February 5, 2025, 2:33pm UTC](https://www.epiusers.help/t/rest-api-postman-and-excel-power-query-editor/122923/12 "2025-02-05T14:33:16Z")

</div>

> [@NateS](#):
>
> No one here will ever dive deep enough to find those creds, and if they did

If @Mark_Wonsil had any hair left, it would be standing on end. That’s not a very zero trust mindset Nate! 😆

---

<div class="post-metadata">

**Author:** ![jkane](https://www.epiusers.help/user_avatar/www.epiusers.help/jkane/32/57624_2.png) [@jkane](https://www.epiusers.help/u/jkane)\
**Post date:** [February 5, 2025, 2:36pm UTC](https://www.epiusers.help/t/rest-api-postman-and-excel-power-query-editor/122923/13 "2025-02-05T14:36:48Z")

</div>

> [@NateS](#):
>
> My M code

I’m going to bite on this because I am confused. I know M code as being for CNC machines. Is this a different or the same code?

---

<div class="post-metadata">

**Author:** ![NateS](https://www.epiusers.help/user_avatar/www.epiusers.help/nates/32/18519_2.png) [@NateS](https://www.epiusers.help/u/NateS)\
**Post date:** [February 5, 2025, 2:57pm UTC](https://www.epiusers.help/t/rest-api-postman-and-excel-power-query-editor/122923/14 "2025-02-05T14:57:37Z")

</div>

> [@jkane](#):
>
> I know M code as being for CNC machines. Is this a different or the same code?

Yes, they are both called M. M language for power query is also called Power Query Formula Language. While M code for machines is more like instructions.

---

<div class="post-metadata">

**Author:** ![CSmith](https://www.epiusers.help/user_avatar/www.epiusers.help/csmith/32/50752_2.png) [@CSmith](https://www.epiusers.help/u/CSmith)\
**Post date:** [February 5, 2025, 3:45pm UTC](https://www.epiusers.help/t/rest-api-postman-and-excel-power-query-editor/122923/15 "2025-02-05T15:45:20Z")

</div>

I was working on a UserForm version to alleviate that type of security issue only requires VBA macros to be enabled to work properly, just get overloaded sometimes and hard to reach back to less time sensitive items. Too often others’ poor planning becomes my emergency ☹

> [@NateS](#):
>
> 1. The data source had to be OData feed, anonymous.
> 2. I think that pointing the permissions to https ://server/Instance/api/v2/odata was also important.
> 
> Initially this didn’t work, but I “Close & Loaded”, and it seems to have connected properly! Awesome!

You can also start with simple blank query {or even Other Sources \> Web} and you will get the appropriate popups for OData feed security connection type unless you have set them already. You can always adjust using the Data Source settings in the Power Query Editor ribbon. Just select the Global permissions radio button.

Anyways, congrats on getting this working! Glad to assist.
