We are using the MTN PHP-SDK from the below URL
https://github.com/digitalmaterial/dep.api.auth.php
Code:
$path = '/subscription/' . $subscription_id;
$depClient = new MTNDEP\DEPClient($accessKey, $accessSecret, $apiKey, $baseUrl);
$requestBody = [];
$response = $depClient->createRequest(MTNDEP\DEPClient::DELETE, $path, null, $requestBody)->send();
$responseArray = json_decode((string) $response->getBody(), true);
Response:
Client error: `DELETE https://api.dep.mtn.co.za/subscription/` resulted in a `404 Not Found` response:
{"message":"No method found matching route subscription/ for http method DELETE."}
We are unable to find any MTN-DEP Cancel subscription PHP code. Please help us and let us know how can we delete the subscription from MTN end?
i have noticed 2 things :
1- in the mentioned documentation, the request sent like this
$depClient->createRequest('POST' '/subscription');
so i think you need to use this , please try to adhere with all steps
$depClient->createRequest('DELETE',$path); // Returns DEPClient object for chaining, see below
$depClient->getRequest(); // Will return the GuzzleHttp\Psr7\Request object with signed auth details for DEP API requests
$response = $depClient->send();
$statusCode = $response->getStatusCode(); // returns the http status code
$rawResponse = (string) $response->getBody(); // body, you will need to cast to string or echo to get the body data.
$responseArray = json_decode($rawResponse, true); // return json decode array.
2- make sure the $subscription_id is set and have a value before you send the request.
Stating to the documentation, you need to specify the customer ID and the subscription ID.
You have to make a DELETE request to the endpoint /customers/{id}/subscriptions/{subscriptionId}.
Maybe the path specified in your code should look like this:
$path = '/customers/' . $customer_id . '/subscriptions/' . $subscription_id;
$depClient = new MTNDEP\DEPClient($accessKey, $accessSecret, $apiKey, $baseUrl);
$requestBody = [];
$response = $depClient->createRequest(MTNDEP\DEPClient::DELETE, $path, null, $requestBody)->send();
$responseArray = json_decode((string) $response->getBody(), true);
Related
I am calling an API of a shipping company to get the POD (Proof of delivery) image of a delivery as per this document.
I am expecting to see an image but the the API response is null.
Here is my code:
$host = "api.shiplogic.com";
$accessKey = 'AKIA55D5DNTBI4X24BCM'; //Sandbox credentials
$secretKey = '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'; //Sandbox credentials
$requestUrl = 'https://api.shiplogic.com';
$uri = '/shipments/pod/images?';
$httpRequestMethod = 'GET';
$data = 'tracking_reference=';
$refnr = 'FQJNF'; //created for testing
require 'AWS/aws-autoloader.php';;
use Aws\Signature\SignatureV4;
use Aws\Credentials\Credentials;
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Request;
use Psr\Http\Client\ClientInterface;
$signature = new SignatureV4('execute-api', 'af-south-1');
$credentials = new Credentials($accessKey, $secretKey);
$psr7Request = new Request($httpRequestMethod, $requestUrl.$uri.$data.$refnr);
$client = new Client([$requestUrl, 'timeout' => 30]);
$sr = $signature->signRequest($psr7Request, $credentials);
$response = $client->send($sr);
$json = $response->getBody()->getContents();
echo $json;
I have tried to var_dump() and print_r()
What am I missing or doing wrong?
[{"id":203913730,"parcel_id":0,"date":"2022-08-05T09:44:19.704Z","status":"delivered","source":"danieladmin","message":"POD file(s) captured","data":{"images":["https://shiplogic-backend-prod-infra-images-and-notes.s3.af-south-1.amazonaws.com/shipment-images/8155533-fe1e0e10-324c-4360-b2f4-be51f091f8bb.png?X-Amz-Algorithm=AWS4-HMAC-SHA256\u0026X-Amz-Credential=ASIA55D5DNTBLMDRXYD5%2F20220805%2Faf-south-1%2Fs3%2Faws4_request\u0026X-Amz-Date=20220805T113651Z\u0026X-Amz-Expires=86400\u0026X-Amz-Security-Token=IQoJb3JpZ2luX2VjEJ7%2F%2F%2F%2F%2F%2F%2F%2F%2F%2FwEaCmFmLXNvdXRoLTEiRzBFAiB4vd1t%2F11LRUaoSCpqMdIP8gOuT9L32p1LSyCzSiGUBQIhAMt8FtNGK6ibRWvAJtIf%2FIGvOsESyCw2bIgNl27PWYBwKp0DCLv%2F%2F%2F%2F%2F%2F%2F%2F%2F%2FwEQAhoMOTU1ODkyNTkxODEwIgwhD2CnEtahYg8Ck0Iq8QLMbochjBL6wQyuYPgOrOyvgliZs44WoRZqjDllfIPfa86R5TDw6hKI6aTaQLpNWUInFDnrGRu7sd%2BolgUsqnN17lr20S2h7Fy%2FnU0Rwv2z11AYSXgXrvxWbHVMJzngkyfteitp0GpD3cjK%2BdIJ9iKRS8g%2BO5WfFQKu99StSfkTWgJ%2Fo1myNwJoJkWkWhYiO1c%2BStpBSs0vdKhSKLOuNu3HBQIpWTQ1U8qnGvNdigAdz%2B7gCJwsaNqUH%2FHtl3xNSSbUSkEzqYLzdkjmKNFUC%2BrVAePsS4UnVhkMmWlnal%2BvSI%2FgY%2BDE1IuuhWYl7kuWa5SC6E5p2vngpN9lm0EnDSmK3OFsohMIJnu23WUXBJTxpmx%2Fb6KL%2FPrXapAhHccAz%2FJFmeU55%2FnMp0AqiuHjWYWE1ei1TPR2mhyj94wTW3Y4lUxhnvfeHz7QmPeh3KN3HAN0S2WHDf9Bv1gUD6bDshj1tiREoeChZzfp1ZbArO86AOgw%2BcSzlwY6nQFtpA37RYzkLVk52OW4g1tyja35Mfs6%2FykajH9IqkjuTLqvNmGIfrS7cLGgqhvdLUEs3QTIYDfPbjgkNsl5roEHbI7NO%2FhfrjIpBVmOsxJsqp62yL8Ze%2F29hgfug0TnycpXSg1bAOQ5ROelqQi5kcuy%2FTT3tePuZy1EO%2BXTm0tQbE3tf0XkLw34cQ6078ZAQJ7tyI4R4qRnWfdTkLtM\u0026X-Amz-SignedHeaders=host\u0026X-Amz-Signature=9a3d73a886012ac24e4719888156922d840a73d43569934a8de33ab2336f47b1"]}}]
<Error>
<Code>AuthorizationQueryParametersError</Code>
<Message>
X-Amz-Algorithm only supports "AWS4-HMAC-SHA256 and AWS4-ECDSA-P256-SHA256"
</Message>
<RequestId>ECGG4HGD86Y0PYAY</RequestId>
<HostId>
qZHFwL8gZ3GEibJ6UmgAoNd97EMVGe1Xw24RjYIKAqqrOi2Cx+YPmBJGoCy4opTiih5Nz5YlEuU=
</HostId>
</Error>
Your code is actually entirely correct as far as getting the response, but the problem is that the response you're trying to copy the URL from is still JSON encoded. This leaves some of the parts of the URL in an invalid, encoded state; specifically, the & is encoded to /u0026.
...?X-Amz-Algorithm=AWS4-HMAC-SHA256\u0026...
That /u0026 at the end of each parameter is the culprit. If you json_decode() the response, then you get the correct URL.
The URL I received when I ran the code and decoded the result seems to work. All I did was add a line and change the last line:
...
$json = $response->getBody()->getContents();
$result = json_decode($json, false);
echo $result[0]->data->images[0];
You could obviously do that without adding a line and just changing the line where $json is assigned, but I wanted to leave that line alone to make it easier to see exactly what was different.
...
$json = json_decode($response->getBody()->getContents(), false);
echo $json[0]->data->images[0];
I want to send btc using my account with api with php.
I tried coinbase api from github which is depreciated
https://github.com/coinbase/coinbase-php
and i am getting error when i tried this code
require_once( __DIR__ . '/requires/coinbase/vendor/autoload.php');
use Coinbase\Wallet\Client;
use Coinbase\Wallet\Configuration;
use Coinbase\Wallet\Enum\CurrencyCode;
use Coinbase\Wallet\Resource\Transaction;
use Coinbase\Wallet\Value\Money;
$configuration = Configuration::apiKey($apiKey, $apiSecret);
$client = Client::create($configuration);
$transaction = Transaction::send([
'toBitcoinAddress' => "$bticoin_address",
'amount' => new Money($amount, CurrencyCode::USD),
'description' => 'Your first bitcoin!',
'fee' => '0.0001' // only required for transactions under BTC0.0001
]);
try {
$transaction = $client->createAccountTransaction($account, $transaction);
}
catch(Exception $e) {
echo $e->getMessage();
}
and i am getting this error
<b>Fatal error</b>: Uncaught TypeError: Argument 1 passed to Coinbase\Wallet\Exception\HttpException::exceptionClass() must be an instance of Psr\Http\Message\ResponseInterface, null given, called in /home/fiberpay/public_html/owner/requires/coinbase/vendor/coinbase/coinbase/src/Exception/HttpException.php on line 33 and defined in /home/fiberpay/public_html/owner/requires/coinbase/vendor/coinbase/coinbase/src/Exception/HttpException.php:98
Stack trace:
#0 /home/fiberpay/public_html/owner/requires/coinbase/vendor/coinbase/coinbase/src/Exception/HttpException.php(33): Coinbase\Wallet\Exception\HttpException::exceptionClass(NULL)
#1 /home/fiberpay/public_html/owner/requires/coinbase/vendor/coinbase/coinbase/src/HttpClient.php(137): Coinbase\Wallet\Exception\HttpException::wrap(Object(GuzzleHttp\Exception\RequestException))
#2 /home/fiberpay/public_html/owner/requires/coinbase/vendor/coinbase/coinbase/src/HttpClient.php(121): Coinbase\Wallet\HttpClient->send(Object(GuzzleHttp\Psr7\Request), Array)
#3 /home/fiberpay/public_html/owne in <b>/home/fiberpay/public_html/owner/requires/coinbase/vendor/coinbase/coinbase/src/Exception/HttpException.php</b> on line <b>98</b><br />
Is there anyway to do that ??
I spend much time to google it but still not found any solution that is i why i put that on there may be i got some good solution from there :)
Best Regars
Instead of using coinbase PHP wrapper use coinbase API itself
To send money from one coinbase account to another you can use the below code
first, get api_key and api_secret
$private_key = 'Doadlraixxxxxx'; //Coinbase Private Key
$api_key = 'ysEZjjBxxxxx'; //Coinbase API KEY
The Create a new stdClass object which contains your request method for withdrawing it will be POST, the path will be API path, and for withdrawing it will be /v2/accounts/:accountid/transactions, and then simply put private key and API key here
$json = new stdClass();
$json->method = "POST";
$json->path = "/v2/accounts/".$account_id."/transactions";
$json->secretapikey = $private_key;
$json->apikey = $api_key;
Now create another stdClass that contain your withdrawal info like email, currency, etc
$body = new stdClass();
$body->type = "send";
$body->to = $to_email;
$body->amount = $amount;
$body->currency = $currency;
then in the next step, we have to create a signature according to the timestamp for this we have to create SHA256 hash of current time, path, and the $body stdClass
$result = json_encode($json);
$body = json_encode($body);
$time= time();
$sign = $time.$json->method.$json->path.$body;
$hmac = hash_hmac("SHA256", $sign, $json->secretapikey);
Our Signature and body are ready now just need to post it
$URL = "https://api.coinbase.com/v2/accounts/".$account_id."/transactions";
$header = array(
"CB-ACCESS-KEY:".$api_key,
"CB-ACCESS-SIGN:".$hmac,
"CB-ACCESS-TIMESTAMP:".time(),
"CB-VERSION:2019-11-15",
"Content-Type:application/json"
);
$ch = curl_init($URL);
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
curl_setopt($ch, CURLOPT_HTTPHEADER,$header);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
print_r($result);
After sending a request the money will be sended successfully.
And with a little decoration code will look like this
https://gist.github.com/AdityaEXP/27408bd361d5b8fcc9ac2bf459eb5303
I've been using the coinbase php library for 4years.
When you get that error, it's highly probably due to incorrect account credentials.
Also, the default github library has an expired uploaded certificate in one of its folder.
You have to replace it.
Coinbase PHP works fine for me everytime.
I am trying to get a list of all my Twilio numbers using cURL inside of a php function. I am getting the information I need back from Twilio however it is just a string of all the information with no whitespace or anything.
This is what I am getting back. I have removed my account number and sid:
string(1621) " {{ SID }}ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX(936) 585-6544+19365856544https://demo.twilio.com/welcome/sms/reply/POSTPOSTfalseWed, 11 May 2016 14:39:22 +0000Wed, 18 May 2016 15:41:25 +0000https://demo.twilio.com/welcome/sms/reply/POSTPOSTnonefalsetruetruetruePOST2010-04-01/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/IncomingPhoneNumbers/PN5e0ef24464a1fbbcf4e2bd127c471892"
Here is the function I am using to cURL Twilio.
function post_incoming($POST) {
// resource url & authentication
$uri = 'https://api.twilio.com/2010-04-01/Accounts/' . $this->sid . '/IncomingPhoneNumbers';
$auth = $this->sid . ':' . $this->authtoken;
$res = curl_init();
// set cURL options
curl_setopt( $res, CURLOPT_URL, $uri );
curl_setopt( $res, CURLOPT_USERPWD, $auth ); // authenticate
curl_setopt( $res, CURLOPT_RETURNTRANSFER, true ); // don't echo
// send cURL
$result = curl_exec( $res );
var_dump($result);
return $result;
}
I need to get the information back as a json array or some kind of array that way I can parse out the Twilio phone number for later.
It is a lot easier if you use the PHP helper library. It woudl look something like this:
// Your Account Sid and Auth Token from twilio.com/user/account
$sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
$token = "{{ auth_token }}";
$client = new Services_Twilio($sid, $token);
$numbers_arr = array();
// Loop over the list of numbers and echo a property for each one
foreach ($client->account->incoming_phone_numbers as $number) {
$numbers_arr[] = $number->phone_number;
}
return json_encode($numbers_arr);
}
This function uses the Twilio PHP SDK to get a list of all numbers in the account then puts them into an array variable $numbers_arr and returns that variable as JSON.
I'm trying to set up a fb messenger chatbot but don't seem to be able to get the webhook callback url verified. Every time I try to verify it I get this error message - The URL couldn't be validated. Response does not match challenge, expected value = '1596214014', received=''
Here's the screenshot:
Screenshot
Here's the php I'm using -
<?php
$challenge = $_REQUEST['hub_challenge'];
$verify_token = $_REQUEST['hub_verify_token'];
if ($verify_token === 'token_my_token') {
echo $challenge;
}
I've also tried
echo $_GET['hub_challenge'];
and just
echo file_get_contents('php://input');
All of these result in the same error message as above. Basically, as far as I can tell facebook isn't sending a GET request to my server or if it is it doesn't include any data. Can anyone tell if I am doing something wrong or if there is a setting I need to change to ensure facebook is sending the data correctly?
Edit - When checking the access logs this is what I find, which looks like facebook isn't sending any data in the get request.
2a03:2880:1010:dffb:face:b00c:0:8000 - - [19/Apr/2016:20:50:06 +0000] "GET /wp-content/plugins/applications/fbmessenger.php HTTP/1.0" 200 - "-" "facebookplatform/1.0 (+http://developers.facebook.com)
Thanks
just try my code and it's gonna work.
$challenge = $_REQUEST['hub_challenge'];
$verify_token = $_REQUEST['hub_verify_token'];
if ($verify_token === 'Your's app token') {
echo $challenge;
}
//Token of app
$row = "Token";
$input = json_decode(file_get_contents('php://input'), true);
//Receive user
$sender = $input['entry'][0]['messaging'][0]['sender']['id'];
//User's message
$message = $input['entry'][0]['messaging'][0]['message']['text'];
//Where the bot will send message
$url = 'https://graph.facebook.com/v2.6/me/messages?access_token='.$row;
$ch = curl_init($url);
//Answer to the message adds 1
if($message)
{
$jsonData = '{
"recipient":{
"id":"'.$sender.'"
},
"message":{
"text":"'.$message. ' 1' .'"
}
}';
};
$json_enc = $jsonData;
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json_enc);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
if(!empty($input['entry'][0]['messaging'][0]['message'])){
$result = curl_exec($ch);
}
you have to return Challenges so Facebook can verify its correct Url and Token Match
<?php
$challenge = $_REQUEST['hub_challenge'];
$verify_token = $_REQUEST['hub_verify_token'];
if ($verify_token === 'token_my_token') {
echo $challenge;
}
Facebook Docs Link ( In Node.js ) You can see challenge return after verifying the token
https://developers.facebook.com/docs/messenger-platform/getting-started/webhook-setup
Could you try my API? https://github.com/Fritak/messenger-platform
If you set it like in example, it should work:
// This is just an example, this method of getting request is not safe!
$stream = file_get_contents("php://input");
$request = empty($stream)? $_REQUEST : $stream;
$bot = new \fritak\MessengerPlatform(
['accessToken' => 'token_for_app',
'webhookToken' => 'my_secret_token',
'facebookApiUrl' => 'https://graph.facebook.com/v2.6/me/' //2.6 is minimum
], $request);
if($bot->checkSubscribe())
{
print $bot->request->getChallenge();
exit;
}
If not, problem is somewhere between Facebook and script, not in PHP itself. Go check apache settings etc.
Well issue might be on facebook side, they had some issues over past few days...
Have only this code in your php file: (fbmessenger.php)
<?php
// header('HTTP/1.1 200 OK');
/* GET ALL VARIABLES GET & POST */
foreach ($_REQUEST AS $key => $value){
$message .= "$key => $value ($_SERVER[REQUEST_METHOD])\n";
}
$input = file_get_contents("php://input");
$array = print_r(json_decode($input, true), true);
file_put_contents('fbmessenger.txt', $message.$array."\nREQUEST_METHOD: $_SERVER[REQUEST_METHOD]\n----- Request Date: ".date("d.m.Y H:i:s")." IP: $_SERVER[REMOTE_ADDR] -----\n\n", FILE_APPEND);
echo $_REQUEST['hub_challenge'];
You will have requests saved in a file called "fbmessenger.txt" in the same directory.
Note that for some strange reason you may need to submit few times to
get it approved & saved! (I had to hit "save" 8-9 times before fb
approved link)
Make sure you use https (SSL) connection and once your connection is done, verify your token with "hub_verify_token" to make sure request is coming from fb.
I need to import quotes into vtiger.
I find out it can be be done using vtiger web services API
I find out the reference manual:
https://wiki.vtiger.com/archives/index.php/vtiger510:Webservice_reference_manual
But i can't find any example PHP script, neither what data fields I need to pass to webservice.php.
Please help, I need some guidance.
I have done something like this, I have a quick and (rather) dirty but working solution:
<?php
function createOffer($account_id,$subject,$offerlanguage, $totalamount,$date_submission,$date_decision,$date_start,$assigned_user_id,$quotestage,$winningchance,$description,$productarray){
global $adb;
$endpointUrl = "[your URL]/webservice.php";
$userName="admin";
$userAccessKey = '[your accesskey]';
$httpc = new HTTP_CLIENT();
//getchallenge request must be a GET request.
$httpc->GET($endpointUrl."?operation=getchallenge&username=".$userName);
$response = $httpc->currentResponse();
//decode the json encode response from the server.
$jsonResponse = Zend_JSON::decode($response['body']);
//check for whether the requested operation was successful or not.
if($jsonResponse['success']==false)
//handle the failure case.
die('getchallenge failed:'.$jsonResponse['error']['errorMsg']);
//operation was successful get the token from the reponse.
$challengeToken = $jsonResponse['result']['token'];
//create md5 string concatenating user accesskey from my preference page
//and the challenge token obtained from get challenge result.
$generatedKey = md5($challengeToken.$userAccessKey);
//getchallenge request must be a GET request.
$httpc->post("$endpointUrl",
array('operation'=>'login', 'username'=>$userName, 'accessKey'=>$generatedKey), true);
$response = $httpc->currentResponse();
//decode the json encode response from the server.
$jsonResponse = Zend_JSON::decode($response['body']);
//operation was successful get the token from the reponse.
if($jsonResponse['success']==false)
//handle the failure case.
die('login failed:'.$jsonResponse['error']['errorMsg']);
//login successful extract sessionId and userId from LoginResult to it can used for further calls.
$sessionId = $jsonResponse['result']['sessionName'];
$userId = $jsonResponse['result']['userId'];
$currency_id=1;
$params = array('description'=>$description,'subject'=>$subject,'quotestage'=>$quotestage,'assigned_user_id'=>'2x'.$assigned_user_id,'account_id'=>'3x'.$account_id,'cf_682'=>$offerlanguage,'currency_id'=>'21x'.$currency_id,'taxtype'=>'group','cf_683'=>$date_submission,'cf_684'=>$date_decision,'cf_685'=>$date_start,'cf_766'=>$winningchance);
$urlArgs = "?&total=".$totalamount;
//encode the object in JSON format to communicate with the server.
$objectJson = Zend_JSON::encode($params);
//name of the module for which the entry has to be created.
$moduleName = 'Quotes';
//sessionId is obtained from loginResult.
$params = array("sessionName"=>$sessionId, "operation"=>'create', "element"=>$objectJson, "elementType"=>$moduleName);
//Create must be POST Request.
$httpc->post($endpointUrl.$urlArgs, $params, true);
$response = $httpc->currentResponse();
//decode the json encode response from the server.
$jsonResponse = Zend_JSON::decode($response['body']);
$savedObject = $jsonResponse['result'];
$id = $savedObject['id'];
$id=str_replace("13x", "", $id);
echo $id." offer: ".$subject." created for amount ".$totalamount." for customer: ".$account_id." assigned to: ".$assigned_user_id;
return $id;
}
As you see there are a few custom fields too so you can see how I've handled those.
You can call this function like this:
createOffer($account_id, $subject, $offerlanguage, $totalamount, $date_submission, $date_decision, $date_start, $assigned_user_id, $quotestage, $winningchance, $description, $productarray)
Then you need to add the products too, which I've found the easiest via a separate function as there can be more products per quote...
<?php
function createProducts($productarray,$id) {
$counter = 1;
foreach ($productarray as $prod) {
$query ="insert into vtiger_inventoryproductrel(id, productid, sequence_no, quantity, listprice) values(?,?,?,?,?)";
$qparams = array($id,$prod['prod'],$counter,$prod['pcs'],$prod['price']);
$productadded=$adb->pquery($query,$qparams);
$counter=$counter+1;
}
}
use it like this:
$prodlist = array();
array_push($prodlist,array('prod'=>"prod1",'pcs'=>2,'price'=>1000));
array_push($prodlist,array('prod'=>"prod2",'pcs'=>2,'price'=>100));
createProducts($prodlist,10);
so my logic is like this:
you create the quote with the createOffer function. It returns with the newly created quote's ID
then you build the array of products (I have just the very basic data here) and add that by referencing the quote's ID
Maybe not the most beautiful solution but works.
Maybe you can start like this (according to your reference link).
Manual: https://wiki.vtiger.com/archives/index.php/vtiger510:Webservice_reference_manual
Login: https://wiki.vtiger.com/archives/index.php/vtiger510:Webservice_reference_manual#Login
Pseudo;
<?php
class VTiger_Login
{
private $serviceURL = 'http://vtiger_url/webservice.php?operation=login&username=%s&accessKey=%s';
// A Vtiger username.
private $userName = 'my_username';
// An md5 of the concatenation of the challenge token and the user's webservice access key.
private accessKey = 'my_accesskey';
public function login() {
// Open CURL
$ch = curl_init();
// Set URL as same as on manual
curl_setopt($ch, CURLOPT_URL, sprintf($this->serviceURL, $this->userName, $this->accessKey));
// Need POST according to manual
curl_setopt($ch, CURLOPT_POST, 1);
// Receive server response = TRUE
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// Exec CURL
$result = curl_exec($ch);
// Close CURL
curl_close($ch);
/*
$result should be like this according to manual;
LoginResult {
sessionId: String // Unique Identifier for the session
userId: String // The vtiger id for the logged in user
version: String // The version of the webservices api
vtigerVersion: String // The version of the vtiger crm.
}
*/
// From manual: All structural data including response from the api is represented as JSON strings.
$result =# json_decode($result);
// See "Response" on manual
if (null === $result) {
throw new Exception('No response returned from Vtiger server!');
}
// See "ErrorObject" on manual
if (null !== $result->success && false === $result->success) {
throw new Exception('Something went wrong with login operation! errorCode: '.
$result->errorCode .', errorMessage: '. $result->errorMessage);
}
// I think, there is no problem anymore, go with $result after this line...
}
}