getting Started with the webapi

Posted By polychromenz Thu 29 May 2014
Add to Favorites0
Author Message
polychromenz Marked As Answer
 Posted Tue 10 Jun 2014
Supreme Being

Supreme Being - (6,490 reputation)Supreme Being - (6,490 reputation)Supreme Being - (6,490 reputation)Supreme Being - (6,490 reputation)Supreme Being - (6,490 reputation)Supreme Being - (6,490 reputation)Supreme Being - (6,490 reputation)Supreme Being - (6,490 reputation)Supreme Being - (6,490 reputation)

Group: Forum Members
Last Active: Thu 21 Sep 2017
Posts: 13, Visits: 179
Please add a reply if this is helpful and i'll post more as I build it

I managed to build the tblElements in a helper class but unfortunately when I send it to the webapi it doesn't arrive. I cant spend too much more time on that so I may come back to it but for now I had to change direction. i have added helper classed of my own that take the hassle out of syncing categories to Kartis (attached). One for the sync application to simplify the web api use and to automate validation via the api key and creating the parameters as XML strings. Two other classes that are added to the Kartris project. I spilt these out to make updating easier, CategoriesHelperBLL could have been added to the main CategoriesBLL class but then updating is a pain.

This sync handles multi language poorly as it will just insert the same text for each language. Ideally it would accept a language ID and you call it for each language.

The aim is to sync categories, products, customers and to collect new orders to integrate to a desktop accounting solution. I have categories working (maybe needs some error handling). You are welcome to use the code in you projects supplied AS IS.

Here is how to use this, most of the
  • add KartisHelper to your VB project
  • add KartrisWebHelperBLL to the BLL folder in Kartris
  • add CategoriesHelperBLL to the BLL folder in Kartris
To sync categories you want to iterate your categories in your source

This is obviously specific to my application but should be easy to change to suit your system. Key thing is to create a list of KartisXMLParm and add the items to match the function you are calling in the Kartris BLL. In this case we are calling the new CategoriesHelperBLL.SyncCategory which just takes the Category code and description. It sets defaults for everything because that's what I want but you can change that if you want.

Public Function PublishToWeb() As Boolean

Dim PROCategories As New PolyPRO45.PROStockCategories(APRO_ProgramFolder, APRO_DataFolder)

For Each Cat As PolyPRO45.SAGROUP In PROCategories.PROStockCategories

If Cat.Code <> "" Then

Dim result As String

Dim xmlParms As New List(Of KartrisXMLParm)

xmlParms.Add(New KartrisXMLParm With {.Name = "pCatCode", .Type = "String", .Value = Cat.Code})

xmlParms.Add(New KartrisXMLParm With {.Name = "pCatDescription", .Type = "String", .Value = Cat.Description})

result = KartrisHelper.CallWebMethod("CategoriesHelperBLL.SyncCategory", xmlParms)

End If

Next

PROCategories = Nothing

Return True

End Function
 KartrisHelpers.zip (3 views, 2.65 KB)
Tue 10 Jun 2014 by polychromenz
polychromenz
 Posted Wed 4 Jun 2014
Supreme Being

Supreme Being - (6,490 reputation)Supreme Being - (6,490 reputation)Supreme Being - (6,490 reputation)Supreme Being - (6,490 reputation)Supreme Being - (6,490 reputation)Supreme Being - (6,490 reputation)Supreme Being - (6,490 reputation)Supreme Being - (6,490 reputation)Supreme Being - (6,490 reputation)

Group: Forum Members
Last Active: Thu 21 Sep 2017
Posts: 13, Visits: 179
That example relies on a few application settings just to make it easier for me to post the sample, you might not want your main login and password and api key in the config file but for the example i hope it helps someone.
polychromenz Marked As Answer
 Posted Wed 4 Jun 2014
Supreme Being

Supreme Being - (6,490 reputation)Supreme Being - (6,490 reputation)Supreme Being - (6,490 reputation)Supreme Being - (6,490 reputation)Supreme Being - (6,490 reputation)Supreme Being - (6,490 reputation)Supreme Being - (6,490 reputation)Supreme Being - (6,490 reputation)Supreme Being - (6,490 reputation)

