docusignapi - 无法使用 DocuSign 创建信封,API PARTNER_AUTHENTICATION_FAILED
问题描述
我正在尝试发送从我帐户中的模板创建的信封。但是,我总是得到回应:
HTTP 未经授权的 401
{"errorCode":"PARTNER_AUTHENTICATION_FAILED","message":"The specified Integrator Key was not found or is disabled. An Integrator key was not specified."}
这是我的代码:
from docusign_esign import TemplateRole, EnvelopesApi, RecipientViewRequest, EnvelopeDefinition, ApiClient
def create_api_client(base_path, access_token):
"""Create api client and construct API headers"""
api_client = ApiClient()
api_client.host = base_path
api_client.set_default_header(header_name="Authorization", header_value=f"Bearer {access_token}")
return api_client
class Eg001Controller:
@staticmethod
def get_args():
"""Get request and session arguments"""
# More data validation would be a good idea here
# Strip anything other than characters listed
# 1. Parse request arguments
signer_email = "my@email.com"
signer_name = "Some Random Guy"
envelope_args = {
"signer_email": signer_email,
"signer_name": signer_name,
"signer_client_id": "SOME_UNIQUE_VALUE",
"ds_return_url": "http://localhost:5000/ds/callback",
}
args = {
"account_id": {"API_CLIENT_ID"}, # My "API Account ID"
"base_path": "demo.docusign.net/restapi",
"access_token": "{ACCESS_TOKEN_GENERATED_BY_THE_EXAMPLE_CODE_LAUNCHER}",
"envelope_args": envelope_args
}
return args
@classmethod
def worker(cls, args):
"""
1. Create the envelope request object
2. Send the envelope
3. Create the Recipient View request object
4. Obtain the recipient_view_url for the embedded signing
"""
envelope_args = args["envelope_args"]
# 1. Create the envelope request object
envelope_definition = cls.make_envelope(envelope_args)
# 2. call Envelopes::create API method
# Exceptions will be caught by the calling function
print("creating client..")
api_client = create_api_client(base_path=args["base_path"], access_token=args["access_token"])
print("creating envelope..")
envelope_api = EnvelopesApi(api_client)
# It fails in the next line!
results = envelope_api.create_envelope(account_id=args["account_id"], envelope_definition=envelope_definition)
envelope_id = results.envelope_id
print(f"Created envelope ID: {envelope_id}")
# 3. Create the Recipient View request object
recipient_view_request = RecipientViewRequest(
authentication_method="None",
client_user_id=envelope_args["signer_client_id"],
recipient_id="1",
return_url=envelope_args["ds_return_url"],
user_name=envelope_args["signer_name"],
email=envelope_args["signer_email"]
)
# 4. Obtain the recipient_view_url for the embedded signing
# Exceptions will be caught by the calling function
results = envelope_api.create_recipient_view(
account_id=args["account_id"],
envelope_id=envelope_id,
recipient_view_request=recipient_view_request
)
return {"envelope_id": envelope_id, "redirect_url": results.url}
@classmethod
def make_envelope(cls, args):
"""
Creates envelope
args -- parameters for the envelope:
signer_email, signer_name, signer_client_id
returns an envelope definition
"""
print("creating envelope definition..")
# Create the envelope definition
envelope_definition = EnvelopeDefinition(
status="sent", # requests that the envelope be created and sent.
template_id="{TEMPLATE_ID}"
)
# Create template role elements to connect the signer and cc recipients
# to the template
signer = TemplateRole(
email="my@email.com",
name="Some Random Guy",
role_name='Signer',
client_user_id="SOME_UNIQUE_VALUE"
)
# Add the TemplateRole objects to the envelope object
envelope_definition.template_roles = [signer]
return envelope_definition
Eg001Controller.worker(Eg001Controller.get_args())
大部分代码都是从这个示例中复制而来的。
笔记:
- 我认为生成访问令牌可能存在问题,因此,我使用了运行他们的代码启动器时生成的相同令牌。令牌应该没有任何问题。
- 如果我使用此代码手动生成令牌,我也会得到相同的响应:(我正在使用 JWT auth)
def jwt_auth():
"""JSON Web Token authorization"""
api_client = ApiClient()
api_client.set_base_path(BASE_PATH)
# try:
ds_app = api_client.request_jwt_user_token(
client_id=INTEGRATION_KEY,
user_id=USER_ID,
oauth_host_name=AUTH_SERVER,
private_key_bytes=PRIVATE_KEY.encode("ascii").decode("utf-8"),
expires_in=3600, # Not configurable/extensible.
scopes=SCOPES
)
return ds_app
- 他们的代码启动器能够使用我的帐户成功完成嵌入式签名!
- 当我添加
X-DocuSign-Authentication
包含我的帐户用户名和密码的标题时,它可以工作。但是,我当然希望能够只使用令牌,而不是我的登录凭据! - 为什么添加
X-DocuSign-Authentication
使它起作用?
解决方案
"base_path": "demo.docusign.net/restapi",
应该改为
"base_path": "https://demo.docusign.net/restapi",
我已经提交了 DocuSign 内部票证,以便为此参数提供错误检查。
推荐阅读
- c - C 类型符号
- python - Python:计算列表的累积值和月值的公式
- enterprise-architect - 如何在 Enterprise Architect 中更改连接器的箭头大小?
- ios - CocoaPods:添加 AFNetworking 的一半依赖
- spring-boot - DataJPATest 尝试加载所有内容
- r - R - 生成二进制变量的函数
- makefile - 如果只有子字符串匹配,为什么要制定选择模式规则?
- kubernetes - 是否有命令检查哪些 pod 应用了服务
- vba - VBA - 范围的动态复制和过去
- c# - ObservableCollection Xamarin