Skip to content

Commit

Permalink
Add ability to include additional headers in a search request (#68)
Browse files Browse the repository at this point in the history
* Add ability to include additional headers in a search request

This allows me to add headers such as `{'searchPreferences': {'bodyFieldsOnly': False}}` so that I can get a more detailed response back from the Search action.

My use case was getting the list of values back from a CustomList object. The only way to do that is to include those headers.

* fix style

* fix style

* fix style
  • Loading branch information
expressintegrations authored Dec 13, 2023
1 parent 10a2cf6 commit 33e1cef
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions netsuite/soap_api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,9 @@ def SupplyChain(self) -> zeep.client.Factory:
def SupplyChainTypes(self) -> zeep.client.Factory:
return self._type_factory("types.supplychain", "lists")

async def request(self, service_name: str, *args, **kw):
async def request(
self, service_name: str, *args, additionalHeaders: Optional[dict] = None, **kw
):
"""
Make a web service request to NetSuite
Expand All @@ -339,7 +341,10 @@ async def request(self, service_name: str, *args, **kw):
The response from NetSuite
"""
svc = getattr(self.service, service_name)
return await svc(*args, _soapheaders=self.generate_passport(), **kw)
headers = self.generate_passport()
if additionalHeaders:
headers.update(additionalHeaders)
return await svc(*args, _soapheaders=headers, **kw)

@WebServiceCall(
"body.readResponseList.readResponse",
Expand Down Expand Up @@ -455,10 +460,12 @@ async def upsert(self, record: zeep.xsd.CompoundValue) -> zeep.xsd.CompoundValue
extract=lambda resp: resp["recordList"]["record"],
)
async def search(
self, record: zeep.xsd.CompoundValue
self, record: zeep.xsd.CompoundValue, additionalHeaders: Optional[dict] = None
) -> List[zeep.xsd.CompoundValue]:
"""Search records"""
return await self.request("search", searchRecord=record)
return await self.request(
"search", searchRecord=record, additionalHeaders=additionalHeaders
)

@WebServiceCall(
"body.writeResponseList",
Expand Down

0 comments on commit 33e1cef

Please sign in to comment.