Docusign API PHP TemplatesApi::updateDocument FORMAT_CONVERSION_ERROR - php

I'm trying to update a template document via PHP API using this: https://github.com/docusign/docusign-php-client/blob/master/src/Api/TemplatesApi.php#L4946
I get one of two errors depending on if I set the apply_document_fields option.
Without it set, I get UNSPECIFIED ERROR Value cannot be null.\r\nParameter name: fileBytes. However, if I view the request body before sending, document_base_64 is set as expected.
With apply_document_fields set 'true' (actual boolean value is not supported), I get FORMAT_CONVERSION_ERROR The data could not be converted.
Either way, it seems like the document data is not getting sent correctly, but I can't figure out how I'm supposed to be sending it. Here's my code:
public static function updateTemplateWithDocument(string $documentId, string $templateId, $documentBody = null)
{
$api = My_Service_Docusign::getInstance();
$templatesApi = new DocuSign\eSign\Api\TemplatesApi($api->getAuth());
$document = new \DocuSign\eSign\Model\Document();
$document->setDocumentBase64(base64_encode($documentBody));
// Got an error reusing $documentId, so I'm incrementing it now
$document->setDocumentId((string) (((int)$documentId) + 1));
$def = new DocuSign\eSign\Model\EnvelopeDefinition();
$def->setDocuments(array($document));
$opts = new \DocuSign\eSign\Api\TemplatesApi\UpdateDocumentOptions();
// Different behavior with this set vs not
$opts->setApplyDocumentFields('true');
$res = $tmpApi->updateDocument($api->getAccountId(), $documentId, $templateId, $def, $opts);
return $res;
}
Unfortunately, DocuSign support doesn't support their API :-(

I figured out I need to use TemplatesApi::updateDocuments (plural) instead, which also allows me to reuse the documentId.

Related

is there an API for PHP_CodeSniffer?

Does PHP_CodeSniffer have an API I can use, rather than run the command line?
So given a string of PHP code, $code, and Composer ensuring loading of the PHP_CodeSniffer code, is there something I can do such as:
// Pseudocode!
$code_sniffer = new PHPCodeSniffer;
$result = $code_sniffer->sniff($code);
rather than go via the command line with something like:
$result = exec(sprintf('echo %s | vendor/bin/phpcs', escapeshellarg($code)));
There is, but you need to write more code than that.
Take a look at the example here: https://gist.github.com/gsherwood/aafd2c16631a8a872f0c4a23916962ac
That example allows you to sniff a piece of code that isn't written to a file yet, and set up things like the standard to use (could also be a ruleset.xml file).
Another example, that uses the JS tokenizer instead of PHP + pulls content from an existing file, is available here: https://gist.github.com/gsherwood/f17cfc90f14a9b29eeb6b2e99e6e7f66
It is shorter because it doesn't use as many options.
Here's what I got working for PHPCS 2:
PHP_CodeSniffer::setConfigData(
'installed_paths',
// The path to the standard I am using.
__DIR__ . '/../../vendor/drupal/coder/coder_sniffer',
TRUE
);
$phpcs = new PHP_CodeSniffer(
// Verbosity.
0,
// Tab width
0,
// Encoding.
'iso-8859-1',
// Interactive.
FALSE
);
$phpcs->initStandard('Drupal');
// Mock a PHP_CodeSniffer_CLI object, as the PHP_CodeSniffer object expects
// to have this and be able to retrieve settings from it.
// (I am using PHPCS within tests, so I have Prophecy available to do this. In another context, just creating a subclass of PHP_CodeSniffer_CLI set to return the right things would work too.)
$prophet = new \Prophecy\Prophet;
$prophecy = $prophet->prophesize();
$prophecy->willExtend(\PHP_CodeSniffer_CLI::class);
// No way to set these on the phpcs object.
$prophecy->getCommandLineValues()->willReturn([
'reports' => [
"full" => NULL,
],
"showSources" => false,
"reportWidth" => null,
"reportFile" => null
]);
$phpcs_cli = $prophecy->reveal();
// Have to set these properties, as they are read directly, e.g. by
// PHP_CodeSniffer_File::_addError()
$phpcs_cli->errorSeverity = 5;
$phpcs_cli->warningSeverity = 5;
// Set the CLI object on the PHP_CodeSniffer object.
$phpcs->setCli($phpcs_cli);
// Process the file with PHPCS.
$phpcsFile = $phpcs->processFile(NULL, $code);
$errors = $phpcsFile->getErrorCount();
$warnings = $phpcsFile->getWarningCount();
$total_error_count = ($phpcsFile->getErrorCount() + $phpcsFile->getWarningCount());
// Get the reporting to process the errors.
$this->reporting = new \PHP_CodeSniffer_Reporting();
$reportClass = $this->reporting->factory('full');
// This gets you an array of all the messages which you can easily work over.
$reportData = $this->reporting->prepareFileReport($phpcsFile);
// This formats the report, but prints it directly.
$reportClass->generateFileReport($reportData, $phpcsFile);

