Skip to content

Commit

Permalink
feat: adding token_info restapi command
Browse files Browse the repository at this point in the history
  • Loading branch information
iloveitaly committed Jan 25, 2024
1 parent 372d2f6 commit dbeaf0a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
25 changes: 23 additions & 2 deletions netsuite/rest_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ async def delete(self, subpath: str, **request_kw):

async def suiteql(self, q: str, limit: int = 10, offset: int = 0, **request_kw):
"""
suiteql(q="SELECT * FROM Transaction", limit=10, offset=0)
Example:
>>> suiteql(q="SELECT * FROM Transaction", limit=10, offset=0)
"""
return await self._request(
"POST",
Expand All @@ -73,9 +74,29 @@ async def jsonschema(self, record_type: str, **request_kw):
**request_kw,
)

async def token_info(self, **request_kw):
"""
Retrieves metadata about the current token. Role, company, etc.
https://docs.oracle.com/en/cloud/saas/netsuite/ns-online-help/chapter_157017286140.html#Issue-Token-and-Revoke-Token-REST-Services-for-Token-based-Authentication
"""

# this overrides the default URL generation: this specific endpoint hits a completely different host
request_kw[
"url"
] = f"https://{self._config.account_slugified}.restlets.api.netsuite.com/rest/tokeninfo"

return await self._request(
method="GET",
# useless, but required by _request
subpath="ignored",
**request_kw,
)

async def openapi(self, record_types: Sequence[str] = (), **request_kw):
"""
Retrieves the OpenAPI specification (metadata catalog) for the Netsuite REST API.
Retrieves the OpenAPI specification (metadata catalog) for the Netsuite REST API. This is the best way to
introspect the NetSuite account and return the record structure.
Args:
record_types (Sequence[str]): Optional. List of record types to include in the OpenAPI specification.
Expand Down
2 changes: 1 addition & 1 deletion netsuite/rest_api_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ async def _request_impl(
self, method: str, subpath: str, **request_kw
) -> httpx.Response:
method = method.upper()
url = self._make_url(subpath)
url = request_kw.pop("url", self._make_url(subpath))

headers = {**self._make_default_headers(), **request_kw.pop("headers", {})}

Expand Down

0 comments on commit dbeaf0a

Please sign in to comment.