restsuite


Namerestsuite JSON
Version 1.0.0 PyPI version JSON
download
home_page
SummaryEasily work with Netsuite's REST API
upload_time2023-06-30 01:35:18
maintainer
docs_urlNone
authorPeter Williams, Richard Demke, Andy Gannaway
requires_python>=3.8
licenseMIT License Copyright (c) 2023 Peter Williams Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords netsuite oauth rest
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # restsuite

restsuite is a python package developed to help developers interact with the Netsuite REST API. restsuite offers a number of classes that can be utilized to interact with Netsuite's Suite-Talk, RESTlet, or SuiteQL services. restsuite currently utilizes Netsuite's token authentication methods, however, current development is under way for supporting Netsuite's Oauth2 authentication methods. 



## Installation

restsuite is part of the Python Package Index (PyPI) and can thus be installed with pip:

```
pip install restsuite
```

restsuite requires a python version of 3.8 or higher and depends on the [requests python package](https://requests.readthedocs.io/en/latest/) and the [requests_oauthlib python package](https://pypi.org/project/requests-oauthlib/)


## Getting Started

As restsuite is an abstraction of the Netsuite API, it will be helpful to become familiar with, or at least reference, the Netsuite API documentation:

- [Suite-Talk Documentation](https://docs.oracle.com/en/cloud/saas/netsuite/ns-online-help/chapter_1540391670.html)
- [RESTlet Documentation](https://docs.oracle.com/en/cloud/saas/netsuite/ns-online-help/section_N2970701.html)
- [SuiteQL Documentation](https://docs.oracle.com/en/cloud/saas/netsuite/ns-online-help/section_156257770590.html)

### Authentication

Each of the provided classes (NetSuiteRest, NetSuiteRESTlet, NetSuiteQL) utilize the [requests_oauthlib](https://pypi.org/project/requests-oauthlib/) package to handle authentication for the developer. All that is required is basic account information that can be generated in the user's account integration settings (see [REST Web Services Prerequisites and Setup](https://docs.oracle.com/en/cloud/saas/netsuite/ns-online-help/section_1544787084.html) for a guide on setting up your Netsuite application to utilize REST capabilities)

Each class requires that you pass the following attributes upon object instantiation:
- Netsuite Account ID : This can be found the Netsuite url path (e.g: *https://{{ account_id }}.app.netsuite.com)*)
- Consumer Key : Consumer Key and Secret are provided upon integration record creation [Integration Record Overview](https://docs.oracle.com/en/cloud/saas/netsuite/ns-online-help/section_4389727047.html).
- Consumer Secret : Consumer Secret is provided upon integation record creation [Integration Record Overview](https://docs.oracle.com/en/cloud/saas/netsuite/ns-online-help/section_4389727047.html)
- Token Key : Tokens can be generated a number of ways. We are currently developing a Class for generating tokens with the [issuetoken endpoint](https://docs.oracle.com/en/cloud/saas/netsuite/ns-online-help/chapter_157017286140.html). For the time being, you can [generate a token with the Netsuite UI](https://docs.oracle.com/en/cloud/saas/netsuite/ns-online-help/bridgehead_4254081947.html).
- Token Secret : See Token Key


## Suite-Talk

The *restsuite.NetSuiteRest* class provides an interface to NetSuite's [Suite-Talk API](https://docs.oracle.com/en/cloud/saas/netsuite/ns-online-help/chapter_1540391670.html). 

For a full list of available resources, see the [NetSuite REST API Browser: Record API v1](https://system.netsuite.com/help/helpcenter/en_US/APIs/REST_API_Browser/record/v1/2022.2/index.html)

#### Examples:

Instantiating a Suite-Talk object:
```python
import restsuite

netsuite = restsuite.NetSuiteRest(
    account_id = NS_ACCOUNT_ID,
    consumer_key = CONSUMER_KEY,
    consumer_secret = CONSUMER_SECRET,
    token_key = TOKEN_KEY,
    token_secret = TOKEN_SECRET
)
```

#### Getting a Record (GET):
```python
url = "https://{}.suitetalk.api.netsuite.com/services/rest/record/v1/job".format(NS_ACCOUNT_ID)

response = netsuite.request("GET", url)

if response.status_code < 300:
    data = response.json()
```
*[Getting docs](https://docs.oracle.com/en/cloud/saas/netsuite/ns-online-help/section_1545141500.html#Getting-a-Record-Instance)*

*It is important to note here that all classes will require the full URL to be passed to each request method.*

#### Creating a Record object (POST):
```python
url = "https://{}.suitetalk.api.netsuite.com/services/rest/record/v1/job/12345".format(NS_ACCOUNT_ID)

body = {"entityid": "New Customer", "companyname": "My Company", "subsidiary": {"id": "1"}}

response = netsuite.request("POST", url=url, body=body)
```
*[Creating docs](https://docs.oracle.com/en/cloud/saas/netsuite/ns-online-help/section_1545141395.html)*

#### Updating a Record object (PATCH):
```python
url = "https://{}.suitetalk.api.netsuite.com/services/rest/record/v1/job/12345".format(NS_ACCOUNT_ID)

body = {"entityid": "Updated Customer"}

response = netsuite.request("PATCH", url=url, body=body)
```
*[Updating docs](https://docs.oracle.com/en/cloud/saas/netsuite/ns-online-help/section_1545142173.html)*

#### Upserting a Record object (PUT):
```python
url = "https://{}.suitetalk.api.netsuite.com/services/rest/record/v1/job/12345".format(NS_ACCOUNT_ID)

body = {"firstName": "John", "lastName": "Smith"}

response = netsuite.request("PUT", url=url, body=body)
```
*[Upsert docs](https://docs.oracle.com/en/cloud/saas/netsuite/ns-online-help/section_156335203191.html)*

#### Deleting a Record object (DELETE)
```python
url = "https://{}.suitetalk.api.netsuite.com/services/rest/record/v1/job/12345".format(NS_ACCOUNT_ID)

response = netsuite.request("DELETE", url=url)
```

## RESTlet

"A restlet is a SuiteScript that executes when called by an external application or by another SuiteScript. Depending on how the RESTlet is written and called, it may also return data to the calling application."

The *restsuite.NetSuiteRESTlet* class acts as an external application that allows you to activate RESTlets based on a handful of HTTP verbs:

- GET
- POST
- PUT
- DELETE

These verbs, however, act more as a guide than as the strict HTTP verbs described [here](https://www.w3schools.in/http/http-request-methods). This is because the actual actions taken are defined in the RESTlets themselves, and the verbs are used to call certain functions within the RESTlet. More information can be found on RESTlets [here](https://docs.oracle.com/en/cloud/saas/netsuite/ns-online-help/section_N2970701.html).

#### Examples:

Calling a RESTlet is similar to the Suite-Talk methods shown above. Only one example will be given here to highlight the difference in the URL path, everything else will be the same.

#### Sending a GET request to RESTlet:
```python
import restsuite

netsuite = restsuite.NetSuiteRESTlet(
    account_id = NS_ACCOUNT_ID,
    consumer_key = CONSUMER_KEY,
    consumer_secret = CONSUMER_SECRET,
    token_key = TOKEN_KEY,
    token_secret = TOKEN_SECRET
)

url = "https://{}.restlets.api.netsuite.com/app/site/hosting/restlet.nl?script={}&deploy={}".format(NS_ACCOUNT_ID, SCRIPT_ID, DEPLOYMENT_ID)

response = netsuite.request("GET", url)
```

## SuiteQL

NetSuite allows for users to query their records their version of SQL, SuiteQL. In order to utilize SuiteQL, query strings are sent to a suiteql endpoint. SuiteQL queries can be sent to Netsuite using the NetSuiteQL class:

```python
import restsuite

netsuite = restsuite.NetSuiteQL(
    account_id = NS_ACCOUNT_ID,
    consumer_key = CONSUMER_KEY,
    consumer_secret = CONSUMER_SECRET,
    token_key = TOKEN_KEY,
    token_secret = TOKEN_SECRET
)

data = netsuite.suiteql("Select * From job where id = 12345")
print(data)
```

The *suiteql* method returns a list of dictionary-type objects, where each object is a record of the queried record-type. For this specific example, each object would be a job record-type that matched the id of 12345.

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "restsuite",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "netsuite,oauth,rest",
    "author": "Peter Williams, Richard Demke, Andy Gannaway",
    "author_email": "Peter Williams <petercw94@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/66/ed/876a6ae33faba876700d6587f89647c57ec900cadb12a21ce3e9eeaeac38/restsuite-1.0.0.tar.gz",
    "platform": null,
    "description": "# restsuite\n\nrestsuite is a python package developed to help developers interact with the Netsuite REST API. restsuite offers a number of classes that can be utilized to interact with Netsuite's Suite-Talk, RESTlet, or SuiteQL services. restsuite currently utilizes Netsuite's token authentication methods, however, current development is under way for supporting Netsuite's Oauth2 authentication methods. \n\n\n\n## Installation\n\nrestsuite is part of the Python Package Index (PyPI) and can thus be installed with pip:\n\n```\npip install restsuite\n```\n\nrestsuite requires a python version of 3.8 or higher and depends on the [requests python package](https://requests.readthedocs.io/en/latest/) and the [requests_oauthlib python package](https://pypi.org/project/requests-oauthlib/)\n\n\n## Getting Started\n\nAs restsuite is an abstraction of the Netsuite API, it will be helpful to become familiar with, or at least reference, the Netsuite API documentation:\n\n- [Suite-Talk Documentation](https://docs.oracle.com/en/cloud/saas/netsuite/ns-online-help/chapter_1540391670.html)\n- [RESTlet Documentation](https://docs.oracle.com/en/cloud/saas/netsuite/ns-online-help/section_N2970701.html)\n- [SuiteQL Documentation](https://docs.oracle.com/en/cloud/saas/netsuite/ns-online-help/section_156257770590.html)\n\n### Authentication\n\nEach of the provided classes (NetSuiteRest, NetSuiteRESTlet, NetSuiteQL) utilize the [requests_oauthlib](https://pypi.org/project/requests-oauthlib/) package to handle authentication for the developer. All that is required is basic account information that can be generated in the user's account integration settings (see [REST Web Services Prerequisites and Setup](https://docs.oracle.com/en/cloud/saas/netsuite/ns-online-help/section_1544787084.html) for a guide on setting up your Netsuite application to utilize REST capabilities)\n\nEach class requires that you pass the following attributes upon object instantiation:\n- Netsuite Account ID : This can be found the Netsuite url path (e.g: *https://{{ account_id }}.app.netsuite.com)*)\n- Consumer Key : Consumer Key and Secret are provided upon integration record creation [Integration Record Overview](https://docs.oracle.com/en/cloud/saas/netsuite/ns-online-help/section_4389727047.html).\n- Consumer Secret : Consumer Secret is provided upon integation record creation [Integration Record Overview](https://docs.oracle.com/en/cloud/saas/netsuite/ns-online-help/section_4389727047.html)\n- Token Key : Tokens can be generated a number of ways. We are currently developing a Class for generating tokens with the [issuetoken endpoint](https://docs.oracle.com/en/cloud/saas/netsuite/ns-online-help/chapter_157017286140.html). For the time being, you can [generate a token with the Netsuite UI](https://docs.oracle.com/en/cloud/saas/netsuite/ns-online-help/bridgehead_4254081947.html).\n- Token Secret : See Token Key\n\n\n## Suite-Talk\n\nThe *restsuite.NetSuiteRest* class provides an interface to NetSuite's [Suite-Talk API](https://docs.oracle.com/en/cloud/saas/netsuite/ns-online-help/chapter_1540391670.html). \n\nFor a full list of available resources, see the [NetSuite REST API Browser: Record API v1](https://system.netsuite.com/help/helpcenter/en_US/APIs/REST_API_Browser/record/v1/2022.2/index.html)\n\n#### Examples:\n\nInstantiating a Suite-Talk object:\n```python\nimport restsuite\n\nnetsuite = restsuite.NetSuiteRest(\n    account_id = NS_ACCOUNT_ID,\n    consumer_key = CONSUMER_KEY,\n    consumer_secret = CONSUMER_SECRET,\n    token_key = TOKEN_KEY,\n    token_secret = TOKEN_SECRET\n)\n```\n\n#### Getting a Record (GET):\n```python\nurl = \"https://{}.suitetalk.api.netsuite.com/services/rest/record/v1/job\".format(NS_ACCOUNT_ID)\n\nresponse = netsuite.request(\"GET\", url)\n\nif response.status_code < 300:\n    data = response.json()\n```\n*[Getting docs](https://docs.oracle.com/en/cloud/saas/netsuite/ns-online-help/section_1545141500.html#Getting-a-Record-Instance)*\n\n*It is important to note here that all classes will require the full URL to be passed to each request method.*\n\n#### Creating a Record object (POST):\n```python\nurl = \"https://{}.suitetalk.api.netsuite.com/services/rest/record/v1/job/12345\".format(NS_ACCOUNT_ID)\n\nbody = {\"entityid\": \"New Customer\", \"companyname\": \"My Company\", \"subsidiary\": {\"id\": \"1\"}}\n\nresponse = netsuite.request(\"POST\", url=url, body=body)\n```\n*[Creating docs](https://docs.oracle.com/en/cloud/saas/netsuite/ns-online-help/section_1545141395.html)*\n\n#### Updating a Record object (PATCH):\n```python\nurl = \"https://{}.suitetalk.api.netsuite.com/services/rest/record/v1/job/12345\".format(NS_ACCOUNT_ID)\n\nbody = {\"entityid\": \"Updated Customer\"}\n\nresponse = netsuite.request(\"PATCH\", url=url, body=body)\n```\n*[Updating docs](https://docs.oracle.com/en/cloud/saas/netsuite/ns-online-help/section_1545142173.html)*\n\n#### Upserting a Record object (PUT):\n```python\nurl = \"https://{}.suitetalk.api.netsuite.com/services/rest/record/v1/job/12345\".format(NS_ACCOUNT_ID)\n\nbody = {\"firstName\": \"John\", \"lastName\": \"Smith\"}\n\nresponse = netsuite.request(\"PUT\", url=url, body=body)\n```\n*[Upsert docs](https://docs.oracle.com/en/cloud/saas/netsuite/ns-online-help/section_156335203191.html)*\n\n#### Deleting a Record object (DELETE)\n```python\nurl = \"https://{}.suitetalk.api.netsuite.com/services/rest/record/v1/job/12345\".format(NS_ACCOUNT_ID)\n\nresponse = netsuite.request(\"DELETE\", url=url)\n```\n\n## RESTlet\n\n\"A restlet is a SuiteScript that executes when called by an external application or by another SuiteScript. Depending on how the RESTlet is written and called, it may also return data to the calling application.\"\n\nThe *restsuite.NetSuiteRESTlet* class acts as an external application that allows you to activate RESTlets based on a handful of HTTP verbs:\n\n- GET\n- POST\n- PUT\n- DELETE\n\nThese verbs, however, act more as a guide than as the strict HTTP verbs described [here](https://www.w3schools.in/http/http-request-methods). This is because the actual actions taken are defined in the RESTlets themselves, and the verbs are used to call certain functions within the RESTlet. More information can be found on RESTlets [here](https://docs.oracle.com/en/cloud/saas/netsuite/ns-online-help/section_N2970701.html).\n\n#### Examples:\n\nCalling a RESTlet is similar to the Suite-Talk methods shown above. Only one example will be given here to highlight the difference in the URL path, everything else will be the same.\n\n#### Sending a GET request to RESTlet:\n```python\nimport restsuite\n\nnetsuite = restsuite.NetSuiteRESTlet(\n    account_id = NS_ACCOUNT_ID,\n    consumer_key = CONSUMER_KEY,\n    consumer_secret = CONSUMER_SECRET,\n    token_key = TOKEN_KEY,\n    token_secret = TOKEN_SECRET\n)\n\nurl = \"https://{}.restlets.api.netsuite.com/app/site/hosting/restlet.nl?script={}&deploy={}\".format(NS_ACCOUNT_ID, SCRIPT_ID, DEPLOYMENT_ID)\n\nresponse = netsuite.request(\"GET\", url)\n```\n\n## SuiteQL\n\nNetSuite allows for users to query their records their version of SQL, SuiteQL. In order to utilize SuiteQL, query strings are sent to a suiteql endpoint. SuiteQL queries can be sent to Netsuite using the NetSuiteQL class:\n\n```python\nimport restsuite\n\nnetsuite = restsuite.NetSuiteQL(\n    account_id = NS_ACCOUNT_ID,\n    consumer_key = CONSUMER_KEY,\n    consumer_secret = CONSUMER_SECRET,\n    token_key = TOKEN_KEY,\n    token_secret = TOKEN_SECRET\n)\n\ndata = netsuite.suiteql(\"Select * From job where id = 12345\")\nprint(data)\n```\n\nThe *suiteql* method returns a list of dictionary-type objects, where each object is a record of the queried record-type. For this specific example, each object would be a job record-type that matched the id of 12345.\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) 2023 Peter Williams  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.",
    "summary": "Easily work with Netsuite's REST API",
    "version": "1.0.0",
    "project_urls": {
        "Homepage": "https://github.com/Petercw94/restsuite"
    },
    "split_keywords": [
        "netsuite",
        "oauth",
        "rest"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b412bac3c86ee8a986219e0ba6da1bfeb1006fe351ae35c9b7cb2ba54f6f5594",
                "md5": "eb953b81e4ad7b287726cd0a2661a8af",
                "sha256": "55d231f4c380f3c90a7251cf0d0c70b630fef8e3463d7a3256f1adc13bf62082"
            },
            "downloads": -1,
            "filename": "restsuite-1.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "eb953b81e4ad7b287726cd0a2661a8af",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 11330,
            "upload_time": "2023-06-30T01:35:17",
            "upload_time_iso_8601": "2023-06-30T01:35:17.018646Z",
            "url": "https://files.pythonhosted.org/packages/b4/12/bac3c86ee8a986219e0ba6da1bfeb1006fe351ae35c9b7cb2ba54f6f5594/restsuite-1.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "66ed876a6ae33faba876700d6587f89647c57ec900cadb12a21ce3e9eeaeac38",
                "md5": "a3fb44f212bda5e7172c95f48dc3846f",
                "sha256": "89db3a637407a186b2143706afb82e61fb2455b4841259f5ee6455aea437f6cb"
            },
            "downloads": -1,
            "filename": "restsuite-1.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "a3fb44f212bda5e7172c95f48dc3846f",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 12048,
            "upload_time": "2023-06-30T01:35:18",
            "upload_time_iso_8601": "2023-06-30T01:35:18.664837Z",
            "url": "https://files.pythonhosted.org/packages/66/ed/876a6ae33faba876700d6587f89647c57ec900cadb12a21ce3e9eeaeac38/restsuite-1.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-06-30 01:35:18",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Petercw94",
    "github_project": "restsuite",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "restsuite"
}
        
Elapsed time: 0.08931s