PHP 5X.X is sending zero as value to any SOAP service

I have a webservice with one one method that reurns an objetc, the method is very simple getObject(int id);
I made a PHP client to test it:
<?php
ini_set("soap.wsdl_cache_enabled", "1"); // Set to zero to avoid caching WSDL
$soapClient = new SoapClient('http://localhost:8080/ws-tickets/tickets2?wsdl');
$id = 2;
$result = $soapClient->get Ticket($id);
print_r($result);
?>
Well, I debug the WS when it is called by this php client and I see that the parameter received by it is ZERO.
If in my database I create a record that has "0" as id, the phpclient will retrieve it perfectly and every data is printed as it supouse to be for the print_r($result); command.
But, no mather wich parameter I send, it allways came to ZERO to the ws and I do not know what I am doing wrong
My Java WS is
#WebService
public class tickets2 {
#EJB
reciboDAO reciboDAO;
public ticket getTicket(int id){
recibo a = this.reciboDAO.getReciboporid(id);
return a;
}
}

building a php object equal to xml tag

i am developing an app in php it pulls data from Reuters API i am trying to add the request parameters before making SOAP call , i have the xml which must be generated from my request it must look like this :
<HeadlineMLRequest>
<Filter>
<MetaDataConstraint class="companies" xmlns="http://schemas.reuters.com/ns/2006/04/14/rmds/webservices/news/filter">
<Value>MSFT.O</Value>
</MetaDataConstraint>
</Filter>
</HeadlineMLRequest>
when i build my request parameter object i tried this
protected function getRequest() {
$retval->HeadlineMLRequest->MaxCount = 10;
$retval->HeadlineMLRequest->Filter->MetaDataConstraint->class = "companies";
$retval->HeadlineMLRequest->Filter->MetaDataConstraint->Value = "MSFT.O";
return $retval;
}
but when i echo last xml request i find it like this
<ns1:headlinemlrequest>
<ns1:maxcount>
10
</ns1:maxcount>
<ns1:filter>
<ns2:metadataconstraint class="companies">
<ns2:value>
</ns2:value>
</ns2:metadataconstraint>
</ns1:filter>
if you notice Value is empty although i set it with "MSFT.O" , any help please?
Complex requests with php soap are not well documented and most examples show only basic techniques.
Try the following:
$metaData = '<MetaDataConstraint class="companies" xmlns="http://schemas.reuters.com/ns/2006/04/14/rmds/webservices/news/filter">
<Value>MSFT.O</Value>
</MetaDataConstraint>';
$xmlvar = new SoapVar($metaData, XSD_ANYXML);
$retval->HeadlineMLRequest->Filter->MetaDataConstraint = $xmlVar;

net.sf.jasperreports.engine.design.JRValidationException - Query parameter not found

