gtawaf

Adding document to package gives error

0 votes
Hello, I'm trying to integreate my Ruby on Rails application with OneSpan. I was able to create a package but when I try to add a document to that package I get Unexpected Content-Disposition value for parameter 'name'". I used PostMan and here is the code for Request:
 POST /api/packages/fcsS1bBSu37ETcAXYmVLvM1S4bg=/documents HTTP/1.1
Host: sandbox.esignlive.com
Authorization: Basic xxxxxxxxxxxxxx
Cache-Control: no-cache
Postman-Token: 752f5f9d-64a1-188c-0ad2-f29d01843563
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW

------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="file"; filename="N11.pdf"
Content-Type: application/pdf


------WebKitFormBoundary7MA4YWxkTrZu0gW-- 

Response:
 {
    "messageKey": "error.validation.invalidParameters",
    "technical": "Unexpected Content-Disposition value for parameter 'name'",
    "message": "Invalid parameters.",
    "code": 400,
    "name": "Validation Error"
}
What am I missing? My code
def self.add_file_to_package(package_id, file, file_name)
    begin
      url = "#{ENV["ONE_SPAN_URL"]}/packages/#{package_id}/documents"
      response = RestClient.post(url,  {:file => File.new(file, 'rb')}, {Authorization: "Basic #{ENV["ONE_SPAN_KEY"]}"})
      return response.body

    rescue RestClient::Exception => err
      Rails.logger.info err.response
      raise
    end
  end

Approved Answer

Reply to: Adding document to package gives error

1 votes
Hi there, From your code and your http request, it seems you are not adding payload for this document. The minimum payload for the document should include the "name" attribute as shown in the attachment. But it's always recommended to add all approvals and attributes in your request JSON in one call like below vs update your documents after uploading:
   {
      "name":"sampleAgreement",
      "index":0,
      "approvals":[
         {
            "fields":[
               {
                  "type":"SIGNATURE",
                  "subtype":"FULLNAME",
                  "width":200.0,
                  "height":50.0,
                  "left":550.0,
                  "page":0,
                  "top":165.0,
                  "extract":false
               }
            ],
            "role":"your role id"
         }
      ]
   }
And if you are uploading multiple documents, your payload JSON should organize like below:
[
   {
    "name":"document1",
     ....
   },
  {
     "name":"document2",
     ....
  }
]
Hope this could help you! Duo

Duo Liang OneSpan Evangelism and Partner Integrations Developer


Attachments
8-10-1.png39.52 KB

Reply to: Adding document to package gives error

0 votes
Thanks that worked. and For anyone using Ruby on Rails with RestClient, here is the code to make it work: Notice to_json and payload
def self.add_file_to_package(package_id, file, file_name)
    begin
      url = "#{ENV["ONE_SPAN_URL"]}/packages/#{package_id}/documents"
      response = RestClient.post(url,  {:file => File.new(file, 'rb'), 'payload':{"name":"test"}.to_json}, {Authorization: "Basic #{ENV["ONE_SPAN_KEY"]}"})
      return response.body

    rescue RestClient::Exception => err
      Rails.logger.info err.response
      raise
    end
  end

Reply to: Adding document to package gives error

0 votes
Hi Gamal, Thanks for sharing your code and your contribution for our community! Please feel free to ask questions when you encountered some problems. :) Duo

Duo Liang OneSpan Evangelism and Partner Integrations Developer


Hello! Looks like you're enjoying the discussion, but haven't signed up for an account.

When you create an account, we remember exactly what you've read, so you always come right back where you left off