Create mysql database using cpanel api - php

I am trying to create mysql database using cpanel xmlapi.
After search on google i found the below code.
$auth_user = 'XXXXXX';
$auth_pass = 'XXXXX';
$server = 'XXXXXXXX.com';
$json_client = new \xmlapi($server);
$json_client->set_output('json');
$json_client->set_port(2083);
$json_client->password_auth($auth_user, $auth_pass);
$json_client->set_debug(1);
# Create Database
$result = $json_client->api1_query($auth_user, 'Mysql', 'adddb',array($shop->alias));
var_dump($result);
After running this code I got this error:
string(202) "{"cpanelresult":{"apiversion":"2","error":"The “cpanel_jsonapi_module†parameter is required.","data":{"reason":"The “cpanel_jsonapi_module†parameter is required.","result":"0"},"type":"text"}}"

Related

Making the DocuSign API transition from sandbox to live

I integrated the PHP API for DocuSign by creating a sandbox account, downloading the php sample and placing the correct credentials in, testing (which worked as expected) and then ran through the live process of 20 transactions, having an enterprise account, etc. All was approved and everything seemed in order according to the admin panel, but making the changes documented in the go live docs just results in a server 500 error. Anyone else experienced this? Maybe some part of the live transition escaped me?
The code below should return login info:
// DocuSign account credentials & Integrator Key
$username = "someemail#somewhere.com"; //or the account string
$password = "xxxxx";
$integrator_key = "abc-123";
$host = "https://demo.docusign.net/restapi";
// create a new DocuSign configuration and assign host and header(s)
$config = new DocuSign\eSign\Configuration();
$config->setHost($host);
$config->addDefaultHeader("X-DocuSign-Authentication", "{\"Username\":\"" . $username . "\",\"Password\":\"" . $password . "\",\"IntegratorKey\":\"" . $integrator_key . "\"}");
/////////////////////////////////////////////////////////////////////////
// STEP 1: Login() API
/////////////////////////////////////////////////////////////////////////
// instantiate a new docusign api client
$apiClient = new DocuSign\eSign\ApiClient($config);
// we will first make the Login() call which exists in the AuthenticationApi...
$authenticationApi = new DocuSign\eSign\Api\AuthenticationApi($apiClient);
// optional login parameters
$options = new \DocuSign\eSign\Api\AuthenticationApi\LoginOptions();
// call the login() API
$loginInformation = $authenticationApi->login($options);
// parse the login results
if(isset($loginInformation) && count($loginInformation) > 0)
{
// note: defaulting to first account found, user might be a
// member of multiple accounts
$loginAccount = $loginInformation->getLoginAccounts()[0];
if(isset($loginInformation))
{
$accountId = $loginAccount->getAccountId();
if(!empty($accountId))
{
echo "Account ID = $accountId\n";
// works as expected
}
}
}
Now, try the same thing using the live URL and credentials as suggested by the go live docs here:
$username = "live-user-account"; <--- live username or email
$password = "xxxxx"; <--- live pw
$integrator_key = "abc-123"; <--- same integrator key
$host = "https://www.docusign.net/restapi/v2/login_information"; <--- live URL
All I get is a server 500 error. I tried with just https://www.docusign.net/restapi and same thing. Server 500 error.
Is there some part of the go live process I overlooked?
Side note - this is attached to an enterprise level account
Ok so get ready for an idiotic ride....
Another stack overflow post answers this here, but I will skip to the actual answer found here
Basically - you have to redefine the $apiClient variable by calling back the api with returned info...
$username = "xxx-xx-xxxx"; <--- your username string or email
$password = "xxxxx"; <--- your password
$integrator_key = "aaa-bbb-ccc"; <--- your integrator key
$host = "https://www.docusign.net/restapi"; <--- LIVE url
// create a new DocuSign configuration and assign host and header(s)
$config = new DocuSign\eSign\Configuration();
$config->setHost($host);
$config->addDefaultHeader("X-DocuSign-Authentication", "{\"Username\":\"" . $username . "\",\"Password\":\"" . $password . "\",\"IntegratorKey\":\"" . $integrator_key . "\"}");
/////////////////////////////////////////////////////////////////////////
// STEP 1: Login() API
/////////////////////////////////////////////////////////////////////////
// instantiate a new docusign api client
$apiClient = new DocuSign\eSign\ApiClient($config);
// we will first make the Login() call which exists in the AuthenticationApi...
$authenticationApi = new DocuSign\eSign\Api\AuthenticationApi($apiClient);
// optional login parameters
$options = new \DocuSign\eSign\Api\AuthenticationApi\LoginOptions();
// call the login() API
$loginInformation = $authenticationApi->login($options);
// parse the login results
if(isset($loginInformation) && count($loginInformation) > 0)
{
// note: defaulting to first account found, user might be a
// member of multiple accounts
$loginAccount = $loginInformation->getLoginAccounts()[0];
if(isset($loginInformation))
{
$accountId = $loginAccount->getAccountId();
// HERE is where we all go wrong
$host = $loginAccount->getBaseUrl();
$host = explode("/v2",$host);
$host = $host[0];
// UPDATE configuration object and then re-call the api client
$config->setHost($host);
$apiClient = new DocuSign\eSign\ApiClient($config);
if(!empty($accountId))
{
//echo "Account ID = $accountId\n";
}
}
}
Then poof, your envelope calls will magically work after that...
This is one FUGLY implementation of a sandbox -> live process. We got some great PHP sample for sandbox but then no connected real world examples of how you have to change things around in the live environment. Yes, we get that live can differ, but just leave this one small piece commented in the php sample and say "when going live, uncomment this" ... Literally nothing else in the code is different other than the login creds.
simple as that.
It kind of makes the sandbox pointless since I now have to re-test everything to make sure this live code is stable.
Thank you support for trying.

