Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 41 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

A simple to use Ruby library for integrating with the MYOB Acumatica REST API via OAuth2.

---

## Installation

Using Bundler:
Expand All @@ -18,13 +16,48 @@ Without Bundler:
gem install myob_acumatica
```

---
## Configuration

## Authorization Code Flow
Provide configuration via **environment variables** and **explicitly per call**.

This flow allows a client application to obtain an access token on behalf of a user, using an authorization code granted by the user after consent.
**Note**: explicit parameters always override environment variables.

### Generate the Authorization Request URL
### Environment variables

```env
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.001
```

```ruby
MyobAcumatica::Api::Customer.get_list(
access_token: token["access_token"],
query_params: { '$filter' => "Status eq 'Active'" }
)
```

### Explicit parameters

```ruby
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'" }
)
```

## Authorization

Allow a client application to obtain an access token on behalf of a user, using an authorization code granted by the user after consent.

### Generate authorization request URL

Redirect the user to the authorization endpoint to initiate the consent flow.

Expand All @@ -45,9 +78,7 @@ https://example.myobadvanced.com/identity/connect/authorize?response_type=code&c

Send users to this URL to initiate the authorization code grant flow.

---

### Exchange Authorization Code for Access Token
### Exchange authorization code for access token

After the user grants consent, Acumatica will redirect to your callback URL with a `code` parameter. Exchange it for an access token:

Expand All @@ -73,9 +104,7 @@ Example response:
}
```

---

### Refresh the Access Token
### Refresh access token

When the access token expires, use the `refresh_token` to obtain a new one without prompting the user again.

Expand All @@ -91,8 +120,6 @@ token = MyobAcumatica::OAuth2::Token.refresh(
This returns a fresh token object with the same structure.


---

## Usage

### Customers
Expand Down Expand Up @@ -149,8 +176,6 @@ MyobAcumatica::Api::Customer.delete_by_keys(
)
```

---

### Invoices

Create an invoice:
Expand Down Expand Up @@ -215,14 +240,10 @@ MyobAcumatica::Api::Invoice.delete_by_id(
)
```

---

## Documentation

See full API reference and usage examples: [rubydoc.info/gems/myob_acumatica](https://www.rubydoc.info/gems/myob_acumatica)

---

## Development

### 1. Clone the repo
Expand Down Expand Up @@ -270,8 +291,6 @@ Try this command with your token:
MyobAcumatica::Api::Customer.get_list(access_token: token["access_token"])
```

---

## Contributing

Bug reports and pull requests are welcome at:
Expand All @@ -280,8 +299,6 @@ https://github.com/fast-programmer/myob_acumatica
Please follow the code of conduct:
https://github.com/fast-programmer/myob_acumatica/blob/master/CODE_OF_CONDUCT.md

---

## License

MIT — see the LICENSE
Expand Down
38 changes: 28 additions & 10 deletions examples/invoice.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
access_token: access_token,
entity: {
'Customer' => { 'value' => 'JOHNGOOD1' },
'CustomerID' => { 'value' => 'JOHNGOOD1' },
'Date' => { 'value' => Date.today.strftime('%Y-%m-%d') },
'DueDate' => { 'value' => (Date.today + 30).strftime('%Y-%m-%d') },
'Terms' => { 'value' => 'NET14DAYS' },
Expand All @@ -31,6 +30,14 @@
'City' => { 'value' => 'San Francisco' },
'State' => { 'value' => 'CA' }
},
'Description' => { 'value' => 'Test stock item' },
'Details' => [
{
'Description' => { 'value' => 'Pair of sneakers' },
'Quantity' => { 'value' => 1 },
'UnitPrice' => { 'value' => 100.00 }
}
],
'custom' => {
'Document' => {
'DiscDate' => { 'value' => (Date.today + 10).strftime('%Y-%m-%dT00:00:00+00:00') }
Expand All @@ -40,6 +47,14 @@
logger: logger
)

MyobAcumatica::Api::Invoice.release(
access_token: access_token,
entity: {
'id' => invoice1['id']
},
logger: logger
)

MyobAcumatica::Api::Invoice.get_by_id(
access_token: access_token,
id: invoice1['id'],
Expand All @@ -52,7 +67,7 @@
logger: logger
)

invoices = MyobAcumatica::Api::Invoice.get_list(
MyobAcumatica::Api::Invoice.get_list(
access_token: access_token,
query_params: {
'$filter' => "Type eq 'Invoice'"
Expand Down Expand Up @@ -91,10 +106,19 @@
logger: logger
)

credit_memos = MyobAcumatica::Api::Invoice.get_list(
MyobAcumatica::Api::Invoice.release(
access_token: access_token,
entity: {
'Type' => credit_memo1['Type'],
'ReferenceNbr' => credit_memo1['ReferenceNbr']
},
logger: logger
)

MyobAcumatica::Api::Invoice.get_list(
access_token: access_token,
query_params: {
'$filter' => "Type eq 'Credit Memo'",
'$filter' => "Type eq 'Credit Memo'"
},
logger: logger
)
Expand All @@ -113,12 +137,6 @@
logger: logger
)

# MyobAcumatica::Api::Invoice.release(
# access_token: access_token,
# entity: { 'id' => invoice1['id'] },
# logger: logger
# )

MyobAcumatica::Api::Invoice.delete_by_keys(
access_token: access_token,
keys: [invoice1['Type']['value'], invoice1['ReferenceNbr']['value']],
Expand Down
Loading