Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating payments using OAuth2 results in a 500 #67

Closed
synotio opened this issue Feb 2, 2017 · 1 comment
Closed

Creating payments using OAuth2 results in a 500 #67

synotio opened this issue Feb 2, 2017 · 1 comment
Labels

Comments

@synotio
Copy link

synotio commented Feb 2, 2017

If you issue a CreatePayment using the following method:

HarvestRestClient _client = new HarvestRestClient(subDomain, email, password);
_client.CreatePayment(invoiceId, invoiceAmount, DateTime.Now);

That will work normally. However, if you do:

HarvestRestClient _client = new HarvestRestClient(subDomain, clientId, clientSecret, clientToken);
_client.CreatePayment(invoiceId, invoiceAmount, DateTime.Now);

That will fail with a 500 response from harvest due to the way that RestSharpFactory.cs constructs the RestClient, more specifically the ParameterType of access_token. Since access_token is set to be GetOrPost, this will result in the whole request being thrown away and the RequestBody will instead just contain access_token=<token>

According to the RestSharp documentation:

If you have GetOrPost parameters as well, they will overwrite the RequestBody – RestSharp will not combine them but it will instead throw the RequestBody parameter away.

We can test a solution to this this using reflection by setting ParameterType to QueryString:

HarvestRestClient _client = new HarvestRestClient(subDomain, clientId, clientSecret, clientToken);

var cli_field = typeof(HarvestRestClient).GetField("_client", BindingFlags.NonPublic | BindingFlags.Instance);

RestClient _iclient = (RestClient)cli_field.GetValue(_client);
_iclient.DefaultParameters.Where(p => p.Name == "access_token").First().Type = ParameterType.QueryString;

_client.CreatePayment(invoiceId, invoiceAmount, DateTime.Now);

And now it works :)

@ithielnor
Copy link
Owner

Cool beans! Will be in the next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants