davidlumley / myob-api Goto Github PK
View Code? Open in Web Editor NEWInterface for accessing MYOB's AccountRight Live API
License: MIT License
Interface for accessing MYOB's AccountRight Live API
License: MIT License
Hi Guys.
Thanks for going to the effort of getting this gem going - hoping to help out as my skills improve.
Not an issue as such, just a Ruby newbie trying to find out if I can use the gem to pull data out of local MYOB files (via a Ruby script, not using Oauth/online site for callbacks)?
I can't quite get my head around how to initialise the API client via Myob::Api::Client.new if not using consumer secret/keys + tokens (does it matter?) to then be able to get through to the select_company_file method which looks like it reverts back to base64 username/password if a token doesn't exist (which is what I think I need to connect to the local file).
Is it a matter of using an empty :access_token to then trigger the base64 user/password? (Apologies, not at my windows machine at this point, just had the thought while typing the issue up!).
Any help much appreciated (or if I'm on the wrong track altogether),
Liam
class MyobSessionsController < ApplicationController
def new
redirect_to myob_client.get_access_code_url
end
def create
@token = myob_client.get_access_token(params[:code])
@company_files = myob_client.company_file.all
# then show the user a view where they can log in to their company file
end
def myob_client
@api_client = Myob::Api::Client.new({
:consumer => {
:key => "u6785eurqcjv6wawgby7b3ag",
:secret => "VmCkQxrMJwefmf5XYwKD5Zv7",
},
})
end
end
routes
resources :myob_sessions
match "myob" => "myob_sessions#new", as: :myob_sessions_new, via: [:get, :post]
localhost:3000/myob
goes to myob login screen
then returns this screen
Your authorised applications
Allow access to your MYOB Account?
We have encountered some issue with the request, please try again later or contact your app support
invalid_request
My registered apps
https://my.myob.com.au/Bd/pages/DevAppList.aspx
Application: mml
Key Secret Redirect Uri Usage (last 24 hr) Quota Limit Throttle Limit Action
u6785eurqcjv6wawgby7b3ag VmCkQxrMJwefmf5XYwKD5Zv7 http://desktop 2 5000 per day 2 per second Edit
What am i missing here?
I am new to GitHub and Ruby is new for me, I am confused with API Client Setup.
I got all detail for;
api_client = Myob::Api::Client.new({
:consumer => {
:key => YOUR_CONSUMER_KEY,
:secret => YOUR_CONSUMER_SECRET,
},
:access_token => YOUR_OAUTH_ACCESS_TOKEN,
:refresh_token => YOUR_OAUTH_REFRESH_TOKEN,
:company_file => {
:name => COMPANY_FILE_NAME,
:username => COMPANY_FILE_USERNAME,
:password => COMPANY_FILE_PASSWORD,
},
})
However, I do not sure where to run this and how it works. This will refer to "myob-api/lib/myob/api/client.rb", right? I have to run this in console right?
@myob_client ||= Myob::Api::Client.new({
:consumer => {
:key => "h7hzzjk9m66y5f2gbqz568x8",
:secret => "teREHZ8SFvuWsW9ZMd5W6qcT",
},
redirect_uri: "https://dev-api.geo.ventures/api/v1/myob/auth/callback",
})
@myob.client.get_access_code_url
=> "https://secure.myob.com/oauth2/account/authorize?client_id=h7hzzjk9m66y5f2gbqz568x8&redirect_uri=https%3A%2F%2Fdev-api.geo.ventures%2Fapi%2Fv1%2Fmyob%2Fauth%2Fcallback&response_type=code&scope=CompanyFile"
then when i tried getting the access token using this ( i got the code from the get_access_code_url then i typed it manually (for test purpose))
@myob_client.get_access_token("lVxf!IAAAAM1aRlX_W-4pHwXiPzjhcse2fTvkh8-pYde3bDKAkamZAQEAAAGVDCeKdT8c2PtMHGpMrJZKFyKmAXdzTgpO0-gUtV0KQX5_khEnV-kw63JkwQ8x49CJj6cluXhBXx2Dz21WN7W28Fj_OyXeNNKPaO8IGAxlVjra9bHbw7OKTGU75m2CEks75kjhy1SSI1hwvzMz-OS3oO8P8gez8O1-6GL4DJlKaPjDLIdzBOFNL7O3uIn3UgXVk-8sweLiBDJZQO7D6bcLwGTM0pVoyOct-l2jfoSTBmGVK3dispjna0jjFChgyULb8ji2-AwvmgHnpAPhsDrwpGQdBSBSndEmwGOh8D6HjAVRX41ucSi_dvOurSNK04UnUpZKpLG__a_DGcgjHSRI")
it shows
OAuth2::Error: invalid_request:
{"error":"invalid_request"}
from /var/lib/gems/2.3.0/gems/oauth2-1.4.1/lib/oauth2/client.rb:119:in `request'
[24] pry(main)> @myob_client.company_file.all
OAuth2::Error: :
{
"Errors": [
{
"Name": "OAuthTokenIsMissing",
"Message": "The supplied OAuth token is missing",
"AdditionalDetails": "Header",
"ErrorCode": 31002,
"Severity": "Error",
"LearnMore": null
}
],
"Information": "Warning, error messages have not been finalised in this release and may change"
}
no implicit conversion of String into Integer
@api_client.select_company_file({:id => "7c13eeb8-snip",:username => "snip",:password=>"snip",
})
Any ideas on what is wrong here
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.