Group: Forum Members
Last Active: Thu 21 Sep 2017
Posts: 13, Visits: 179
Whilst that answers my question i'd like to share some code to make life MUCH easier for anyone else new here.

Start by making a reference to the service \protected\KartrisWebAPI.svc

Then I have a helper class that I have shared here (you'll need to rename that to KartrisHelper.vb)

Called a follows
Dim xmlParms As New List(Of KartrisXMLParm)

' vbs example "<Parameter Name=""numTaxID"" Type=""Byte""><Value>2</Value></Parameter>"

' becomes

xmlParms.Add(New KartrisXMLParm With {.Name = "numTaxID", .Type = "Byte", .Value = 2})

Dim result As String = KartrisHelper.CallWebMethod("TaxBLL.GetTaxRate", xmlParms)

Debug.Print(result)
 KartrisHelper.txt (3 views, 2.85 KB)
Wed 4 Jun 2014 by polychromenz
Paul Marked As Answer
 Posted Fri 30 May 2014
große Käse

große Käse - (522,712 reputation)große Käse - (522,712 reputation)große Käse - (522,712 reputation)große Käse - (522,712 reputation)große Käse - (522,712 reputation)große Käse - (522,712 reputation)große Käse - (522,712 reputation)große Käse - (522,712 reputation)große Käse - (522,712 reputation)

Group: Administrators
Last Active: Tue 10 Sep 2024
Posts: 807, Visits: 2,748
It's an http request header that you need to add, for example in our .vbs script there is this:

xmlhttp.setRequestHeader "Authorization", strKartrisWebAPIKey


This is not a SOAP header, which is values written into the XML. It's a header written into the HTTP request itself.

This link below will help... it is possible to write these in .NET too:

http://blogs.msdn.com/b/wsdevsol/archive/2014/02/07/adding-custom-messageheader-and-http-header-to-a-wcf-method-call.aspx

The C# they have converted looks like this

Dim client As New CalculatorServiceClient()

Using New OperationContextScope(client.InnerChannel)

' Add a HTTP Header to an outgoing request
Dim requestMessage As New HttpRequestMessageProperty()
requestMessage.Headers("MyHttpHeader") = "MyHttpHeaderValue"

OperationContext.Current.OutgoingMessageProperties(HttpRequestMessageProperty.Name) = requestMessage
End Using


--
If my post solves your issue, can you 'Mark as Answer' so it's easier for other users to find in future.

If you would like to be informed of new features, new releases, developments and occasional special bonuses, please sign up to our mailing list: http://bit.ly/19sKMZb
polychromenz
 Posted Thu 29 May 2014
Supreme Being

Supreme Being - (6,490 reputation)Supreme Being - (6,490 reputation)Supreme Being - (6,490 reputation)Supreme Being - (6,490 reputation)Supreme Being - (6,490 reputation)Supreme Being - (6,490 reputation)Supreme Being - (6,490 reputation)Supreme Being - (6,490 reputation)Supreme Being - (6,490 reputation)

Group: Forum Members
Last Active: Thu 21 Sep 2017
Posts: 13, Visits: 179
I'm new to Kartris and pretty new to using webapis.

I think I have the basics clear in my head now but I need some help.

I made a reference to the service and created an instance. I can see how to call the execute method and use it to BLL methods etc. that all makes sense.

How do I login and how do I pass my APIKey?

My code is something like this but where do I set the API key?

If I run this the strResult will return "Sorry. Cant authenticate request!"

Private Function CallWebMethod(MethodName As String, ParametersXML As String)

'Use the web service

Dim myKart As New svcKartris.KartrisWebAPIClient

'Login

Dim strLogin As String = "<Parameter Name=""UserName"" Type=""String""><Value>Admin</Value></Parameter>"

strLogin += "<Parameter Name=""Password"" Type=""String""><Value>TestPassword</Value></Parameter>"

Dim strResult As String = ""

strResult = myKart.Execute("LoginsBLL.Validate", strLogin)

strResult = myKart.Execute(MethodName, ParametersXML)

Debug.Print(strResult)

End Function
Thu 29 May 2014 by polychromenz

Similar Topics

Expand / Collapse

Reading This Topic

Expand / Collapse

Back To Top