MYOBCommunity
Partner Zone
|
|
Partner Zone

Unable to connect MYOB AccountRight online file

4 REPLIES
MYOB Staff Post DeveloperJack
141 Posts
MYOB Staff Post
Australia
DeveloperJack
MYOB Staff Post

141Posts

30Kudos

21Solutions

Re: Unable to connect MYOB AccountRight online file

Hi there @Passfield,

I'd recommend reaching out to developers@myob.com for some support here. We'll need to know your API key (keep that one secret) and any screenshots/HTTP logs you have.

Cheers,

Jack

Jack Skinner
MYOBapi Evangelist

Are you a developer? Check out http://developer.myob.com
Looking for an Add-on? Check out http://myob.com/addons/
Experienced Partner Passfield
11 Posts
Experienced Partner
United Kingdom
Passfield
Experienced Partner

11Posts

3Kudos

2Solutions

Re: Unable to connect MYOB AccountRight online file

I am using the following code:

CompanyFile[] companyFileList = null;
IApiConfiguration configurationCloud = null;

configuration = null;
// Set up initial MYOB connection, and create and save the tokens
configurationCloud = new ApiConfiguration(main.CompanySettings["DevCode"], main.CompanySettings["DevSecret"], "http://desktop");

 

oAuthKeyService = new SimpleOAuthKeyService();

var oauthService = new OAuthService(configurationCloud);
var tokens = oauthService.GetTokens(OAuthLogin.GetAuthorizationCode(configurationCloud));
oAuthKeyService.OAuthResponse = tokens;

 

// Load all files from cloud
var cfsCloud = new CompanyFileService(configurationCloud, null, oAuthKeyService);
companyFileList = cfsCloud.GetRange();

 

The windows pops up to login and I correctly enter the username and password.

I have generated a developer key and secret.  First I just generated one from my developer account, but then I also generated one from the client account (the one I used to log into).  In both cases I got the attached error.  In generating the developer key I used http://desktop as the redirect and tried both the original filename and the product name

CropperCapture[91].jpg
MYOB Staff Post DeveloperJack
141 Posts
MYOB Staff Post
Australia
DeveloperJack
MYOB Staff Post

141Posts

30Kudos

21Solutions

Re: Unable to connect MYOB AccountRight online file

Hi there @Passfield,

We have a C# and a VB.NET sample that may help you better understand how to use the SDK to complete Oauth. If you're implementing it from scratch in your own application, the high-level steps (for a desktop app) are:

 - First, open a browser window to the auth token URL with the appropriate query string params

 - For http://desktop redirect url, wait for the window to refresh and the code will be in the <title>?code=ACCESSCODE</title> tags. For web applications (i.e. not http://desktop) it will be a query string param

 - Use that code to make an HTTP POST to the access token URL.

 - Store that access token (along with the refresh token you get back) securely within your application.

 

Details on the exact params required are on this authentication documentation page.

 

I'd definitely recommend checking out the .NET code samples for a reference on how to use the OAuth classes from the SDK.

 

Hope this helps!

Cheers,

Jack

Jack Skinner
MYOBapi Evangelist

Are you a developer? Check out http://developer.myob.com
Looking for an Add-on? Check out http://myob.com/addons/
Partner PabloInNz
1 Post
Partner
PabloInNz
Partner

1Posts

0Kudos

0Solutions

Re: Unable to connect MYOB AccountRight online file

Is this code running in a browser ?

I have just recently gone though this using MVC and I struggled to understand what was going on too. Initially you need to register a redirect url. In this case, I'm testing locally in Visual studio so I registered a local host address. This url is called when someone logs on and passes back the code.

Code snippets from my initial test set up as below should help you. The entry point is GetuserAccessCode which then redirects to MYOB where you enter your login and password. This then redirects to the url you specified and passes in the code. You use this code to get the access token. 

 

private const string AuthServerUri = "https://secure.myob.com/oauth2/account/authorize/";
private const string RedirectUrl = "http://localhost:12345/GetUserAccessTokens";
private const string AuthScope = "CompanyFile";
private const string DeveloperKey = "xxxxxxxxxxxxxxx";
private const string DeveloperSecret = "xxxxxxxxxxxxxxx";

/// <summary>
/// Redirect to the MYOB page so the Customer can log on to their page.This then redirects back to the url we specified
/// with an access code. This code is then used to get initial AccessTokens.
/// <returns></returns>
public ActionResult GetUserAccessCode()
{
	//note that the "state" parameter is used to pass additional info that will come back from the OAuth 
	//http://myobapi.tumblr.com/post/60294451539/passing-state-via-oauth
	
	string url = string.Format("{0}?client_id={1}&redirect_uri={2}&scope={3}&response_type=code&state={4}", AuthServerUri, DeveloperKey, HttpUtility.UrlEncode(RedirectUrl), AuthScope, HttpUtility.UrlEncode(<stuff you want to pass through>));
	return Redirect(url);
	
}
public async Task<ActionResult> GetUserAccessTokens(string code, string state)
{
	string result;
	try
	{
		OAuthService oauthService = CreateOAuthService();
		OAuthTokens token = await oauthService.GetTokensAsync(code);
		result = "An access token has been stored successfully and the api can now be used.";
	}
	catch (Exception ex)
	{
		result = String.Format("An error occurred getting or stroing the access token. The Api cannot be used until this is fixed.</br>Error:{0}", ex.GetBaseException().Message);
	}
	return Content(result);
}

 

 

Experienced Partner Passfield
11 Posts
Experienced Partner
United Kingdom
Passfield
Experienced Partner

11Posts

3Kudos

2Solutions

Unable to connect MYOB AccountRight online file

I am using VS2010 and have installed the 2016.2.99 SDK.  I have a developer code and developer secret, but I am not sure how I go about getting the code with which to generate the token.  From the readme.txt file there is:

 

2. Get an code via the browser to allow your application to access your customer's Company File(s)

var code = ....; // from browser bode (http://desktop) or request string during redirect

 

followed by:

var configuration = new ApiConfiguration("<<appid>>","<<appsecret>>","<<appredireturl>>");
var oauthService = new OAuthService(configuration);
var tokens = oauthService.GetTokens(code);

 

Please could someone tell me how to get a code or where it is displayed.

 

Thanks a lot

Didn't find your answer here?
Try using advanced search to find a post more easily Advanced Search
or
Get the conversation started and make a new post Start a Post