pythonnetsuitesuiteql

NetSuite -Invalid search query - cant query tables under 'connect Browser'


I'm having a problem to query the data from netsuite with get requests. Every time I want to query a table which is under connect Browser I get a bad request error: Invalid search query

def post_sql(url, realm, token_key, token_secret, consumer_key, consumer_secret):
header_oauth = OAuth1(  client_key=consumer_key, client_secret=consumer_secret,
                        resource_owner_key=token_key, resource_owner_secret=token_secret,
                        signature_type='auth_header',
                        realm=realm,
                        signature_method='HMAC-SHA256')
conn = requests.post(url, headers={"Prefer":"transient"}, auth=header_oauth, json={
"q": 'SELECT * FROM Sales_reps'
    
  })

return conn.json()

But when I query tables from analytics browser it works perfectly after changing a table names slightly (transaction_lines into transactionline and so on).

Does anyone know what could be a problem?

This is the list of queries I want to perform:

SELECT * FROM ACCOUNTS
SELECT * FROM TRANSACTION_LINES
SELECT * FROM TRANSACTIONS
SELECT * FROM ITEMS
SELECT * FROM ENTITY
SELECT * FROM DEPARTEMENTS 
SELECT * FROM LOCATIONS
SELECT * FROM SALES_REPS
SELECT * FROM EMPLOYEES
SELECT * FROM CUSTOMERS
SELECT * FROM ENTITY_STATUS
SELECT * FROM ENTITY_STATUS_HISTORY

Solution

  • Probably the error is because you are using the wrong scheme database to apply those queries. Remember that NetSuite has two DataBase with different table names.

    Here you have a example of the different tables names on each scheme.

        <table style="border:solid">
          <tr>
            <th style="border:solid">Scheme NetSuite.com Table</th>
            <th style="border:solid">Scheme NetSuite2.com Table</th>
          </tr>
          <tr>
            <td style="border:solid">ACCOUNTS</td>
            <td style="border:solid">ACCOUNT</td>    
          </tr>
          <tr>
            <td style="border:solid">TRANSACTION_LINES</td>
            <td style="border:solid">TRANSACTIONLINE</td>
          </tr>
          <tr>
            <td style="border:solid">TRANSACTIONS</td>
            <td style="border:solid">TRANSACTION</td>
          </tr>
          <tr>
            <td style="border:solid">SALES_REPS</td>
            <td style="border:solid">VENDOR</td>
          </tr>
        </table>