BulkEnvelopesApi Docusign请求数据格式

时间:2018-06-13 05:56:23

标签: ruby docusignapi

我在使用BulkEnvelopesApi rom Docusign API for Ruby时遇到困难。它继续给我这个错误:

  

DocuSign_eSign :: ApiError(错误请求):

编辑:在@kiddorails建议包含debug = True之后,错误消息为:

  

{" errorCode":" UNSPECIFIED_ERROR"," message":"值不能是   null。\ r \ nParameter name:stream" }

我正在使用这个宝石:https://github.com/docusign/docusign-ruby-client

我输入数据的格式有什么问题吗?

这是我的代码供参考。

  def self.send_env()
    self.auth # To initialize the @api_client

    t1 = DocuSign_eSign::TemplatesApi.new(@api_client)
    signer_placeholder ={"signers":[{"email":"bulk@recipient.com","name":"Bulk Recipient",
                                     "routingOrder":1,"recipientId":"1","roleName":"Fruit",
                                     "isBulkRecipient":"True"}]}
    t1.update_recipients(account_id=ENV["ACCOUNT_ID_LIVE"], template_id=ENV["TEMPLATE_ID_LIVE"], template_recipients=signer_placeholder)
    br = DocuSign_eSign::BulkRecipient.new(
        {
            "accessCode": '112233',
            "email": 'berry@gmail.com',
            "name": 'Berry',
            "rowNumber":1
        }
    )

    brr = DocuSign_eSign::BulkRecipientsRequest.new({"bulkRecipients": Array(br)})
    bea = DocuSign_eSign::BulkEnvelopesApi.new(@api_client)
    bea.update_recipients(account_id=ENV["ACCOUNT_ID_LIVE"], envelope_id=ENV["TEMPLATE_ID_LIVE"],
                      recipient_id="1",bulk_recipients_request=brr)

我可以使用这种类似的数据格式调用其他Docusign API。只能用于BulkEnvelopesAPI。

我在想这个BulkEnvelopesAPI函数的源代码是否有问题。

感谢您阅读!

1 个答案:

答案 0 :(得分:1)

在@kiddorails的帮助下,我设法解决了这个问题。

以下是解决方案:

首先,以此格式编辑源代码。主要思想是将Content-Type更改为&text; / csv',并将字符串输入正文。

def update_recipients_with_http_info(account_id, envelope_id, recipient_id, bulk_recipients_request)
      if @api_client.config.debugging
        @api_client.config.logger.debug "Calling API: BulkEnvelopesApi.update_recipients ..."
      end
      # verify the required parameter 'account_id' is set
      fail ArgumentError, "Missing the required parameter 'account_id' when calling BulkEnvelopesApi.update_recipients" if account_id.nil?
      # verify the required parameter 'envelope_id' is set
      fail ArgumentError, "Missing the required parameter 'envelope_id' when calling BulkEnvelopesApi.update_recipients" if envelope_id.nil?
      # verify the required parameter 'recipient_id' is set
      fail ArgumentError, "Missing the required parameter 'recipient_id' when calling BulkEnvelopesApi.update_recipients" if recipient_id.nil?
      # resource path
      local_var_path = "/v2/accounts/{accountId}/envelopes/{envelopeId}/recipients/{recipientId}/bulk_recipients".sub('{format}','json').sub('{' + 'accountId' + '}', account_id.to_s).sub('{' + 'envelopeId' + '}', envelope_id.to_s).sub('{' + 'recipientId' + '}', recipient_id.to_s)

      # query parameters
      query_params = {}

      # header parameters
      header_params = {}
      # HTTP header 'Accept' (if needed)
      header_params['Accept'] = @api_client.select_header_accept(['application/json'])
      header_params['Content-Type'] = 'text/csv'
      # form parameters
      form_params = {}

      # http body (model)
      # post_body = @api_client.object_to_http_body(bulk_recipients_request)
      # puts bulk_recipients_request
      # post_body = body_params
      auth_names = []
      data, status_code, headers = @api_client.call_api(:PUT, local_var_path,
        :header_params => header_params,
        :query_params => query_params,
        :form_params => form_params,
        :body => bulk_recipients_request,
        :auth_names => auth_names,
        :return_type => 'BulkRecipientsSummaryResponse')
      if @api_client.config.debugging
        @api_client.config.logger.debug "API called: BulkEnvelopesApi#update_recipients\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
      end
      return data, status_code, headers
    end
  end

其次,将bulk_recipients_request设置为字符串(每行数据都有换行符)

"rowNumber,email,name,Accesscode\n"+"1,berry@gmail.com,Berry,11223\n"