URL - Functioncall

Hi,

Stupid Question … I’m looking in a few documents, trying to find how to call a function from a URL
The Kinetic REST guide states this:

https://[KineticServer]/[KineticInstance]/api/v2/efx/[Company]/[Library]/[Function]/

which is the same as the Ice Tools:
https://[EpicorServer]/[ERPInstance]/api/v2/efx/[CompanyID]/MyLib/OrderSum

When I am running this (with API key in the URL) I’m just getting back a list of published functions - not the actual data e.g.:
ArrayOfLibraryDescription xmlns:i=“http://www.w3.org/2001/XMLSchema-instance” xmlns=“http://schemas.datacontract.org/2004/07/Epicor.RESTApi.Functions”>

Bank Adjustment

BankAdjustment

CASBundle

BAQ’s work fine.
Anyone got any ideas what I am doing wrong?

Many thanks

Mark

Are you testing this in Swagger or some other method? I suggest accessing the Swagger help system at http://[KineticServer]/[KineticInstance]/api/help/v2

You can test the REST operation of your function there. It’s helped me out a bunch.
For example, I have a function that is called from our Salesforce instance to get the price per unit for a part from Kinetic. Swagger lets me test that function by filling in the payload and the API key.

When executed, it displays the Curl command used as well as the response body and response headers.

2 Likes

Thanks - It worked OK in swagger. Managed to get round it by running a BAQ that in turn runs a function.

Hi Mark.
How do you run a BAQ that runs a function?
How is that possible?

Advanced BPM on the Updatable BAQ.

Run it on get list.

Note that the function URL will change when the library is demoted or promoted. When in the demoted state there is a /staging/ in the path

https://[KineticServer]/[KineticInstance]/api/v2/efx/staging/[Company]/[Library]/[Function]/

This gets me all the time.
Brett

Thanks for replying @aarong and @bmanners . Perhaps I should expand a bit more about my need. I have a function that returns a Dataset and I wanted to invoke it from Excel using OData but that didn’t work. I am trying to find an alternative to this and thought that if a BAQ can run a function then maybe I can create a BAQ that can be called from Excel.
Do you think this is a good alternative or do you have other ideas that I should explore?
Thank you for your time!

Are you wanting to pass parameters to your function?

That is cool! I had just assumed demote functions were not available at all. So, I can setup a whole proper test without promoting my function, until it actually works properly!? What a crazy idea! :stuck_out_tongue:

No, I don’t need to pass parameters. The function runs a couple of BAQs to create a table with data and returns it.

Returns it back to excel?? Are you going to call the function via a button etc?

Yes, I want to create a button in Excel that uses OData to invoke the function and displays the result.
I’ve done this with BAQs and it works fine, but it doesn’t seem to work with functions.

Can you try?

Sub FetchAPIData()
    Dim url As String
    Dim req As Object
    Dim json As String
    Dim ws As Worksheet
    Dim apiKey As String

    ' Set the API endpoint URL
    url = "https://api.example.com/data"

    ' Set your API key
    apiKey = "your_api_key_here"

    ' Create an HTTP request
    Set req = CreateObject("MSXML2.ServerXMLHTTP")
    req.Open "POST", url, False
    req.setRequestHeader "Content-Type", "application/json"
    req.setRequestHeader "Authorization", "Basic " & Base64Encode("username:password") ' Replace with your credentials
    req.setRequestHeader "X-API-Key", apiKey ' Add the API key header

    ' Send the request
    req.send

    ' Get the response
    json = req.responseText

    ' Load data into Sheet2
    Set ws = ThisWorkbook.Sheets("Sheet2")
    ws.Cells.Clear
    ws.Cells(1, 1).Value = json ' Assuming the entire response is a JSON string

    ' Clean up
    Set req = Nothing
End Sub

Function Base64Encode(ByVal sText As String) As String
    Dim arrData() As Byte
    arrData = StrConv(sText, vbFromUnicode)
    Base64Encode = Application.EncodeBase64(arrData)
End Function

I’m no excel wizard but this uses similar request to C#

2 Likes

Thanks @aarong ! Your code was just what I needed. I had to modify a couple of things like replacing MSXML2.ServerXMLHTTP with MSXML2.XMLHTTP.6.0 and typing my Authorization credentials instead of using the Base64Encode function.
I owe you one. :smiley:

1 Like