DocuSign API(PHP SDK)-为什么会收到此响应? “请求服务器时出错,收到了带有响应正文的不成功的HTTP代码[302]:”

时间:2020-11-01 14:50:54

标签: php docusignapi

我正在尝试使用DocuSign PHP SDK发送基于模板的签名请求。我正在尝试遵循此示例中概述的步骤:https://developers.docusign.com/docs/esign-rest-api/how-to/request-signature-template-remote

要进行身份验证,我正在使用JWT。我组装了由DocuSign生成的,用RSA256私钥签名的标头和有效负载,并且作为响应,我收到的访问令牌采用以下格式: eyJ0eXAiOiJ ----- .. yyyyyy -----。zzzzzz ----- (例如,实际令牌要更长)。

当我尝试在此处运行此代码时(输入上面的访问令牌和DocuSign凭据作为参数):

private function worker($args)
{
    $envelope_args = $args["envelope_args"];
    # Create the envelope request object
    $envelope_definition = $this->make_envelope($envelope_args);
    # Call Envelopes::create API method
    # Exceptions will be caught by the calling function
    $config = new \DocuSign\eSign\Configuration();
    $config->setHost($args['base_path']);
    $config->addDefaultHeader('Authorization', 'Bearer ' . $args['ds_access_token']);
    $api_client = new \DocuSign\eSign\client\ApiClient($config);
    $envelope_api = new \DocuSign\eSign\Api\EnvelopesApi($api_client);
    try {
        $results = $envelope_api->createEnvelope($args['account_id'], $envelope_definition);
        $envelope_id = $results->getEnvelopeId();
    }
    catch(ApiException $apiException) {
        echo $apiException->getMessage();
    }
    return ['envelope_id' => $envelope_id];
}

然后我最终捕获了一个异常:

Error while requesting server, received a non successful HTTP code [302] with response Body:

深入研究并var_dumping响应,正文确实是空的,这里是响应头:

array(
  0 => string 'HTTP/1.1 302 Found'
  'Cache-Control' => string 'no-cache'
  'Content-length' => string '0'
  'Location' => string 'https://account-d.docusign.com/v2.1/accounts/6d7dc630-xxxx-xxxx-xxxx-xxxxxxxxxxxx/envelopes'
  'Connection' => string 'close'
)

我已在响应的“位置”部分中屏蔽了该数字,以防万一。作为DS API的新手,我不清楚这个数字是多少。这不是我在项目配置中定义的任何内容。

有人知道此错误消息表示什么吗?我是否要访问不正确的API端点?这是否表明我的JWT访问令牌无效?还有吗?

感谢您提供的任何帮助。

1 个答案:

答案 0 :(得分:0)

一种更好的技术是使用php quickstart,然后复制从模板创建信封的示例

重新输入您的当前代码:我将检查您的基本路径。

还要检查您的访问令牌。您的软件将被重定向到帐户服务器