首页 > 解决方案 > 从 Python 访问 Netsuite 保存的搜索数据

问题描述

我正在尝试使用 python 访问从 Netsuite Saved Search 获得的数据。我想编写一个脚本(在 python 中)运行保存的搜索并将结果保存在我的计算机上。

我在哪里可以阅读有关如何构建我的 API 请求以成功执行此操作的信息?帮助文档很糟糕。

在 python 中执行此操作的任何代码示例?

标签: pythonnetsuitesaved-searches

解决方案


假设:1)您已经在 NetSuite 中创建了一个集成并且您已经准备好令牌 2)您已经部署了一个运行已保存搜索的套件脚本

那么你的python脚本可以是以下内容:

from requests_oauthlib import OAuth1Session

session = OAuth1Session(
    client_key='**YOUR_KEYS**',
    client_secret='**YOUR_KEYS**',
    resource_owner_key='**YOUR_KEYS**',
    resource_owner_secret='**YOUR_KEYS**',
    signature_type='auth_header',
    signature_method='HMAC-SHA256',
    realm='**YOUR_NETSUITE_ACCOUNT_NUMBER**',
)

r = session.get(

 url='https://**YOUR_NETSUITE_ACCOUNT**.restlets.api.netsuite.com/app/site/hosting/restlet.nl?script=**YOUR_SCRIPT_DEPLOYMENT_ID**&deploy=1&searchId'
                '=**YOUR_SAVED_SEARCH_ID**',
            headers={'Content-Type': 'application/json'
                     }
        )

netsuite = r.json()
print(netsuite)```

推荐阅读