Adobe Sign API - /transientDocyments - php

This is the example adobe have in their documentation.
I have tried with Guzzle:
$client->request('POST', 'transientDocuments', [
'multipart' => [
[
'name' => 'test',
'contents' => fopen('pdfs/test.pdf', 'r'),
'filename' => 'file.pdf',
'headers' => [
'Content-Type' => 'multipart/form-data',
'Content-Transfer-Encoding' => "binary",
]
],
]
]);
fopen returns resource(13) of type (stream)
But every time I get {"code":"NO_FILE_CONTENT","message":"Must provide file body"}.

You should write code to satisfy the following request shown in image below.
Explanation
When u log in with your e-sign account you will be redirected to one of the hosts (like api.in1.echosign.com). You need to put File as form-data parameter key and your file as value. You get Mime-Type based on file extension. In response you will get TransientDocumentId which can be used for the creating and sending agreements etc.

Was stuck with the same but realised that the parameters name and filename to be enclosed in double quotes.
'name' => '"File"',
'filename' => '"file.pdf"',
PS. my code is in .Net, not php

Related

How to disable urlencode query parameter guzzle

maybe someone has experienced the same problem, I want to make a GET request by sending data in the url parameter,
the endpoint need request like this:
https://test.com/sales/transaction/?page=1&pageSize=1&transactionDateFrom=2023-01-24T00:00:00.000Z&transactionDateTo=2023-01-24T15:59:59.000Z
but if i send from guzzle using dynamics data, the request is like this:
https://test.com/sales/transaction/?page=1&pageSize=5&transactionDateFrom=2023-01-2500%3A00%3A00.000Z&transactionDateTo=2023-01-2523%3A59%3A59.000Z
my code to send request:
$req = $client->request('GET','https://test.com/sales/transaction/', [
'query' => [
'page' => 1,
'pageSize' => 5,
'transactionDateFrom' => 2023-01-24T00:00:00.000Z,
'transactionDateTo' => 2023-01-24T15:59:59.000Z
],
'headers' => $headers
]);
how to resolve the timezone format to normal string like this
transactionDateFrom=2023-01-24T00:00:00.000Z&transactionDateTo=2023-01-24T15:59:59.000Z
maybe someone has solved this problem before and can provide some information, thanks

Post data and file together to Laravel API using Guzzle

I've two working project communicating between each other via an API built in a Laravel. So far there is only simple POST requests made with GuzzleHttp 6.
And I am currently trying to have a new POST request made from 1 to 2, which would send a couple of simple fields along with one file.
Project 1 has a form, on the form submit I handle the data and want to send them to project 2 via a POST request to this new API endpoint.
I've tried different guzzle options 'multipart', 'form_data' etc and realised they may not be combined together. Now I understood that this options are exclusive and using only "multipart" seems the way to go.
But when I send my request to Laravel no data nor file are there.
Here is the code for my request
$options = ‌[
'multipart' =>
[
[
'name' => 'data',
'contents' => '{"field_1":"Test","field_2":"Test","field_3":"Test"}',
'headers' =>
[
'Content-Type' => 'application/json',
],
],
[
'name' => 'file',
'filename' => 'test.pdf',
'Mime-Type' => 'application/pdf',
'contents' => file_get_contents($_FILEs['text_file']['temp_name']),
]
]
];
$this->client->request('POST', "api/test_post", $options)
I also gve this a try:
$options = ‌[
'multipart' =>
[
[
'name' => 'field_1',
'contents' => 'Test',
],
[
'name' => 'field_2',
'contents' => 'Test',
],
[
'name' => 'file',
'filename' => 'test.pdf',
'Mime-Type' => 'application/pdf',
'contents' => fopen($_FILEs['text_file']['temp_name'],'r'),
]
]
];
$this->client->request('POST', "api/test_post", $options)
If I look the request content on the receiving end, nothing is there. No field or file.
I've seen couples posts, some say to include headers some say not too. I kinda got lost and amd now running out of ideas.
I would expecet the infos to be as if they where form post I guess:
$request->inpust('field_1') -> 'test'
$request->inpust('field_2') -> 'test'
$request->inpust('field_3') -> 'test'
$request->file('file') -> my uploaded file
Also I should point out that I am not exactly sure how multipart/form-data works, so that might not help me.
If you can point me to the right direction, that would help a lot
Well I finally figured it out. The second example from above is the way to go also be sure to check the headers of the request and the client...
As this API has been running for quite some time and was only doing json type requests, the Client was instantiated with
$options = [
headers => [ 'Content-Type' => 'application/json']
]
Which, as stated in multiple answers across the internet, prevents Guzzle to automatically set the Content-Type depending of the request options.
In my case, removing this line made Guzzle enable to set it properly when provided with 'multipart' option.
Also, as all other requests are using the 'json' options, Guzzle also works it's magic and set 'Content-Type' => 'application/json' as well.

Creating campaign for dynamic TextMerge segment fails