cannot access nusoap webservice on my hosted website to localhost, but work on localhost to localhost

I didn't know what is wrong with my server. It looks like can't access local nusoap webservice ..
but working fine when my web still on localhost.
When I hosted it, it can't access ws nusoap .
I even disable firewall on my PC, but still it didn't work
.
here my code
public function index() {
$this->load->helper('url');
$this->load->library("Nusoap_lib");
$url = 'http://localhost:8082/ws/live.php?wsdl';
$client = new nusoap_client($url, true);
echo $url;
$proxy = $client->getproxy();
$username = 'username';
$password = 'password';
$result=$proxy->GetToken($username, $password);
$token = $result;
$var = 2011;
$tahun = (int)$var;
$table = 'nilai';
$filter = "id_smt = 20141";
//$filter = "";
$order = "";
$jumlah = $proxy->GetCountRecordset($token, $table, $filter);
I got error like this
An uncaught Exception was encountered
Type: Error
Message: Call to a member function GetToken() on null
Filename: /var/www/validator-feeder/application/controllers/Wsa.php
Line Number: 19
The point is my hosted website cannot access localhost
$url = 'http://localhost:8082/ws/live.php?wsdl';
but my local website can access localhost.
any idea what cause this ??

Dropbox PHP SDK not working on production server

I am playing around with Dropbox PHP SDK and I have a wired problem. On my localhost environment it works like a charm, but on my server it does not. I have ssl and the dropbox redirect urls is: https://flaviuscojocariu.com/arhitecta/dropbox_finished.php
I don't understand where the problem can be, as I searched my entire code for http://localhost/ links and replaced everything. I get only the 500 error and I don't understand why.
Can someone advice?
If needed I can provide more code. This is the code which I use for auth.
<?php
session_start();
$_SESSION['user_id'] = 1;
require __DIR__.'/../vendor/autoload.php';
$dropboxKey = '***';
$dropboxSecret = '***';
$appName = '***';
$appInfo = new Dropbox\AppInfo($dropboxKey,$dropboxSecret);
// Store CSRF token
$csrfToken = new Dropbox\ArrayEntryStore($_SESSION, 'dropbox-auth-csrf-token');
// Define auth details
$webAuth = new Dropbox\WebAuth($appInfo, $appName, 'http://localhost/arhitecta/dropbox_finished.php', $csrfToken);
$db = new PDO('mysql:host=127.0.0.1;dbname=arhitecta;', 'root','');
//User datails
$user = $db->prepare("
SELECT * FROM users WHERE id = :user_id
");
$user->execute(['user_id' => $_SESSION['user_id']]);
$user = $user->fetchObject();

PHP, PDO => MSSQL with 2 instances

i wrote a simple script to query some data from a MSSQL-Express 2012 Server.
All workes fine with the first instance:
$host = "192.168.13.3\test1";
$user = "sa";
$passwd = "test1";
self::$instance = new PDO ("dblib:host=$host","$user","$passwd");
but if I try to connect to my second Instance like:
$host = "192.168.13.3\test2";
$user = "sa";
$passwd = "test2";
self::$instance = new PDO ("dblib:host=$host","$user","$passwd");
I get this error:
[message:protected] => SQLSTATE[HY000] Unable to connect: Adaptive Server is unavailable or does not exist (severity 9)
[string:Exception:private] =>
[code:protected] => 20009
With MSSQL-Server-Management-Tool I can access both instances without problems.
Has somebody a hint where i can find my failure?
Thanks in advance

How to re-initialize the Docusign PHP API with different credentials

We have a case where we need to check envelope status in two separate Docusign accounts. If we don't get status in the first, we want to check the second.
I'm having trouble getting the API to re-initialize with the credentials of our second account. I'm calling this snippet with the new variables:
require_once('docusign/SignatureApi.php');
$IntegratorsKey = "abcd";
$UserID = "dave#account.com";
$Password = "xxxxx";
$_apiEndpoint = $Endpoint;
$_apiWsdl = "docusign/api/APIService.wsdl";
$api_options = array('location'=>$_apiEndpoint,'trace'=>true,'features' => SOAP_SINGLE_ELEMENT_ARRAYS);
$api = new APIService($_apiWsdl, $api_options);
$api->setCredentials("[" . $IntegratorsKey . "]" . $UserID, $Password);
$res = RequestEnvelopStatuses($envelopes);
$envelopeStatuses = $res->RequestStatusesResult;
if(!count($envelopeStatuses->EnvelopeStatuses->EnvelopeStatus)){
// If we did not find envelopes, check other account
$IntegratorsKey = "wxyz";
$UserID = "fred#altaccount.com";
$Password = "xxxxx";
$api->setCredentials("[" . $IntegratorsKey . "]" . $UserID, $Password);
// retry request
$res = RequestEnvelopStatuses($envelopes);
$envelopeStatuses = $res->RequestStatusesResult;
}
It doesn't return an error, but won't return envelope status either. It seems to still use the first credentials (guessing). The second attempt always seems to return whatever the first attempt did.
Is there a better / preferred way to do this?
That does not look like the proper way to get the envelope status. Maybe that's why you are not finding them and trying to look again?
// Create a filter using account ID and today as a start time
$envStatusFilter = new EnvelopeStatusFilter();
$envStatusFilter->AccountId = $AccountID;
$beginDateTime = new EnvelopeStatusFilterBeginDateTime();
$beginDateTime->_ = todayXsdDate(); // note that this helper function
// is in CodeSnippets/include/utils.php
// in the PHP SDK
$envStatusFilter->BeginDateTime = $beginDateTime;
// Send
$requestStatusesparams = new RequestStatuses();
$requestStatusesparams->EnvelopeStatusFilter = $envStatusFilter;
$response = $api->RequestStatuses($requestStatusesparams);

Categories