Tutorial: Using Postman with OAuth 2.0

This tutorial walks you through the setup for OAuth 2.0 in both NetSuite and Postman. Once you're set up, you'll be able to perform CRUD actions on elements of your NetSuite account.

Prerequisites

Before starting, you will need the proper roles, permissions, and features set up in your NetSuite account. For more information, see Prerequisites and Setup for REST Web Services. You will also need to install the Postman desktop application. For more information, see Installing Postman

Step 1: Integration record for application

  1. In your NetSuite account, create a new integration record. Don't save it yet. For how to create this record, see Create Integration Records for Applications to Use OAuth 2.0.

    An integration record is what allows for a connection between Postman and your NetSuite account.

  2. In the Authentication tab, set up your integration record:

    Authentication area
    • Under Token-based Authentication, make sure all options cleared.

    • Under OAuth 2.0, make sure only the following options are checked or filled in:

    • Under User Credentials, leave all options cleared.

  3. Before clicking Save, note that when you do, the client ID and secret will display at the bottom of the page. Make note of both the ID and secret, as you'll need them later and you won't be able to access them again.

    Important:

    The system displays the client ID and client secret only the first time you save the integration record. After you leave this page, these values cannot be retrieved from the system. If you lose or forget the client ID and client secret, you will have to reset them on the Integration page, to obtain new values. Treat these values as you would a password.

  4. Click Save.

Step 2: Postman environment

  1. Follow these steps to import and set up a Postman environment: Importing and Setting Up a Postman Environment.

  2. Follow these steps to import a Postman collection: Importing the Postman Collection.

  3. Follow these steps to test a request: Sending a Request From the Imported Collection.

Step 3: Postman token

Creating the token:

  1. In Postman, open the Collections tab and select your collection that you created in step 2.

    Image with arrow pointing to a collection in Postman
  2. Open the Authorization tab then make the following selections:

    An image with an arrow pointing to the Authorization tab in Postman
    1. For Auth Type, select OAuth 2.0.

    2. For Add authorization data to, select Request Headers.

  3. In the Configure New Token section, select or fill in the following:

    1. Token name: Give your token a name.

    2. Grant type: Select Authorization Code.

    3. Callback URL: The same URL you used for the Redirect URI.

    4. Auth URL: https://<youraccountID>.app.netsuite.com/app/login/oauth2/authorize.nl

      Replace <youraccountID> with your own account ID.

    5. Access Token URL: https://<youraccountID>.app.netsuite.com/services/rest/auth/oauth2/v1/token

      Replace <youraccountID> with your own account ID.

    6. Client ID: Use the client ID from your integration record.

    7. Client Secret: Use the client secret from your integration record.

    8. Scope: rest_webservices

    9. State: This can be any random string of ASCII characters. It must include at least 22 characters.

    10. Client Authentication: Send as Basic Auth header

  4. Click Get New Access Token. If you get the NetSuite login screen after clicking Get New Access Token, log in to your account and confirm the message that appears.

  5. Click Use Token.

    Manage Access Tokens dialog

    The token will now show up as your selection under Current Token.

  6. Click Save.

    Save button in Postman

Testing the token:

  1. Create a new HTTP GET request.

    Arrows pointing to options to select in Postman to create a GET request
  2. Click Save.

    Image with arrow to indicate the Save button to save a GET request
  3. Select the collection you set up in step 2, then click New Folder and create a new folder.

    Image indicating which folder to select Image indicating where to click to create a new folder
  4. Give your request a name and click Save.

    Save Request dialog
  5. Insert the URL into the GET field. To learn more about this URL, see REST Web Services URL Schema and Account-Specific URLs. For this tutorial, you can use https://<youraccountID>.suitetalk.api.netsuite.com/services/rest/record/v1/metadata-catalog/customer

    Replace <youraccountID> with your account ID.

    Arrow indicating where to insert URL
  6. Open the Authorization tab.

  7. Under Auth Type, select Inherit auth from parent.

  8. Click Send to test if the connection works.

    Arrow indicating Send button

Step 4: CRUD in Postman

You can now perform CRUD in Postman for your NetSuite account. Try completing the following examples:

Creating a contact:

  1. Create a new HTTP request.

    Image indicating how to create a new HTTP request
  2. Make sure the request is POST.

    Image indicating POST option
  3. Save this request in the same folder you created when testing the token (see "Testing the token" under "Step 3: Postman token").

  4. Under the Authorization tab, select Inherit from parent.

  5. Insert the URL into the POST field. For this example, you can use https://<youraccountID>.suitetalk.api.netsuite.com/services/rest/record/v1/contact

    Replace <youraccountID> with your own.

  6. Open the Body tab, and select the raw option. Make sure the drop-down option has JSON selected.

    Arrows indicating which options to select
  7. Enter the information you want for your contact. At a minimum, you should include an entityId. You can see all the available fields for contact records as well as data types here.

    Image indicating where to add your text

    For this example, you can enter the following.

                    {"entityid": "ExampleContact_1234","comments":"Example text"} 
    
                  
  8. Click Send.

    You should see a "204 No Content" message if the POST was successful.

  9. If you go into NetSuite, the contact now appears in your contacts list.

Updating a contact:

  1. Create a new HTTP request.

  2. Make sure the request is a PATCH.

  3. Save this request in the same folder you created when testing the token (see "Testing the token" under "Step 3: Postman token").

  4. Under the Authorization tab, select Inherit from parent.

  5. Insert the URL into the PATCH field. For this example, you can use https://<youraccountID>.suitetalk.api.netsuite.com/services/rest/record/v1/contact

    Replace <youraccountID> with your own.

  6. Add the Internal ID for the contact you just created to the end of the URL. https://<youraccountID>.suitetalk.api.netsuite.com/services/rest/record/v1/contact/<internalId>

    You can find a contact's internal ID on the Contacts page.

    Image indicating where to find internal IDs in your account
  7. Open the Body tab, and select the raw option. Make sure the drop-down option has JSON selected.

  8. Enter the information you want updated for your contact. For this example, you can update the entityId. You can see all the available fields for contact and their names as well as data types here.

                    {"entityid": "ExampleContact_5678"} 
    
                  
  9. Click Send.

    You should see a "204 No Content" message if the PATCH was successful.

  10. Now, if you refresh the page in NetSuite, the contact's name will be updated.

Deleting a contact:

  1. Create a new HTTP request.

  2. Make sure the request is a DELETE.

  3. Save this request in the same folder you created when testing the token (see "Testing the token" under "Step 3: Postman token").

  4. Under the Authorization tab, select Inherit from parent.

  5. Insert the URL into the DELETE field. For this example, you can use https://<youraccountID>.suitetalk.api.netsuite.com/services/rest/record/v1/contact

    Replace <youraccountID> with your own.

  6. Add the Internal ID to the end of the URL. https://<your account ID>.suitetalk.api.netsuite.com/services/rest/record/v1/contact/<internalId>

  7. Click Send.

    You should see a "204 No Content" message if the DELETE was successful.

  8. Now, if you refresh the page in NetSuite, the contact will be gone from your contact list.

Related Topics

General Notices