A simple to use Ruby library for integrating with the MYOB Acumatica REST API via OAuth2.
Using Bundler:
bundle add myob_acumaticaWithout Bundler:
gem install myob_acumaticaProvide via environment variables or explicit arguments.
MYOB_ACUMATICA_INSTANCE_NAME=example.myobadvanced.com
MYOB_ACUMATICA_CLIENT_ID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx@Company
MYOB_ACUMATICA_CLIENT_SECRET=xxxxxxxxxx_x_xxxxxxxxx
MYOB_ACUMATICA_REDIRECT_URI=http://localhost:4567/oauth2/callback
MYOB_ACUMATICA_SCOPE=api offline_access
MYOB_ACUMATICA_ENDPOINT_NAME=Default
MYOB_ACUMATICA_ENDPOINT_VERSION=20.200.001MyobAcumatica::Api::Customer.get_list(
access_token: token["access_token"],
query_params: { '$filter' => "Status eq 'Active'" }
)MyobAcumatica::Api::Customer.get_list(
access_token: token["access_token"],
instance_name: "example.myobadvanced.com",
endpoint_name: "Default",
endpoint_version: "20.200.001",
query_params: { '$filter' => "Status eq 'Active'" }
)Note: explicit arguments override environment variables.
Allow a client application to obtain an access token on behalf of a user, using an authorization code granted by the user after consent.
Redirect the user to the authorization endpoint to initiate the consent flow.
MyobAcumatica::OAuth2::Token.authorize_url(
instance_name: 'example.myobadvanced.com',
redirect_uri: 'https://example.myobadvanced.com/oauth2/callback',
client_id: 'abc123',
scope: 'api offline_access'
)This returns a URL like:
https://example.myobadvanced.com/identity/connect/authorize?response_type=code&client_id=abc123&redirect_uri=https%3A%2F%2Fexample.myobadvanced.com%2Foauth2%2Fcallback&scope=api+offline_access
Send users to this URL to initiate the authorization code grant flow.
After the user grants consent, Acumatica will redirect to your callback URL with a code parameter. Exchange it for an access token:
token = MyobAcumatica::OAuth2::Token.authorize(
code: params[:code],
instance_name: 'example.myobadvanced.com',
redirect_uri: 'https://example.myobadvanced.com/oauth2/callback',
client_id: 'abc123',
client_secret: 'secret123'
)Example response:
{
"access_token" => "...",
"expires_in" => 3600,
"token_type" => "Bearer",
"refresh_token" => "...",
"scope" => "api offline_access"
}When the access token expires, use the refresh_token to obtain a new one without prompting the user again.
token = MyobAcumatica::OAuth2::Token.refresh(
refresh_token: token["refresh_token"],
instance_name: 'example.myobadvanced.com',
client_id: 'abc123',
client_secret: 'secret123'
)This returns a fresh token object with the same structure.
Create or update a customer:
MyobAcumatica::Api::Customer.put_entity(
access_token: token['access_token'],
instance_name: 'example.myobadvanced.com',
endpoint_name: 'Default',
endpoint_version: '20.200.001',
entity: {
'CustomerID' => { 'value' => 'JOHNGOOD' },
'CustomerName' => { 'value' => 'John Good' },
'CustomerClass' => { 'value' => 'CUSTDFT' }
}
)List customers:
MyobAcumatica::Api::Customer.get_list(
access_token: token['access_token'],
instance_name: 'example.myobadvanced.com',
endpoint_name: 'Default',
endpoint_version: '20.200.001',
query_params: { '$filter' => "Status eq 'Active'" }
)Get customer by keys:
MyobAcumatica::Api::Customer.get_by_keys(
access_token: token['access_token'],
instance_name: 'example.myobadvanced.com',
endpoint_name: 'Default',
endpoint_version: '20.200.001',
keys: ['JOHNGOOD']
)Delete a customer:
MyobAcumatica::Api::Customer.delete_by_keys(
access_token: token['access_token'],
instance_name: 'example.myobadvanced.com',
endpoint_name: 'Default',
endpoint_version: '20.200.001',
keys: ['JOHNGOOD']
)Create an invoice:
MyobAcumatica::Api::Invoice.put_entity(
access_token: token["access_token"],
instance_name: 'example.myobadvanced.com',
endpoint_name: 'Default',
endpoint_version: '20.200.001',
entity: {
'CustomerID' => { 'value' => 'JOHNGOOD' },
'Date' => { 'value' => '2025-06-06' },
'Details' => [
{
'InventoryID' => { 'value' => 'CONSULTING' },
'Quantity' => { 'value' => 2 },
'UnitPrice' => { 'value' => 150.0 }
}
]
}
)List invoices:
MyobAcumatica::Api::Invoice.get_list(
access_token: token["access_token"],
instance_name: 'example.myobadvanced.com',
endpoint_name: 'Default',
endpoint_version: '20.200.001',
query_params: {
'$filter' => "Status eq 'Open'",
'$top' => 10,
'$select' => 'InvoiceNbr,CustomerID,Status,Date'
}
)Get invoice by ID:
MyobAcumatica::Api::Invoice.get_by_id(
access_token: token["access_token"],
instance_name: 'example.myobadvanced.com',
endpoint_name: 'Default',
endpoint_version: '20.200.001',
id: '00000000-0000-0000-0000-000000000000'
)Delete an invoice:
MyobAcumatica::Api::Invoice.delete_by_id(
access_token: token["access_token"],
instance_name: 'example.myobadvanced.com',
endpoint_name: 'Default',
endpoint_version: '20.200.001',
id: '00000000-0000-0000-0000-000000000000'
)See full API reference and usage examples: rubydoc.info/gems/myob_acumatica
git clone https://github.com/fast-programmer/myob_acumatica.git
cd myob_acumatica
bundle installMYOB_ACUMATICA_INSTANCE_NAME=example.myob.com
MYOB_ACUMATICA_CLIENT_ID=your-client-id
MYOB_ACUMATICA_CLIENT_SECRET=your-client-secret
MYOB_ACUMATICA_REDIRECT_URI=http://localhost:4567/oauth2/callback
MYOB_ACUMATICA_SCOPE=api offline_access
MYOB_ACUMATICA_ENDPOINT_NAME=Default
MYOB_ACUMATICA_ENDPOINT_VERSION=22.200.001This test app helps acquire an OAuth token and inspect customer data.
bundle exec ruby examples/app.rbVisit in your browser:
- http://localhost:4567/oauth2/authorize — start login
- http://localhost:4567/oauth2/callback — receive tokens and fetch customer list
bin/consoleTry this command with your token:
MyobAcumatica::Api::Customer.get_list(access_token: token["access_token"])Bug reports and pull requests are welcome at: https://github.com/fast-programmer/myob_acumatica
MIT — see the LICENSE https://opensource.org/licenses/MIT