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.
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!
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!
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.
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#
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.