I use JasperServer and PHP JavaBridge to generate PDF reports via JasperServer inside PHP. I get compile error because of missing (unassigned) parameter passed to JRXML compiler
Fatal error: Uncaught [[o:Exception]:
"java.lang.Exception: Invoke failed:
[[c:JasperCompileManager]]->compileReport((o:String)[o:String]).
Cause: net.sf.jasperreports.engine.design.JRValidationException:
**Report design not valid** : 1. **Query parameter not found** : db_field_id VM:
1.6.0_18#http://java.sun.com/" at: #-12
net.sf.jasperreports.engine.design.JRAbstractCompiler.verifyDesign(JRAbstractCompiler.java:258)
I cant find a way to pass my
$params = new Java("java.util.HashMap");
foreach ($jrxml_params as $key => $jr_param) $params->put($key, $jr_param);
list of params to the compile method nor I can disable this verification by
$japser_props = new JavaClass("net.sf.jasperreports.engine.util.JRProperties");
$japser_props->COMPILER_XML_VALIDATION = false;
Here is what I use to generate PDF (works fine if JRXML file doesn't contain $P{} pamareters and halts otherwise)
$class = new JavaClass("java.lang.Class");
$class->forName("com.mysql.jdbc.Driver");
$driverManager = new JavaClass("java.sql.DriverManager");
$conn = $driverManager->getConnection("jdbc:mysql://localhost:3306/XXX?user=XXX&password=1234");
$compileManager = new JavaClass("net.sf.jasperreports.engine.JasperCompileManager");
$report = $compileManager->compileReport(realpath("/www/some.jrxml"));
$params = new Java("java.util.HashMap");
foreach ($jrxml_params as $key => $jr_param) $params->put($key, $jr_param);
$jasperPrint = $fillManager->fillReport($report, $params, $conn);
$exportManager = new JavaClass("net.sf.jasperreports.engine.JasperExportManager");
$outputPath = realpath(".")."/"."output.pdf";
$exportManager->exportReportToPdfFile($jasperPrint, $outputPath);
How do I avoid this error, I know what I need to pass and I don't know a way to do it, can't I just pass params to fillManager?
$japser_props = new JavaClass("net.sf.jasperreports.engine.util.JRProperties");
$japser_props->setProperty('net.sf.jasperreports.compiler.xml.validation',true);
this is the way to set property from PHP but that's not the problem. It turns out everything was fine, I've missed parameter declaration before my MySQL query... Put
<parameter name="db_field_id" class="java.lang.Integer">
in your JRXML before you use it as $P{db_field_id} now it compliles fine and later
$jasperPrint = $fillManager->fillReport($report, $params, $conn);
parameters are assigned at fill time

How do I POST XML data to a URL via JavaScript in an Adobe AIR app?

I'm writing an application that downloads an XML string from a URL and POSTs that to another URL (that's set up to handle an incoming "XML" field). I've got the first part right - it downloads the XML and I can alert() it and all that, but I'm unable to figure out how to POST that data to a server.
function pull() {
var myLoader = new air.URLLoader();
var myRequest = new air.URLRequest('http://something/something.xml');
myLoader.addEventListener(air.Event.COMPLETE, pulled);
myLoader.load(myRequest);
}
function pulled(evt) {
if (evt.target.bytesTotal>0) {
// alerting shows the full string just fine
alert(evt.target.data);
var myLoader = new air.URLLoader();
var myRequest = new air.URLRequest('http://someplace/push.php');
myRequest.method = air.URLRequestMethod.POST;
// myVars = new air.URLVariables("xml="+evt.target.data); //
// alert(evt.target.data.toUpperCase());
myRequest.data = "xml="+evt.target.data; // myVars;
myLoader.dataFormat = air.URLLoaderDataFormat.TEXT;
myLoader.addEventListener(air.Event.COMPLETE, pushed);
myLoader.load(myRequest);
}
}
I made the 2nd server PHP echo the contents of the xml variable, but I'm just unable to get the exact contents of the XML string. There is something I'm doing wring with the myRequest.data and/or dataFormat bit.
Can someone just figure this out? I know it's probably a simple thing, but I'm at my wit's end right now.
This is my first AIR app.
Another related question (or sub-question) is that...
alert(evt.target.data); // shows an alert box with the XML
alert(typeof evt.target.data); // shows String
alert(evt.target.data.toUpperCase()); // shows the xml converted to upper case
alert(encodeURI(evt.target.data)); // shows up blank.
alert(escape(evt.target.data)); // shows up blank.
Why??
The error seems to be the way you are assigning the parameters to 'data' ... Use URLVariables.
var params:URLVariables = new URLVariables();
params.[name of parameter] = [value];
--- so like params.xml = (YOUR XML) ... from your example:
// uses the dynamic object to add the 'xml' property to 'params' at runtime.
params.xml = evt.target.data
Then Change you request.data to request.data = params;
-- The URLVariables guy is dynamic - so you can add properties as I describe above.
For a basic example - much more complete that what I have here: http://livedocs.adobe.com/flex/3/html/help.html?content=data_access_2.html

Categories