Xero - beautiful accounting software

Xero Developer Help Center

Xero Developer Community

Community > Wrapper libraries >

Potential Issue with Wrapper when setting Contact Discount field

Started by Edward Re -   in Wrapper libraries

Hi All,

I am using the latest version of the C# Xero Wrapper and I have been unable to set the Discount field for a new or an existing Contact.

Whilst the Wrapper can successfully read the Discount value, it seems unable to set the value for this field when the Contact is created or Updated.

As I will be migrating a large number of Contacts into Xero, it is important for me to be able to set the Discount field programmatically to avoid doing this manually for the many Contacts.

Any Assistance would be greatly appreciated

Hi Edward,

I would friendly advise you to send an email as the forum is not checked frequently by them. it is network@xero.com.

However, my request would be that which library are you using and If the one has included the XeroAPIHelper class , could you please tell me how do you establish your connection through Xero and then how to import/export your items?

I am trying to find out the right solution for my project to implement and start asap

Appreciate your time & help.
 

Duncan Grant  

Hi Mehmet,

I use the Xero API SDK (Minimal) library from NuGet and Visual Basic

If you require professional assistance I recommend Henzard (see below contact details) whom has helped me before at a very honest hourly rate. I don't feel I should offer you advice when I am not a Xero API expert .

Kind Regards

Edward

========= Xero Consultant =======
Henzard Kruger
Certified Advisor and API developer
Picahoo cc - 0711304241 - henzard@picahoo.co.za
Skype: henzard, Gtalk: henzardkruger@gmail.com
Quality is remembered long after the price is forgotten
 

Edward Re  

Hi Edward,

I appreciate your advise.

Could you please highlight the address link that you've taken the API library?
thank you
 

Duncan Grant  

Hi Mehmet,

The library is installed as a reference in Visual Basic using a feature called NuGet. NuGet allows you to search for libraries with, let's say, the keyword "Xero" and it will show all current and older libraries. You can then click and automatically install the Xero API SDK library automatically. In the past, when this NuGet was not available you had to download the library DLL from the server (in this case Xero) and create a reference in your Visual Basic/C# project.

Hope it helps.
 

Edward Re  

Hi Edward,

Thank you very much for the detail. I am aware of NuGet. I have actually taken the dll from the website. I wanted to compare whether I am using an incorrect version.
Their sample is based on a mvc project and the most authentication method and creation/list methods are written based on that purpose. Whereas we are implementing this structure in web forms project. It is where we are struggling at.
 

Duncan Grant  

Hi Mehmet,

Is there a reason you are not using NuGet? It is part of the Microsoft Development Environment. Allow me to say, and I could be wrong, but it seems to me you are programming using the 'Old' ways. Also, do you use VB or C# ?
 

Edward Re  

Hi Edward,

I understand your point. The reason why I am doing "the old ways" is because I was referred to go to this "https://github.com/XeroAPI/Xero-Net" website and investigate the solution. That has the samples how to establish the integration, how to create / how to list etc. For a person who doesn't know about their API methods, I guess, It is a good sample to look at , however, it is based on MVC and the structure is slightly different. It is not related to the knowledge of knowing MVC or not, it is more related to the structure how they've built in the sample.
 

Duncan Grant  

you are right, the Xero-Net code is good to see the available classes.

if you need some sample VB code to connect to Xero and create a product/item you can refer to my earlier post being:-
https://community.xero.com/developer/discussion/9282954/

 

Edward Re  

Hi Edward,

Thank you for that. However, I am struggling to generate the redirect URL within the sample that I have mentioned about.
There is a return string URL which comes out of "GetRequestTokenAuthorizeUrl" class, however, it is MVC Authentication. I couldn't have been find the method which returns me a redirect URL for the public Authentication. There is a class "PublicAuthenticator" as well as "XeroApiHelper" however, I couldn't implement into my solution yet.
 

Duncan Grant  

Hi Edward,

Regarding the authentication url , any chance to show me a snippet code which generates the authentication url and redirects the person through Xero ? as you mentioned the approach of creating the session
https://community.xero.com/developer/discussion/9282954/

The reason i am asking is because the mvc sample doesn't allow me to generate the authentication URL for web forms.

I appreciate your assistance.
 

Duncan Grant  

Hi Mehmet,

I am not sure if I truly understand your question, but I will take a guess.

I use the wrapper which shields you from the url in question. You are possibly thinking of passing an XML as endpoint to perform a GET, PUT or POST. The wrapper uses it's own object constructs, if you look at the discussion I sent you earlier that's the way I create a session with Xero and how I create a new Item as such:-

