david.lagazo

Upload a new document through multipart/form-data using Postman

0 votes
Hello! I seem to be getting a 500 when I try to upload a new document. I am not exactly sure what is going wrong; I attached my settings below, and this is the generated HTTP snippet by Postman
POST /api/packages/cRtQjTTkipxb6m3LiHkaLEeEcDo=/documents HTTP/1.1
Host: sandbox.esignlive.com
Authorization: Basic MY_API_KEY
Accept: text/html
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW

----WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="files[]"; filename=""
Content-Type: 


----WebKitFormBoundary7MA4YWxkTrZu0gW

Attachments
Approved Answer

Reply to: Upload a new document through multipart/form-data using Postman

2 votes
Hey David, Can you try and remove the Content-Type header you've set manually? You are overriding the value set by Postman as you've already selected "form-data" in the "body" section. Also can you remove/hide your api key from the post as to make sure nobody else can use your account :) You can also download a tutorial on how to upload a document to an existing package through multipart/form-data using Postman: https://developer.esignlive.com/code-share/upload-document-multipartform-data-using-postman/
Haris Haidary OneSpan Technical Consultant

Reply to: Upload a new document through multipart/form-data using Postman

0 votes
WOW THANKS! After I removed my Content-Type in the header it went through.

Reply to: Upload a new document through multipart/form-data using Postman

0 votes
My pleasure :)
Haris Haidary OneSpan Technical Consultant

Reply to: Upload a new document through multipart/form-data using Postman

0 votes
Hey Haris, At this point, we've had 2 dev's get stuck on taking the postman instance, and turn it into a php script. We are having a lot of difficulty and not sure where to go. Could you help point us in the right direction? Server throwing a 500
 '@' . $file_name_with_full_path);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $target_url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    "Authorization: Basic MY_API_KEY",
    "Accept: text/html",
    "content-type: multipart/form-data;"
));
$result = curl_exec($ch);
curl_close($ch);

Reply to: Upload a new document through multipart/form-data using Postman

0 votes
Hey David, I'll look it over for you. I will get back to you when I have something for you :)
Haris Haidary OneSpan Technical Consultant

Reply to: Upload a new document through multipart/form-data using Postman

0 votes
Alright I got a working code for you on how to do a cURL POST with php:
 $documentJSON,
			"file"=>"@$documentPath"
		);

		$headerOptions = array(
		    'Authorization: Basic ' . $ESIGNLIVE_AUTH_KEY
		);
		if(!is_null($contentType))
		{
			$headerOptions[] = "Content-Type: $contentType";
		}
		$ch = curl_init();	
		curl_setopt($ch, CURLOPT_URL, $url);
		curl_setopt($ch, CURLOPT_POST, true);
		curl_setopt($ch, CURLOPT_FAILONERROR, true); 
		curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); 
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
		curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); 
		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
		
		if(!is_null($postfields))
		{
			curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
			if(!is_array($postfields))
			{
				$headerOptions[] = 'Content-Length: ' . strlen($postfields);
			}
		}
		
		curl_setopt($ch, CURLOPT_HTTPHEADER, $headerOptions);

		$response = curl_exec($ch);
		curl_close($ch);
		
		echo $response;
		
?>
And here is the JSON I used for the payload:
{
    "id": "document1",
    "name": "Sample NDA"  
}
Let me know if this works for you.
Haris Haidary OneSpan Technical Consultant

Reply to: Upload a new document through multipart/form-data using Postman

0 votes
Thanks for your reply! I tried it out, it uploads a PDF, but something strange happens. When I viewed the uploaded PDF, the content is just a string showing @+ $documentPath I've tried fiddling with it a little, can't figure it out Response = {"status":"","id":"app","signedHash":null,"extract":false,"approvals":[],"pages":[{"id":"","top":0.0,"height":1030.0,"left":0.0,"width":796.0,"index":0,"version":0}],"external":null,"data":null,"index":1,"fields":[],"description":"","name":"Sample NDA","size":31132}

Reply to: Upload a new document through multipart/form-data using Postman

3 votes
Oh my mistake. There was a typo in the code I posted. Change this line:
$documentPath = getcwd() . "\project-info\document.pdf";
to
$document = file_get_contents("project-info\document.pdf");

$postfields = array(
            "payload"=> $documentJSON,
			"file"=> $document
		);
Let me know if it works for you.
Haris Haidary OneSpan Technical Consultant

Reply to: Upload a new document through multipart/form-data using Postman

0 votes
Many thanks! I got it to work with the following code
 $documentJSON,
			"file"=> $document
		);

		$headerOptions = array(
		    'Authorization: Basic ' . $ESIGNLIVE_AUTH_KEY
		);
		if(!is_null($contentType))
		{
			$headerOptions[] = "Content-Type: $contentType";
		}
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL, $url);
		curl_setopt($ch, CURLOPT_POST, true);
		curl_setopt($ch, CURLOPT_FAILONERROR, true);
		curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

		if(!is_null($postfields))
		{
			curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
			if(!is_array($postfields))
			{
				$headerOptions[] = 'Content-Length: ' . strlen($postfields);
			}
		}

		curl_setopt($ch, CURLOPT_HTTPHEADER, $headerOptions);

		$response = curl_exec($ch);
		curl_close($ch);

		echo $response;
		
?>

Reply to: Upload a new document through multipart/form-data using Postman

0 votes
Glad to hear you got it working. I edited your post to hide your api key :)
Haris Haidary OneSpan Technical Consultant

Reply to: Upload a new document through multipart/form-data using Postman

0 votes
Hi There, I have he same issue, but when I tried the code above can't get it working(maybe it's on the API side). I received 504 gateway timeout. Here's the API documentation link Here's the code generated from postman: $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => "https://api.actionsteplabs.com/api/rest/files/?part_count=2&part_number=1", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "POST", CURLOPT_POSTFIELDS => "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"[object Object]\"\r\nContent-Type: false\r\n\r\n\r\n-----011000010111000001101001--", CURLOPT_HTTPHEADER => array( "accept: application/vnd.api+json", "authorization: Bearer (access_token), "content-length: 5242880", "content-type: multipart/form-data; boundary=---011000010111000001101001" ), )); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); if ($err) { echo "cURL Error #:" . $err; } else { echo $response; }

Reply to: Upload a new document through multipart/form-data using Postman

0 votes
Hi Arjun, For one thing, you can't simply copy-paste the code generated by postman, as it most often than not will have all the parameters needed to make the call. Code generated by postman is not reliable and will almost always require modifications on your part, but is a good starting point. Also, from the code that you shared, you are making a POST to "https://api.actionsteplabs.com/api/rest/files/?part_count=2&part_number=1”, which is not eSignLive. Have a look at these blogs on how to create and send a package through Postman and in PHP: https://www.esignlive.com/blog/esignlive-how-to-using-postman/ https://www.esignlive.com/blog/esignlive-how-to-creating-a-simple-php-web-application/
Haris Haidary OneSpan Technical Consultant

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