Skip to content

The agent engineering platform.

Zapier update oauth support (#6780)

Robert Lewisda462d9dd4f2
diff --git a/docs/extras/modules/agents/tools/integrations/zapier.ipynb b/docs/extras/modules/agents/tools/integrations/zapier.ipynb
index fdc5255a90..06079315f5 100644
--- a/docs/extras/modules/agents/tools/integrations/zapier.ipynb
+++ b/docs/extras/modules/agents/tools/integrations/zapier.ipynb
@@ -7,7 +7,7 @@
"source": [
"# Zapier Natural Language Actions API\n",
"\\\n",
- "Full docs here: https://nla.zapier.com/api/v1/docs\n",
+ "Full docs here: https://nla.zapier.com/start/\n",
"\n",
"**Zapier Natural Language Actions** gives you access to the 5k+ apps, 20k+ actions on Zapier's platform through a natural language API interface.\n",
"\n",
@@ -21,7 +21,7 @@
"\n",
"2. User-facing (Oauth): for production scenarios where you are deploying an end-user facing application and LangChain needs access to end-user's exposed actions and connected accounts on Zapier.com\n",
"\n",
- "This quick start will focus on the server-side use case for brevity. Review [full docs](https://nla.zapier.com/api/v1/docs) or reach out to [email protected] for user-facing oauth developer support.\n",
+ "This quick start will focus on the server-side use case for brevity. Review [full docs](https://nla.zapier.com/start/) for user-facing oauth developer support.\n",
"\n",
"This example goes over how to use the Zapier integration with a `SimpleSequentialChain`, then an `Agent`.\n",
"In code, below:"
@@ -39,7 +39,7 @@
"# get from https://platform.openai.com/\n",
"os.environ[\"OPENAI_API_KEY\"] = os.environ.get(\"OPENAI_API_KEY\", \"\")\n",
"\n",
- "# get from https://nla.zapier.com/demo/provider/debug (under User Information, after logging in):\n",
+ "# get from https://nla.zapier.com/docs/authentication/ after logging in):\n",
"os.environ[\"ZAPIER_NLA_API_KEY\"] = os.environ.get(\"ZAPIER_NLA_API_KEY\", \"\")"
]
},
diff --git a/langchain/tools/zapier/tool.py b/langchain/tools/zapier/tool.py
index 96d3b7622b..9e770075e1 100644
--- a/langchain/tools/zapier/tool.py
+++ b/langchain/tools/zapier/tool.py
@@ -1,6 +1,6 @@
"""## Zapier Natural Language Actions API
\
-Full docs here: https://nla.zapier.com/api/v1/docs
+Full docs here: https://nla.zapier.com/start/
**Zapier Natural Language Actions** gives you access to the 5k+ apps, 20k+ actions
on Zapier's platform through a natural language API interface.
@@ -24,8 +24,8 @@ NLA offers both API Key and OAuth for signing NLA API requests.
connected accounts on Zapier.com
This quick start will focus on the server-side use case for brevity.
-Review [full docs](https://nla.zapier.com/api/v1/docs) or reach out to
[email protected] for user-facing oauth developer support.
+Review [full docs](https://nla.zapier.com/start/) for user-facing oauth developer
+support.
Typically, you'd use SequentialChain, here's a basic example:
@@ -42,8 +42,7 @@ import os
# get from https://platform.openai.com/
os.environ["OPENAI_API_KEY"] = os.environ.get("OPENAI_API_KEY", "")
-# get from https://nla.zapier.com/demo/provider/debug
-# (under User Information, after logging in):
+# get from https://nla.zapier.com/docs/authentication/
os.environ["ZAPIER_NLA_API_KEY"] = os.environ.get("ZAPIER_NLA_API_KEY", "")
from langchain.llms import OpenAI
@@ -61,8 +60,9 @@ from langchain.utilities.zapier import ZapierNLAWrapper
llm = OpenAI(temperature=0)
zapier = ZapierNLAWrapper()
-## To leverage a nla_oauth_access_token you may pass the value to the ZapierNLAWrapper
-## If you do this there is no need to initialize the ZAPIER_NLA_API_KEY env variable
+## To leverage OAuth you may pass the value `nla_oauth_access_token` to
+## the ZapierNLAWrapper. If you do this there is no need to initialize
+## the ZAPIER_NLA_API_KEY env variable
# zapier = ZapierNLAWrapper(zapier_nla_oauth_access_token="TOKEN_HERE")
toolkit = ZapierToolkit.from_zapier_nla_wrapper(zapier)
agent = initialize_agent(
@@ -99,7 +99,7 @@ class ZapierNLARunAction(BaseTool):
(eg. "get the latest email from Mike Knoop" for "Gmail: find email" action)
params: a dict, optional. Any params provided will *override* AI guesses
from `instructions` (see "understanding the AI guessing flow" here:
- https://nla.zapier.com/api/v1/docs)
+ https://nla.zapier.com/docs/using-the-api#ai-guessing)
"""
diff --git a/langchain/utilities/zapier.py b/langchain/utilities/zapier.py
index 4975ab6f32..d4da2f1c9f 100644
--- a/langchain/utilities/zapier.py
+++ b/langchain/utilities/zapier.py
@@ -1,6 +1,6 @@
"""Util that can interact with Zapier NLA.
-Full docs here: https://nla.zapier.com/api/v1/docs
+Full docs here: https://nla.zapier.com/start/
Note: this wrapper currently only implemented the `api_key` auth method for testing
and server-side production use cases (using the developer's connected accounts on
@@ -24,16 +24,20 @@ from langchain.utils import get_from_dict_or_env
class ZapierNLAWrapper(BaseModel):
"""Wrapper for Zapier NLA.
- Full docs here: https://nla.zapier.com/api/v1/docs
+ Full docs here: https://nla.zapier.com/start/
- Note: this wrapper currently only implemented the `api_key` auth method for
- testingand server-side production use cases (using the developer's connected
- accounts on Zapier.com)
+ This wrapper supports both API Key and OAuth Credential auth methods. API Key
+ is the fastest way to get started using this wrapper.
+
+ Call this wrapper with either `zapier_nla_api_key` or
+ `zapier_nla_oauth_access_token` arguments, or set the `ZAPIER_NLA_API_KEY`
+ environment variable. If both arguments are set, the Access Token will take
+ precedence.
For use-cases where LangChain + Zapier NLA is powering a user-facing application,
and LangChain needs access to the end-user's connected accounts on Zapier.com,
- you'll need to use oauth. Review the full docs above and reach out to
- [email protected] for developer support.
+ you'll need to use OAuth. Review the full docs above to learn how to create
+ your own provider and generate credentials.
"""
zapier_nla_api_key: str
@@ -120,7 +124,7 @@ class ZapierNLAWrapper(BaseModel):
`params` will always contain an `instructions` key, the only required
param. All others optional and if provided will override any AI guesses
(see "understanding the AI guessing flow" here:
- https://nla.zapier.com/api/v1/docs)
+ https://nla.zapier.com/docs/using-the-api#ai-guessing)
"""
session = self._get_session()
response = session.get(self.zapier_nla_api_base + "exposed/")
diff --git a/tests/unit_tests/tools/test_zapier.py b/tests/unit_tests/tools/test_zapier.py
index a4b60be965..4092b46df6 100644
--- a/tests/unit_tests/tools/test_zapier.py
+++ b/tests/unit_tests/tools/test_zapier.py
@@ -50,3 +50,19 @@ def test_custom_base_prompt_fail() -> None:
base_prompt=base_prompt,
api_wrapper=ZapierNLAWrapper(zapier_nla_api_key="test"),
)
+
+
+def test_wrapper_fails_no_api_key_or_access_token_initialization() -> None:
+ """Test Wrapper requires either an API Key or OAuth Access Token."""
+ with pytest.raises(ValueError):
+ ZapierNLAWrapper()
+
+
+def test_wrapper_api_key_initialization() -> None:
+ """Test Wrapper initializes with an API Key."""
+ ZapierNLAWrapper(zapier_nla_api_key="test")
+
+
+def test_wrapper_access_token_initialization() -> None:
+ """Test Wrapper initializes with an API Key."""
+ ZapierNLAWrapper(zapier_nla_oauth_access_token="test")