I have successfully developed some code to integrate VB 2008 with the KASHFLOW API but having an issue with the Customer.Update Command. The Program I am taking a Database Table and exporting all the Customer Records. Before Inserting a New Record I am checking for an existing record and if it is present would look to update the appropriate fields. The code to perform Customer.Update is failing with the following error: Conversion from string "" to type 'Integer' is not valid. Code: iResult = uService.UpdateCustomer(sStatus, sStatusDetail, My.Settings.UserName, My.Settings.Password, uCustomer) I have tried inserting this line directly after the Customer Retrieval line so that I am in fact just sending back the data I have just collected and it fails with the same error. I guess my questions therefore come down to what I am missing when updating a record (Insert works just fine). The rest of the code for this subroutine is enclosed below: Code: ' Dimension Local Variables - Database Values Dim sSQL As String Dim uCommand As OleDb.OleDbCommand Dim uReader As OleDb.OleDbDataReader ' Dimension Local Variables - Return Values Dim iResult As Integer Dim sStatus As String = "" Dim sStatusDetail As String = "" ' Dimension Local Variables - Function Call Dim uCustomer As New KashFlowAPIRef.Customer Dim uBinding As New ServiceModel.BasicHttpBinding uBinding.Security.Mode = ServiceModel.BasicHttpSecurityMode.Transport Dim uEndpoint As New ServiceModel.EndpointAddress("https://securedwebapp.com/api/service.asmx") Dim uService As New KashFlowAPIRef.KashFlowAPISoapClient(uBinding, uEndpoint) ' Open Access Data Table - Select Data uConnection.ConnectionString = My.Settings.KASHFLOWConnectionString.ToString sSQL = "SELECT * FROM Customers WHERE Export = 0" uCommand = New OleDb.OleDbCommand(sSQL, uConnection) uConnection.Open() uReader = uCommand.ExecuteReader While uReader.Read() ' Check for Existing Record uCustomer = uService.GetCustomer(sStatus, sStatusDetail, My.Settings.UserName, My.Settings.Password, uReader("SageRef")) ' Define Customer Record uCustomer.CustomerID = 2942720 uCustomer.Code = uReader("SageRef") uCustomer.Name = uReader("ClientName") uCustomer.Contact = uReader("Contact") uCustomer.Address1 = uReader("Address1") uCustomer.Address2 = uReader("Address2") uCustomer.Address3 = uReader("Address3") uCustomer.Address4 = uReader("Address4") uCustomer.Postcode = uReader("Postcode") uCustomer.Telephone = uReader("Telephone") uCustomer.Email = uReader("EMail") uCustomer.ShowDiscount = 0 If uCustomer.CustomerID = 0 Then ' Write New Record iResult = uService.InsertCustomer(sStatus, sStatusDetail, My.Settings.UserName, My.Settings.Password, uCustomer) Debug.Print("Results: " & iResult & " / " & sStatus & " / " & sStatusDetail) Else ' Update Record iResult = uService.UpdateCustomer(sStatus, sStatusDetail, My.Settings.UserName, My.Settings.Password, uCustomer) Debug.Print("Results: " & iResult & " / " & sStatus & " / " & sStatusDetail) End If End While ' Clear Up uConnection.Close() MsgBox("Export New Customers Completed", MsgBoxStyle.OkOnly + MsgBoxStyle.Information)
Are you able to paste the XML that's generated and posted to us. For reference, here is an example of what it should look like. https://securedwebapp.com/api/service.asmx?op=UpdateCustomer
I'm afraid I don't lnow how to gain access to the SOAP output as it is send via the call shown in the code. The part I can't understand is that if I retrieve a customer record using GetCustomer and then post that back as an update it should work. Is there any other tests I can carry out or can you demonstrate how to get the required output. Angus
Similar issue with update customer via API I can add a customer (using classic ASP) but when i update a customer I get a The Customer ID you provided is not valid yet I am using the same customer code to insert ? I am a little confused between customer code and customerid can anyone help ?
The Customer Code cannot be used to manipulate records as it is the human friendly cide you see when looking at the online interface. You can get the Customer ID by passing this customer code to the API. Here is a sample in VB 2008 that I use to check and see if the customer record needs to be added. The Customer ID is the internal ID used within Kashflow for manipulating the end data record. Hope that helps Angus Code: ' Check for Existing Record uCustomer = uService.GetCustomer(sStatus, sStatusDetail, My.Settings.UserName, My.Settings.Password, uReader("ClientID")) ' Define Customer Record If uCustomer.CustomerID = 0 Then uCustomer.Code = uReader("ClientID") uCustomer.Name = uReader("ClientName") uCustomer.Contact = uReader("Contact") uCustomer.Address1 = uReader("Address1") uCustomer.Address2 = IIf(IsDBNull(uReader("Address2")), "", uReader("Address2")) uCustomer.Address3 = IIf(IsDBNull(uReader("Address3")), "", uReader("Address3")) uCustomer.Address4 = IIf(IsDBNull(uReader("Address4")), "", uReader("Address4")) uCustomer.Postcode = IIf(IsDBNull(uReader("Postcode")), "", uReader("Postcode")) uCustomer.Telephone = IIf(IsDBNull(uReader("Telephone")), "", uReader("Telephone")) uCustomer.Mobile = IIf(IsDBNull(uReader("Mobile")), "", uReader("Mobile")) uCustomer.Email = IIf(IsDBNull(uReader("EMail")), "", uReader("EMail")) uCustomer.ShowDiscount = 0 ' Write New Record iResult = uService.InsertCustomer(sStatus, sStatusDetail, My.Settings.UserName, My.Settings.Password, uCustomer) End If