I'm trying to send a campaign to a dynamic list segment based on a custom numeric merge field (GMT_OFFSET, in this case) but the code below yields the following error from the MailChimp API:
"errors" => [
0 => [
"field" => "recipients.segment_opts.conditions.item:0"
"message" => "Data did not match any of the schemas described in anyOf."
]
]
My code, using drewm/mailchimp-api 2.4:
$campaign = $mc->post('campaigns', [
'recipients' => [
'list_id' => config('services.mailchimp.list_id'),
'segment_opts' => [
'conditions' => [
[
'condition_type' => 'TextMerge',
'field' => 'GMT_OFFSET',
'op' => 'is',
'value' => 2,
],
],
'match' => 'all',
],
],
],
// Cut for brevity
];
If I am to take the field description literally (see below), the TextMerge condition type only works on merge0 or EMAIL fields, which is ridiculous considering the Segment Type title says it is a "Text or Number Merge Field Segment". However, other people have reported the condition does work when applied exclusively to the EMAIL field. (API Reference)
I found this issue posted but unresolved on both DrewM's git repo (here) and SO (here) from January 2017. Hoping somebody has figured this out by now, or found a way around it.
Solved it! I passed an integer value which seemed to make sense given that my GMT_OFFSET merge field was of a Number type. MailChimp support said this probably caused the error and suggested I send a string instead. Works like a charm now.

Can't update Google Drive file

I'm trying to upload a file to Google Drive using the the v3 Google Drive SDK:
$this->drive()
->files
->update(
$this->report->getId(),
$this->report, // This is a Google_Service_Drive_DriveFile instance
[
'uploadType' => 'multipart',
'data' => file_get_contents($this->getLocalReportLocation())
]
);
And I receive the following exception:
Error calling PATCH https://www.googleapis.com/upload/drive/v3/files/ABCDe4FGHvXZTKVOSkVETjktNE0?uploadType=multipart: (403) The resource body includes fields which are not directly writable.
Apparently the issue is caused by $this->report which I obtain in the following way:
// Fetch the latest synchronized report
$latestReport = $this->drive()
->files
->listFiles([
'orderBy' => 'modifiedTime',
'q' => '\''.$this->userEmail.'\' in owners AND name contains \'AppName\'',
])
->getFiles()[0];
$this->report = $this->drive()
->files
->get($latestReport->id);
Probably $this->report, which is an instance of \Google_Service_Drive_DriveFile, contains some fields that are causing issues when set and passed to the update() method.
I was able to solve the problem by passing a new instance of \Google_Service_Drive_DriveFile to the update() method like this:
$this->drive()
->files
->update($this->report->getId(), (new \Google_Service_Drive_DriveFile()), [
'uploadType' => 'multipart',
'data' => file_get_contents($this->getLocalReportLocation()),
'mimeType' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
]);

Mandrill email attachments file path

I am trying to add some attachments to an email that is being sent using the mandrill api via a php wrapper. I have tried a number of different things to try to successfully attach the file but to no avail.
I am using cakephp 2.x but I don't think that has any particular significance in this instance (maybe it does?!).
I am using the php wrapper maintained by mandrill at https://bitbucket.org/mailchimp/mandrill-api-php
Here is the code:
$mandrill = new Mandrill(Configure::read('Site.mandrill_key'));
$params = array(
'html' => '
<p>Hi '.$user['User']['name'].',</p>
<p>tIt is that time of the year again.<br />
Please login to the website members area and upload your renewal requirements.</p>
<p>Kind regards.</p>',
"text" => null,
"from_email" => Configure::read('Site.email'),
"from_name" => Configure::read('Site.title'),
"subject" => "Renewal Pending",
"to" => array(array('email' => $user['User']['email'])),
"track_opens" => true,
"track_clicks" => true,
"auto_text" => true,
"attachments" => array(
array(
'path' => WWW_ROOT.'files/downloads/renewals',
'type' => "application/pdf",
'name' => 'document.pdf',
)
)
);
$mandrill->messages->send($params, true);
}
This shows that an attachment has been added to the email and is a pdf but the actual pdf has not been attached.
I also tried by adding the path directly onto the file as in:
"attachments" => array(
array(
'type' => "application/pdf",
'name' => WWW_ROOT.'files/downloads/renewals/document.pdf',
)
I have googled and read every article I can find but cannot find any specific reference as to how I should specify the path for mandrill to correctly attach my attachment.
Any help will be greatly appreciated.
OK. So thanks to Kaitlin for her input.
The PHP way to deal with this is to get the file and then base64_encode it:
$attachment = file_get_contents(WWW_ROOT.'files/downloads/file.pdf');
$attachment_encoded = base64_encode($attachment);
and then in the attachments part of the mandrill array you pass the :
"attachments" => array(
array(
'content' => $attachment_encoded,
'type' => "application/pdf",
'name' => 'file.pdf',
)
So easy! Thanks again Kaitlin!
It looks like you're passing a parameter called path, but the Mandrill API doesn't take the path of a file for attachments. If you're using the send or send-template call, attachments should be an associative array (hash) with three keys: type, name, and content.
The content parameter should be the contents of the file as a Base64 encoded string, so instead of path, you'll want to get the file contents, Base64 encode them, and then pass them in a parameter called content instead of path.
You can see the full details of the parameters, including for attachments, in the Mandrill API docs here: https://mandrillapp.com/api/docs/messages.html#method=send

Categories