Dim sResult As Xero.Api.Core.Model.Item
NEW ITEM
Dim uItem As New Xero.Api.Core.Model.Item
uItem.Id = Guid.NewGuid()
uItem.Code = "1A"
uItem.Description = "test description"
sResult = xSession.Create(uItem)

now, the Xero.Api.Core.Model has other objects to create contacts, Invoices etc etc etc. etc. Maybe you need to paste the code I gave into a new project, create a reference to the latest Xero Wrapper and start playing with the above objects.

If I am still not answering your question is because I am not an expert in Xero API matters, and perhaps you should seek a Xero expert by either contacting Henzard whom I recommend, or posting a request for a Developer/Consultant in the Community.

Alternatively, you can try to get your answers from Xero.

I hope it helps.

 

Edward Re  

Hi Edward,

I appreciate that you've taken your time for my question. However, my question wasn't really that.

I have come across 2 different approach how to gather the authentication from Xero over the internet, therefore I ended up integrating the wrapper solution in my project, however, I am working on web forms and I cannot see any solution in the software how to generate the authentication URL.

For instance:

public ActionResult Connect()
{
var authorizeUrl = _authenticator.GetRequestTokenAuthorizeUrl(_user.Name);

return Redirect(authorizeUrl);
}

This is how to connect through Xero with the "IMvcAuthenticator" library.

When it comes to connect via PublicAthenticator , I couldn't make it.

What I am doing is in web form:

SessionManager.XeroSession = XeroManager.GetCurrentSession();
dynamic callbackUri = new UriBuilder(Request.Url.Scheme, Request.Url.Host, Request.Url.Port, "company.aspx");
RequestToken token = SessionManager.XeroSession.GetRequestToken(callbackUri.Uri);
string authorisationUrl = SessionManager.XeroSession.GetUserAuthorizationUrl();
Response.Redirect(authorisationUrl);

This is a completely different structrue.

Plus, creating invoices or retrieving the informations, I do this:

Repository rep = SessionManager.XeroRepository;
//then create invoices or retrieve items etc.

So, I want to replace all these with the solution what is provided in GitHub.

Hope this makes sense and much more clear.
 

Duncan Grant  

Hi Mehmet,

Will you connect to Xero as a Private, Public or Partner ?
 

Edward Re  

Hi Edward,

Public at this stage.
 

Duncan Grant  

Hi Edward,

Any chance to have a chat with you via email or phone ?
I really appreciate that.
 

Duncan Grant  

Hi Mehmet,

I am trying to keep all of my Xero related activities in the open, maybe you can post the matter here?
 

Edward Re  

Hi Edward,

I understand that.

I have already posted my matter related to the first approach of gathering the autherization using the wrapper solution in web forms.

I have come across 2 different approach how to gather the authentication from Xero over the internet, therefore I ended up integrating the wrapper solution in my project, however, I am working on web forms and I cannot see any solution in the software how to generate the authentication URL.

For instance:

public ActionResult Connect()
{
var authorizeUrl = _authenticator.GetRequestTokenAuthorizeUrl(_user.Name);

return Redirect(authorizeUrl);
}

This is how to connect through Xero with the "IMvcAuthenticator" library.

When it comes to connect via PublicAthenticator , I couldn't make it.

What I am doing is in web form:

SessionManager.XeroSession = XeroManager.GetCurrentSession();
dynamic callbackUri = new UriBuilder(Request.Url.Scheme, Request.Url.Host, Request.Url.Port, "company.aspx");
RequestToken token = SessionManager.XeroSession.GetRequestToken(callbackUri.Uri);
string authorisationUrl = SessionManager.XeroSession.GetUserAuthorizationUrl();
Response.Redirect(authorisationUrl);

This is a completely different structrue.

Plus, creating invoices or retrieving the informations, I do this:

Repository rep = SessionManager.XeroRepository;
//then create invoices or retrieve items etc.



I have also mentioned the issue as:

I am using the public authentication at the moment which creates some issues such as once the user logs in my web app, then i have to navigate him through the xero website for the authentication and then I am able to import/export whatever the user wants including creating invoices, however, I cannot re-initialize the connection if the user logs out in my system and logs in back within 5 minute.

 

Duncan Grant  

Hi Mehmet,

I understand your issue but don't know how to help. Sorry!
 

Edward Re  

Hi Edward

As per the API documentation (http://developer.xero.com/documentation/api/contacts/) Discount is a read only field.

Thanks for your question.
Phil Alsford
API Team
 

Phil Alsford (Xero Staff)  

no worries I hadn't seen the read only property.

thanks
 

Edward Re