# NetSuite

Source: https://developers.swell.is/app-guides/netsuite

The NetSuite app connects your Swell store to [NetSuite](https://www.netsuite.com). It's for businesses that keep NetSuite as their system of record and take orders from business buyers on Swell. Each order is sent to NetSuite as a sales order when it's placed, for the buyer's NetSuite customer, with the PO number, the shipping cost and the prices the buyer saw. The sales order carries no tax and no payment terms: NetSuite works those out.

Every 15 minutes, the app reads what changed in NetSuite. Customers get their payment terms, credit limit and price level, and the price level sets their Swell customer group. Products and variants with the same SKU as a NetSuite item get the prices of your price levels as customer group prices, and their stock. Each order shows the invoices and fulfillments of its sales order, and shipped fulfillments become Swell shipments with tracking.

The app connects with NetSuite's OAuth 2.0 client credentials and a certificate that it creates for your store. Nothing is installed in NetSuite. It works with sandbox accounts and OneWorld subsidiaries, and it uses the PO number from Swell's Wholesale Desk app when an order has one.

Free and open source (MIT) · [Source on GitHub](https://github.com/swellstores/netsuite-app)

## How it works

Orders are sent, and changes come back from NetSuite, only while **Sync with NetSuite** is on. The actions you choose yourself work either way.

| When | What the app does |
| --- | --- |
| An order is placed, or paid if Send orders to NetSuite is set to When they are paid | Finds or creates the buyer's NetSuite customer, matches the order's items to NetSuite items by SKU, and creates the sales order. The order then shows its NetSuite sales order number and status. |
| An order is canceled | Closes its sales order, if Close the sales order when the Swell order is canceled is on and nothing has been fulfilled or billed in NetSuite. Otherwise the sales order stays open and the record says why. |
| A linked customer's company name or phone is changed in Swell | Updates the NetSuite customer, for customers the app created. |
| Every 15 minutes | Reads the customers and items that changed in NetSuite, and the invoices and fulfillments of the sales orders it follows. |
| A linked customer changed in NetSuite | Saves the payment terms, credit limit and price level on the Swell customer, sets the customer group that the price level is mapped to, and copies a changed company name or phone. |
| An item changed in NetSuite, or its stock moved | Sets the customer group prices and the stock of the Swell product or variant with the same SKU. |
| A sales order is invoiced in NetSuite | Lists the invoice on the order's record with its total, amount due, due date and status. |
| A fulfillment of a sales order is shipped in NetSuite | Creates a Swell shipment for the items with the tracking number, if Create Swell shipments from NetSuite fulfillments is on. |
| All invoices of a sales order are paid in NetSuite | Records the payment on the Swell order with your manual payment method, if Record the payment in Swell when a NetSuite invoice is paid is on and the invoices were settled by customer payments or deposits. |
| NetSuite refuses an order, or an order can't be matched | Lists the order under Needs attention with the reason, and e-mails the store's administrators. |
| NetSuite can't be reached or is busy | Tries again for about ten minutes, then with each 15-minute check. After a day, lists the order under Needs attention. |
| You choose Send to NetSuite on an order, or on selected orders | Sends the order now, whether or not Sync with NetSuite is on. |
| You choose Retry, or Retry failed orders | Tries again. An order that is in NetSuite is never sent twice. |

## Before you begin

- A NetSuite account, and a NetSuite administrator for the setup in NetSuite.
- A NetSuite sandbox account to test with. A sandbox account ID ends in `_SB1` or similar, such as `1234567_SB1`.
- A SKU on every product and variant you sell, equal to the item's Item Name/Number in NetSuite, or to another item field that you name in the settings. Each SKU must be on exactly one active NetSuite item.
- Stock tracking turned on in Swell for the products whose stock should follow NetSuite.
- A Swell customer group for each NetSuite price level you sell at. Create the groups under **Settings > Customers** and note their IDs.
- Buyers who are already customers in NetSuite need their Swell customer in a customer group before their first order. The app then links them by e-mail address and doesn't create a second customer.
- To record payments from NetSuite, a manual payment method under **Settings > Payments**, such as your method for payment terms.
- For a OneWorld account, the ID of the subsidiary that new customers belong to.

## Set up

Install NetSuite from the Swell App Store. Connect your Swell test environment to a NetSuite sandbox account first, and check a test order's sales order, invoice and fulfillment in the sandbox before you connect the live environment. NetSuite accounts differ in the features they use, such as OneWorld and Multi-Location Inventory, so check each part on your own account. Steps 1 to 4 need a NetSuite administrator.

The role in step 2 needs these permissions:

| Tab | Permission | Level |
| --- | --- | --- |
| Transactions | Sales Order | Edit |
| Transactions | Invoice | View |
| Transactions | Item Fulfillment | View |
| Transactions | Find Transaction | View |
| Lists | Customers | Edit |
| Lists | Items | View |
| Lists | Locations, Subsidiaries (OneWorld), Price Levels, Terms | View |
| Setup | REST Web Services | Full |
| Setup | Log in using OAuth 2.0 Access Tokens | Full |
| Reports | SuiteAnalytics Workbook | Edit (SuiteQL) |

**1. Turn on the features in NetSuite**

In NetSuite, go to **Setup > Company > Enable Features > SuiteCloud** and turn on REST Web Services and OAuth 2.0.

**2. Create a role and an integration user**

Go to **Setup > Users/Roles > Manage Roles > New** and create a role with the permissions in the table above. Give the role to the employee the app acts as. A user of its own for the integration keeps the app's changes apart from your staff's.

**3. Create the integration record**

Go to **Setup > Integration > Manage Integrations > New**. Enter the name Swell and set the state to Enabled. Under OAuth 2.0, tick **Client Credentials (Machine to Machine) Grant** and the scope **REST Web Services**. Leave the other grants and Token-Based Authentication off. Save, and copy the Client ID (consumer key). NetSuite shows it once.

**4. Create and upload the certificate**

In Swell, go to **Apps > NetSuite > Settings** and click **Create certificate**. The message says until when the certificate is valid. Copy all of **Certificate to upload in NetSuite**, including the BEGIN and END lines, into a text file named swell.pem.

In NetSuite, go to **Setup > Integration > Manage Authentication > OAuth 2.0 Client Credentials (M2M) Setup** and choose Create New. Choose the integration user, the role from step 2 and the Swell integration, upload swell.pem and save. Copy the Certificate ID that NetSuite shows.

**5. Connect**

In the app's settings, enter Account ID, Client ID and Certificate ID. The account ID is in NetSuite under **Setup > Company > Company Information**. Click **Save settings**, then **Test connection**. The message lists your subsidiaries, locations, price levels and terms with their IDs, and names anything in the settings that NetSuite doesn't have.

**6. Choose the order settings**

Under **Orders**, choose when orders are sent, whether only business accounts' orders are sent, and the sales order status. If your SKUs aren't in Item Name/Number, enter the item field in **NetSuite field that holds the SKU**. The location, department, class, shipping methods and extra fields are optional. Click **Save settings**.

**7. Choose what comes back**

Under **Customers**, add a row under **Price levels and customer groups** for each price level you sell at, with its name or ID and the ID of its Swell customer group. Prices are synced only for price levels with a row. OneWorld accounts also enter the subsidiary for new customers. Under **Prices and stock**, enter the currency of your NetSuite prices and the stock locations you sell from. Under **Invoices and shipments**, choose whether fulfillments create shipments and whether payments are recorded. Save, then test the connection again.

**8. Turn on the sync**

Under Connection, turn on **Sync with NetSuite** and save. Then choose **Actions > Sync all prices and stock** and click Start. The result is under **Orders > NetSuite pulls**. Check the prices, stock and customer groups it set.

**9. Test with an order**

In the test environment, place an order for products whose SKUs are in the sandbox. Under **Orders > NetSuite sales orders**, the order is listed as In NetSuite with its sales order number. Open it and click **View in NetSuite**. In the sandbox, check the customer, the lines and prices, the PO number, the shipping cost, the tax and the total. Total check on the record says if NetSuite's total differs from the order's.

In the sandbox, invoice the sales order and fulfill it with a tracking number. In Swell, choose **Actions > Get changes from NetSuite now** in the app's settings. The record then lists the invoice with its amount due and the fulfillment, and the order has a shipment with the tracking number. If you record payments, pay the invoice in the sandbox, get the changes again and check the payment on the order. Cancel another test order and check that its sales order is closed.

**10. Go live**

Settings are saved separately for each environment, and each environment has its own certificate. In the live environment, repeat steps 1 to 8 with your production NetSuite account. To send orders placed before the sync was on, select them in the order list and choose **Send to NetSuite**.

Keep the test environment connected to the sandbox. The app has no test mode: each environment sends its orders to the NetSuite account in its settings, and sets its prices and stock from that account.

## Using NetSuite

### Orders

While **Sync with NetSuite** is on, an order is sent when it's placed, or when it's paid if **Send orders to NetSuite** is set to **When they are paid**. With **Send orders from** set to **Business accounts only**, orders from other accounts are listed as **Skipped**. A draft order is sent once it's placed. The sales order has:

- The buyer's NetSuite customer.
- The date the order was created, and the status chosen in **Sales order status**.
- The PO number that Wholesale Desk saved on the order, or else the order's own PO number.
- A memo with the order number, such as `Swell order 1042`.
- One line per item, for the NetSuite item with the same SKU, with the quantity and the price the buyer saw after the item's discounts. The price is sent as a custom price.
- The order's shipping cost, and the shipping item from **Shipping methods** if the order's shipping service has a row.
- The order's shipping and billing addresses.
- The location, department and class from the settings, and the values of the rows under **Extra fields**.

NetSuite calculates the tax. If your store's prices include tax, the app sends each line and the shipping charge without it. When NetSuite's total differs from the Swell order's, the order is still sent, and **Total check** on its record says by how much. Every order the app sent or tried to send has a record under **Orders > NetSuite sales orders**, with one of these statuses:

- **In NetSuite**: the sales order exists. The record has its number, **Status in NetSuite**, **Total in NetSuite** and **View in NetSuite**.
- **In progress**: the app is sending the order, or NetSuite couldn't take it yet and the app tries again.
- **Needs attention**: the order couldn't be sent. **Problem** says why.
- **Skipped**: the app doesn't send this order, for example a canceled order or one from an account that isn't a business account.
- **Resolved by hand**: you marked it as resolved.

The order itself shows the sales order number and status on its **NetSuite** tab, and in the **NetSuite** and **NetSuite status** columns of the order list.

### Customers

A Swell customer is linked to a NetSuite customer when their first order is sent. A customer in a customer group is linked to the active NetSuite customer with the same e-mail address, and to the one with the lowest internal ID if there are several. Customers in no group are never matched by e-mail address, because anyone can register with someone else's address, and only you can put a customer in a group.

To connect a buyer to the customer you already have in NetSuite, put their Swell customer in a customer group before their first order. Any group works. The price level in NetSuite sets the group from then on.

With no match, the app creates the customer: a company if the account has a company name, a person otherwise, with the e-mail address, phone, billing address and the subsidiary from the settings. The NetSuite customer ID is saved on the Swell customer.

NetSuite decides the rest. Each check saves the customer's payment terms, credit limit and price level on the customer's **NetSuite** tab. A price level with a row under **Price levels and customer groups** sets the customer's group. A customer whose price level has no row, or a row without a group, is taken out of the groups that the rows name.

Company name and phone are kept the same on both sides, and the change the app sees last wins. A change in NetSuite is copied to Swell. A change in Swell is copied to NetSuite for customers the app created. A customer matched by e-mail address keeps its company name and phone as NetSuite has them.

### Prices

With **Sync prices from NetSuite** on, each price level with a row under **Price levels and customer groups** becomes the prices of its customer group, on the Swell product or variant with the item's SKU. NetSuite's quantity breaks become quantity ranges. A row without a group sets the product's regular price. Prices are read in the currency under **Currency**, or USD when it's empty.

Prices of customer groups that have no row stay as they are. So do the prices of a product when NetSuite has no price for it at a price level in that currency, and all prices of products whose SKU isn't in NetSuite.

### Stock

With **Sync stock from NetSuite** on, the stock of a product or variant with stock tracking on is set to the item's quantity in NetSuite: **Available** or **On hand**, added up over the **Stock locations**, or over all locations when none are entered. The change is a stock adjustment with a reason such as `NetSuite stock sync: 5 → 8`.

Items that NetSuite keeps no stock for at those locations are left as they are in Swell. For a product with variants, the app sets the stock of the variants, by their SKUs.

### Invoices and payments

The app doesn't create invoices. When NetSuite invoices a sales order, the next check lists the invoice on the record under **Invoices**, with its number, date, due date, total, amount due and status. **Invoiced** and **Amount due** add up the order's invoices.

With **Record the payment in Swell when a NetSuite invoice is paid** on and a method in **Record payments as**, the app records a payment on the Swell order once NetSuite shows nothing due on the sales order's invoices and they were settled by customer payments or deposits. The payment is for the invoiced amount, up to what's still due on the Swell order, with the note `Paid in NetSuite`. An order that's already paid in Swell, or canceled, gets no payment. **Payment recorded in Swell** on the record shows the amount the app has accounted for.

When the invoices were settled another way, such as with a credit memo or a journal, the app records no payment. **Payment check** on the record says so. If you received money for part of it, record that payment on the Swell order yourself.

### Shipments

With **Create Swell shipments from NetSuite fulfillments** on, a fulfillment that has shipped becomes a Swell shipment for the same items, with the fulfillment's tracking numbers and shipping method, and the note `NetSuite fulfillment` followed by its number. A fulfillment that is only picked or packed waits until it ships.

The app never ships more of an item than the Swell order still has to deliver. If the items were already shipped, canceled or refunded in Swell, no shipment is created, and **Note** on the fulfillment says so. Each fulfillment is listed on the record under **Fulfillments**.

The app follows a sales order until it's invoiced in full with nothing due and fully shipped, until NetSuite closes or cancels it, or for 180 days. Followed sales orders are on the **Awaiting invoice or shipment** tab.

### Canceled orders

When an order that's in NetSuite is canceled in Swell, the app closes every line of its sales order, and **Cancellation** on the record shows **Closed**. If part of the sales order was already fulfilled or billed, or **Close the sales order when the Swell order is canceled** is off, the sales order stays open. **Cancellation** shows **Left open** and **Problem** says why. No e-mail is sent for it. Close or credit the sales order in NetSuite.

An order canceled before it reached NetSuite isn't sent. Cancellations are handled while **Sync with NetSuite** is on.

### Sending orders on demand

To send an order that the sync didn't cover, such as one placed before the app was on, open the order and choose **Actions > Send to NetSuite**. To send several, select them in the order list and choose **Send to NetSuite**, then **Send**. Both work whether or not **Sync with NetSuite** is on and whether or not the order is paid. The results are under **Orders > NetSuite sales orders**.

### Needs attention and retries

Orders that couldn't be sent are listed under **Orders > NetSuite sales orders > Needs attention**, with the reason in **Problem**. Correct the cause first, for example a SKU, the customer or the connection. Then:

- To retry one order, open its record and choose **Actions > Retry**.
- To retry several, select them in the list and choose **Retry**, then **Retry**.
- To retry every order that needs attention, and finish the ones in progress, choose **Actions > Retry failed orders** in the app's settings, then **Retry**.

An order that is in NetSuite is never sent twice. Each sales order is marked with the Swell order it belongs to, and the app looks for that sales order in NetSuite before it sends an order again.

If NetSuite can't be reached or is busy, the order stays **In progress**. The app tries again for about ten minutes, then with each 15-minute check. After a day of waiting, the order is listed under **Needs attention** with `The order could not be sent within a day.`

When orders need attention, or NetSuite refuses the connection, the app e-mails the store's administrators with the problem and a link to the app. The subject starts with `Action needed:`. You get one e-mail when orders start needing attention and one when NetSuite refuses the connection, not one per order. No new e-mail is sent until the problems are cleared, or a day passes without a new one. The e-mail is the notification **NetSuite needs attention**, which you can edit or turn off under **Settings > Notifications**.

### Marking as resolved

To stop the app from sending an order, for example after you entered the sales order in NetSuite by hand, open its record and choose **Actions > Mark as resolved**. Optionally enter the **Sales order number in NetSuite (optional)**, then click **Mark as resolved**. The status becomes **Resolved by hand**, and the order is listed on the **Skipped** tab. The app doesn't read the invoices or fulfillments of a sales order you entered by hand.

**Mark as resolved** is available on records that need attention, are in progress, or whose **Cancellation** shows **Closing**. A record whose sales order is in NetSuite but couldn't be closed stays **In NetSuite**, and its sales order is left as it is.

### Checks for changes

While **Sync with NetSuite** is on, the app checks NetSuite every 15 minutes. A check reads the customers and items changed since the last check began, with ten minutes to spare, and the sales orders it follows. The first check reads the last 24 hours. **Last checked NetSuite** in the settings shows when the last one began.

To check right away, choose **Actions > Get changes from NetSuite now** in the app's settings. To read every item with a SKU and every linked customer, not only the changed ones, choose **Actions > Sync all prices and stock**, then **Start**. Run it after setup, and after you change the price level rows, the currency or the stock settings.

Each check that changed something or met a problem, and each full sync, is listed under **Orders > NetSuite pulls** with what it changed. **SKUs not in Swell** lists the SKUs of NetSuite items it read that aren't on a Swell product or variant. **Problems** lists what it couldn't read or write. When one part can't be read, the others are still synced, and the next check reads the same period again.

### In the dashboard

| Where | What it's for |
| --- | --- |
| Apps > NetSuite > Settings | The Connection, Orders, Customers, Prices and stock, and Invoices and shipments settings, with Create certificate and Test connection. |
| Apps > NetSuite > Settings, Actions menu | Retry failed orders, Get changes from NetSuite now and Sync all prices and stock. |
| Orders > NetSuite sales orders | Every order the app sent or tried to send, with the Needs attention, In NetSuite, Awaiting invoice or shipment and Skipped tabs, and Retry for selected records. |
| A sales order record | Its number, status, status and total in NetSuite, problem, total check, PO number, invoices, fulfillments and cancellation, View in NetSuite, and Retry and Mark as resolved in its Actions menu. |
| An order's NetSuite tab | The order's sales order record, its NetSuite sales order number and NetSuite status. |
| An order's Actions menu | Send to NetSuite. |
| The order list | The NetSuite and NetSuite status columns, and Send to NetSuite for selected orders. |
| A customer's NetSuite tab | NetSuite customer ID, Price level, Payment terms, Credit limit and Synced with NetSuite. |
| Orders > NetSuite pulls | Each check that changed something or met a problem, with its counts, SKUs not in Swell and Problems, and the With problems tab. |
| Settings > Notifications | The e-mail NetSuite needs attention. |

## Settings

Settings are in **Apps > NetSuite > Settings** and are saved separately for each environment. They're in five sections: **Connection**, **Orders**, **Customers**, **Prices and stock**, and **Invoices and shipments**. **Connection** also has the **Create certificate** and **Test connection** buttons. IDs are NetSuite internal IDs, which **Test connection** lists. A NetSuite ID that isn't a number is ignored.

| Setting | Description | Default |
| --- | --- | --- |
| Account ID | Connection. Your NetSuite account ID, under Setup > Company > Company Information. A sandbox ends in _SB1 or similar, for example 1234567_SB1. | None |
| Client ID | Connection. The consumer key of the integration record, shown once when you save it in NetSuite. | None |
| Certificate ID | Connection. Shown in NetSuite's OAuth 2.0 Client Credentials (M2M) Setup after you upload the certificate. Create certificate empties it. | None |
| Certificate to upload in NetSuite | Connection. Read-only. Filled in by Create certificate. Copy all of it, including the BEGIN and END lines, into a file named swell.pem. | Empty |
| Private key | Connection. Made by Create certificate and kept by the app. Masked on the settings page. Leave it as it is. | None |
| Connected account | Connection. Read-only. The account ID, marked as a sandbox if it is one, filled in by Test connection. | Not tested yet |
| Last checked NetSuite | Connection. Read-only. When the last check for changes began. Filled in by the app. | Not yet |
| Sync with NetSuite | Connection. While on, orders are sent to NetSuite and changes come back every 15 minutes. The buttons and actions work either way. | Off |
| Send orders to NetSuite | Orders. When they are placed, or When they are paid. | When they are placed |
| Send orders from | Orders. All customers, or Business accounts only. | All customers |
| Sales order status | Orders. Pending fulfillment, or Pending approval. | Pending fulfillment |
| NetSuite field that holds the SKU | Orders. itemid (Item Name/Number), upccode, or the ID of a custom item field such as custitem_sku. | Empty: itemid |
| Location ID | Orders. Optional. The NetSuite location on every sales order. | None |
| Department ID | Orders. Optional. The department on every sales order. | None |
| Class ID | Orders. Optional. The class on every sales order. | None |
| Shipping methods | Orders. Optional. A row for each Swell shipping service, with the Swell shipping service ID, such as standard, and the NetSuite shipping item ID. Without a row, the sales order gets the shipping cost and no shipping item. | None |
| Extra fields | Orders. Optional. A row copies a value from the Swell order to a custom body field of the sales order. Swell order field is a path in the order, such as $app.wholesale_desk.date_due or comments. NetSuite field ID must start with custbody, such as custbody_due_date. Other rows are ignored. | None |
| Close the sales order when the Swell order is canceled | Orders. Only while nothing has been fulfilled or billed in NetSuite. Otherwise the record shows why it was left open. | On |
| Subsidiary for new customers | Customers. OneWorld accounts only. The ID of the subsidiary that customers the app creates belong to. | None |
| Price levels and customer groups | Customers. A row for each price level. NetSuite price level is its name or ID. Swell customer group ID is the group that customers on the price level get, and that the price level's prices are saved for. A row without a group sets each product's regular price. | None |
| Sync prices from NetSuite | Prices and stock. Sets the prices of the price levels under Customers on products and variants with a matching SKU. | On |
| Currency | Prices and stock. The currency of the NetSuite prices to use, as its ISO code. Usually your store's currency. | Empty: USD |
| Sync stock from NetSuite | Prices and stock. Swell stock follows NetSuite for products with stock tracking on. | On |
| Stock locations | Prices and stock. The IDs of the NetSuite locations whose stock you sell online. Empty: all locations. | None |
| Stock quantity | Prices and stock. Available, or On hand. | Available |
| Create Swell shipments from NetSuite fulfillments | Invoices and shipments. With the tracking number. Items already shipped in Swell are not shipped twice. | On |
| Record the payment in Swell when a NetSuite invoice is paid | Invoices and shipments. Once NetSuite shows nothing due on a sales order's invoices and they were settled by customer payments or deposits, the payment is recorded on the Swell order with the method below. | Off |
| Record payments as | Invoices and shipments. The ID of a manual payment method under Settings > Payments, such as net_terms. Required for recording payments. Never a card or store credit. | None |

## Limitations

- The app has no test mode. Each environment sends its orders to the NetSuite account in its settings, so connect the test environment to a sandbox.
- Items are matched by SKU only. An order with an item that has no SKU, or whose SKU is on no active NetSuite item or on several, isn't sent until that's corrected.
- The app doesn't send tax. NetSuite calculates it, so the sales order's total can differ from the Swell order's.
- Discounts reach NetSuite as lower line prices, not as discount lines. The order's currency isn't sent.
- Changes to an order after it was sent, refunds and returns aren't sent to NetSuite. Only a cancellation is.
- An order listed as **Skipped** isn't sent later, except a draft that's placed. That includes orders skipped by **Send orders from** before you changed it. Enter those in NetSuite by hand.
- Customers in no customer group are never matched to an existing NetSuite customer, so their first order creates a new one.
- After a customer is linked, only company name and phone are synced. Addresses and e-mail addresses aren't.
- Payment terms and the credit limit are shown on the customer. The app doesn't apply them at checkout.
- Prices are synced for the price levels you map, in one currency. Customer-specific prices and quotes aren't synced.
- Stock is one quantity per product or variant, added up over the locations. A stock sync sets Swell to NetSuite's quantity, so an order that NetSuite's quantity doesn't reflect yet counts as in stock again until it does.
- A SKU on more than one Swell product or variant gets no prices or stock.
- The app reads invoices and doesn't create them. A payment is recorded only once nothing is due on the sales order's invoices, not for part payments, and only when they were settled by customer payments or deposits.
- Tracking added to a fulfillment after its Swell shipment was created isn't copied to the shipment.
- A sales order is followed for 180 days at most. A check for changes looks back seven days at most, so run **Sync all prices and stock** after the sync was off for longer.
- A full sync reads up to 50,000 NetSuite items, and a check follows up to 12,500 sales orders.
- The certificate is valid for about two years, and the app doesn't remind you before it ends.

## Troubleshooting

Problems with an order are shown in **Problem** on its record, under **Orders > NetSuite sales orders > Needs attention**. Problems with a check are shown in **Problems** on its record, under **Orders > NetSuite pulls > With problems**. The app also logs errors. In the Swell dashboard, the logs are under **Developer > Console > Logs**.

### Test connection fails

`Enter the account ID, the client ID, the certificate ID, a certificate (choose Create certificate), save the settings, then test again.` names what isn't saved yet. A message that says the value `is not a NetSuite account ID` means **Account ID** has other characters than letters, digits, `_` and `-`.

`NetSuite refused the token request` means NetSuite didn't accept the certificate or the IDs. Check the **Account ID**, that **Client ID** is the consumer key of an enabled integration record with the client credentials grant and the REST Web Services scope, that **Certificate ID** is the one NetSuite shows for the certificate, and that the certificate uploaded in NetSuite is the one in **Certificate to upload in NetSuite**. A message that ends with `Try again in a minute.` means NetSuite couldn't be reached or was busy.

### "The integration's role can't read …"

**Test connection** connected, but the role couldn't read the lists it names. That's expected for subsidiaries on accounts without OneWorld. If it names price levels, locations or terms, add the missing permission to the role from the table under Set up, then test again.

### "NetSuite refused the connection" or "NetSuite's integration role may not …"

NetSuite no longer accepts the app's requests, or the role lacks the permission the message names. Orders are listed under **Needs attention**, a run over several orders stops at the first one, and checks stop at what they can't read. The store's administrators get an e-mail whose subject starts with `Action needed: NetSuite is not accepting requests from`.

In NetSuite, check that the integration record is enabled, and that the certificate under **Setup > Integration > Manage Authentication > OAuth 2.0 Client Credentials (M2M) Setup** is active and not expired. For a missing permission, add it to the role. Then click **Test connection** and choose **Actions > Retry failed orders**. If the certificate expired, see "Replacing the certificate" below.

### Replacing the certificate

**Create certificate** makes a new private key and empties **Certificate ID** at once, so the app can't connect until the new certificate is in NetSuite. Upload it as in step 4 of Set up, enter the new **Certificate ID**, click **Save settings** and **Test connection**, and remove the old certificate in NetSuite. Orders placed in between are listed under **Needs attention**: choose **Actions > Retry failed orders**.

### "These items have no SKU in Swell …"

Give each product or variant the message names the SKU of its NetSuite item, then retry the order.

### "NetSuite has no active item with the item name/number …"

No active NetSuite item has the SKU in the field under **NetSuite field that holds the SKU**. SKUs after `inactive:` are on an inactive item. Correct the SKU in Swell or the item in NetSuite, then retry.

### "More than one NetSuite item has the SKU …"

Make the SKU unique in NetSuite, then retry.

### "The order has no customer account …" or "NetSuite refused the new customer for …"

Add a customer to the order, or correct what NetSuite's reason at the end of the message names. Then retry.

### "NetSuite refused the sales order: …"

NetSuite answered with the reason that follows, and created nothing. Correct it in Swell, in NetSuite or in the app's settings, then retry. If you enter the sales order in NetSuite by hand instead, mark the record as resolved.

### "The order could not be sent within a day"

NetSuite couldn't be reached or was busy for a day, so the app stopped trying. The rest of the message is the last error. Choose **Retry** on the record, or **Actions > Retry failed orders** in the app's settings.

### An order stays In progress

**Problem** says what the app is waiting for, such as `NetSuite is busy with other requests for this account.` or `NetSuite has not confirmed the last attempt yet.` The app tries again by itself. NetSuite limits how many requests an account answers at once, across all its integrations.

### An order isn't listed, or is listed as Skipped

An order has no record if **Sync with NetSuite** was off when it was placed, or if orders are sent when paid and it isn't paid yet. Choose **Actions > Send to NetSuite** on the order. A skipped order's **Problem** says why: it's a draft, it was canceled before it was sent, it has no items, or `Only orders from business accounts are sent to NetSuite`.

### Total check: "NetSuite's total is …"

The sales order was created, and NetSuite's total differs from the Swell order's by the amount shown. Check the tax and the shipping cost on the sales order in NetSuite.

### A canceled order's sales order is still open

**Problem** on the record says that part of it is fulfilled or billed, or that closing is off in the settings. Close or credit it in NetSuite. If **Cancellation** shows **Closing**, the app is still trying: choose **Retry**, or **Mark as resolved** to leave the sales order as it is.

### Prices or customer groups don't change

Check that **Price levels and customer groups** has a row for the price level, and that the group ID is the ID of a group under **Settings > Customers**. `NetSuite has no price level …` under **Problems** means a row names a price level NetSuite doesn't have. Check that **Currency** is a currency the items have prices in, and that the product's SKU isn't listed under **SKUs not in Swell**. A customer's group changes only after their first order linked them to a NetSuite customer.

### Stock doesn't change

Check that stock tracking is on for the product, that the item has stock at one of the **Stock locations**, and that the SKU is on one product or variant only. `More than one Swell product or variant has the SKU …` under **Problems** names the SKUs that were left as they are.

### A fulfillment has no Swell shipment

A fulfillment that is picked or packed gets its shipment once it ships. **Note** on the fulfillment starts with `No Swell shipment:` when its items were already shipped, canceled or refunded in Swell. Check also that **Create Swell shipments from NetSuite fulfillments** is on.

### A payment isn't recorded

Payments need **Record the payment in Swell when a NetSuite invoice is paid** and a method in **Record payments as**. **Test connection** says `Payments are not recorded until you name a manual payment method` when the method is missing. A payment is recorded once nothing is due on any of the sales order's invoices, and only for what's still due on the Swell order. If **Payment check** on the record has a note, the invoices were settled with something other than a customer payment, and the app recorded none. `Swell did not record the payment` under **Problems** means Swell refused it. Check the ID in **Record payments as**.

### A check shows Stopped

**Problems** names what NetSuite refused. `Stopped without finishing; the next check took over.` means a check was cut off, and the next one read the same period. **Get changes from NetSuite now** answers `Not connected yet, or another check is running.` when the connection settings are incomplete or a check is under way.

## Uninstalling

Uninstalling applies to the environment you are in, so remove the app from the test and live environments separately. It removes the app's functions, its 15-minute schedule, the **NetSuite sales orders** and **NetSuite pulls** lists, the **NetSuite** tabs and actions on orders and customers, the notification and the settings page. Orders are no longer sent, and nothing comes back from NetSuite.

Uninstalling doesn't delete the app's records, or the values of the `$app.netsuite` fields on orders, customers and products.

Nothing is changed in NetSuite. Sales orders and customers stay there, and so do the integration record and the certificate mapping. To end the connection on NetSuite's side, remove the certificate mapping under **Setup > Integration > Manage Authentication > OAuth 2.0 Client Credentials (M2M) Setup** and the integration record under **Setup > Integration > Manage Integrations**.

To stop the sync without uninstalling, turn off **Sync with NetSuite** and click **Save settings**.

## For developers

The app adds these fields to orders, accounts and products. It writes them itself, and its next sync replaces changes made to them.

| Field | On | Type | Description |
| --- | --- | --- | --- |
| $app.netsuite.salesorder_id | Orders | objectid | The ID of the order's record in apps/netsuite/salesorders. |
| $app.netsuite.salesorder | Orders | link | The record itself, for expand. |
| $app.netsuite.netsuite_number | Orders | string | The sales order number NetSuite assigned. |
| $app.netsuite.netsuite_status | Orders | string | The sales order's status in NetSuite, as last read. |
| $app.netsuite.customer_id | Accounts | string | The internal ID of the NetSuite customer. |
| $app.netsuite.linked_by | Accounts | string | created, external_id or email: how the customer was linked. |
| $app.netsuite.terms | Accounts | string | The name of the customer's payment terms in NetSuite. |
| $app.netsuite.credit_limit | Accounts | float | The customer's credit limit in NetSuite. |
| $app.netsuite.price_level | Accounts | string | The name of the customer's price level. |
| $app.netsuite.fingerprint | Accounts | string | Company name and phone as last synced, so the app's own write isn't taken for a change. |
| $app.netsuite.date_synced | Accounts | date | When the app last wrote the account or its NetSuite customer. |
| $app.netsuite.item_id | Products | string | The internal ID of the NetSuite item with the product's SKU. Set when the app writes new prices on the product. |
| $app.netsuite.date_synced | Products | date | When the app last wrote prices on the product. |

| Collection | Holds | Fields |
| --- | --- | --- |
| apps/netsuite/salesorders | One record per order the app sent or tried to send. | key (order:<order id>, unique), status (pending, sent, failed, skipped, resolved), source, name, order_id, order_number, account_id, customer_name, customer_email, po_number, amount, currency, customer_id, netsuite_id, number, netsuite_status, netsuite_total, netsuite_url, total_note, lines, invoices, fulfillments, invoiced_amount, unpaid_amount, payment_recorded, open (boolean), cancel (requested, closed, kept), problem, problem_code, attempts, date_attempted, date_submitted, date_pending, date_sent, date_checked, locked_until. |
| apps/netsuite/pulls | One record per check that changed something or met a problem, and per full sync. | name, kind (changes, full), source, status (running, done, failed), slot (unique), window_minutes, since, customers, prices, stock, invoices, shipments, payments, unmatched, errors, date_started, date_finished, locked_until. |
| apps/netsuite/alerts | One record per open problem. Creating one sends the NetSuite needs attention e-mail. | key (connection or orders, unique), message, subject, count, date_last_seen, app_id. |

| Function | Runs on | What it does |
| --- | --- | --- |
| order-events | order.submitted, order.paid and order.canceled, while Sync with NetSuite is on | Writes the order's record and starts a send-orders run, or marks the record for closing. |
| account-updated | account.updated, while Sync with NetSuite is on | Sends a linked account's company name and phone to NetSuite when name, phone, billing or shipping changed. |
| schedule | Cron, every 15 minutes, while Sync with NetSuite is on | Starts a pull-changes run, and a send-orders run for records that wait for NetSuite and had no attempt for 15 minutes. |
| send-orders | A workflow and an action: Send to NetSuite, Retry and Retry failed orders, order-events and schedule | Works on one record, or on selected orders or records five per step in ID order, until each is sent, skipped or needs attention. |
| pull-changes | A workflow and an action: Get changes from NetSuite now, Sync all prices and stock, and schedule | Reads customers, then items, then followed sales orders, one page per step. Data full: true runs a full sync. |
| test-connection | The Test connection button | Gets a new token, reads price levels, locations, terms and subsidiaries, saves Connected account and clears the connection alert. |
| create-certificate | The Create certificate button | Makes an EC P-256 key pair and a self-signed certificate valid for 729 days, saves both and empties the certificate ID. |
| resolve | The Mark as resolved action, with an optional number | Sets the record to resolved, or to sent when its sales order is in NetSuite. |

The app's permissions are `write_orders`, `write_accounts`, `write_products`, `write_shipments` and `write_payments`. Besides its own fields and records, it writes `group`, `billing.company` and `phone` on accounts, `price` and `prices` on products and variants, stock adjustments through `POST /products:stock`, shipments with `$events: true`, and payments with `success: true` and `$events: true`.

To get a token, the app signs a JWT with ES256 and the private key in its settings, with the certificate ID as `kid`, the client ID as `iss`, the scope `rest_webservices` and ten minutes to live. It posts the JWT to `https://<account>.suitetalk.api.netsuite.com/services/rest/auth/oauth2/v1/token` with the client credentials grant, and keeps the token per worker until five minutes before it expires. In the host name, the account ID is in lowercase with `_` as `-`.

Reads are SuiteQL, `POST /query/v1/suiteql` with `Prefer: transient`, in pages of up to 1,000 rows. Writes use the record API: `POST /record/v1/customer` and `POST /record/v1/salesOrder`, and `PATCH` on a customer for company name and phone and on a sales order to set `isClosed` on its lines. The app reads `GET /record/v1/salesOrder/{id}` and `/record/v1/itemFulfillment/{id}` with `expandSubResources=true` for line quantities and package tracking numbers. It sends one request at a time per worker. Reads time out after 20 seconds and writes after 90. A 429 or `CONCURRENCY_LIMIT_EXCEEDED` is waited out for 1, 2 and 4 seconds, and a read that fails on the network or with a 5xx is repeated once.

A sales order's `externalId` is `swell-<order id>`, and a customer's is `swell-acc-<account id>`. Lines have `price` `-1` with `rate` and `amount`, and the PO number is `otherRefNum`, cut to 45 characters. `date_submitted` is set before the create call. A record still marked on a later attempt is looked up by its external ID, and sent again only if it isn't found five minutes after the first send. A duplicate answer adopts the existing sales order.

A worker takes a record by raising `attempts` with `$inc` and holding `locked_until` for five minutes. A run's step for one order retries 5 times, from 20 seconds with exponential backoff, and a step over a selection 4 times. `problem_code` is `temporary`, `connection`, `rejected`, `unavailable` or `internal`, or names the cause: `draft`, `canceled`, `not_business`, `no_items`, `no_sku`, `unknown_sku`, `duplicate_sku`, `no_customer`, `customer_rejected` or `no_order`. The schedule picks up records that are `pending`, or `sent` with `cancel` `requested`, and sets a record to `failed` once its `date_pending` is a day old. A `connection` failure stops a run over several records.

A pull reads customers in pages of 200, items in pages of 100 and followed sales orders in pages of 25, up to 500 pages each. A step retries 4 times, from 30 seconds with exponential backoff. A check reads what changed since `connection.last_checked` with ten minutes of overlap: at least 30 minutes, at most seven days, and 24 hours the first time. One pull runs at a time. The running one holds the unique `slot` `running` for up to 30 minutes. `unmatched` keeps up to 200 SKUs and `errors` up to 50 messages. A check that changed nothing and met no problem deletes its record.

An alert that was last seen less than a day ago is updated instead of created again, so it sends no second e-mail. Alerts are created with `$events: true` and a `$notify` name. Sending or resolving an order deletes the connection alert, and the orders alert once no record is `failed`.

## Support

Swell builds and maintains the NetSuite app. For help with the app, email support@swell.is. For questions about your NetSuite account, roles or integration records, ask your NetSuite administrator.

The app is open source under the MIT license. The source is on [GitHub](https://github.com/swellstores/netsuite-app).
