I'm using the qbo-api-v3 for PHP to authenticate and retrieve a Balance Sheet report via PHP script. This has been working just fine over the last 6 months, but recently stopped returning data (returns NULL for repsonseCOde, responseBody, and responsArray). I can't figure out why - any ideas? Thanks!
// qbo API
require_once dirname(__FILE__).'/../v3-php-sdk-2.2.0-RC/config.php';
require_once(PATH_SDK_ROOT . 'Core/ServiceContext.php');
require_once(PATH_SDK_ROOT . 'PlatformService/PlatformService.php');
require_once(PATH_SDK_ROOT . 'Utility/Configuration/ConfigurationManager.php');
require_once(PATH_SDK_ROOT . 'Core/CoreHelper.php');
require_once(PATH_SDK_ROOT . 'DataService/Batch.php');
require_once(PATH_SDK_ROOT . 'DataService/IntuitCDCResponse.php');
require_once(PATH_SDK_ROOT . 'Data/IntuitRestServiceDef/IPPAttachableResponse.php');
require_once(PATH_SDK_ROOT . 'Data/IntuitRestServiceDef/IPPFault.php');
require_once(PATH_SDK_ROOT . 'Data/IntuitRestServiceDef/IPPError.php');
require_once('RestServiceHandler.php');
require_once(PATH_SDK_ROOT . 'Core/OperationControlList.php');
// QBO Service Context
$serviceType = IntuitServicesType::QBO;
$oauth['AccessToken'] = ...
$oauth['AccessTokenSecret'] = ...
$oauth['ConsumerKey'] = ...
$oauth['ConsumerSecret'] = ...
$oauth['RealmID'] = ...
$requestValidator = new OAuthRequestValidator(ConfigurationManager::AppSettings('AccessToken'),
ConfigurationManager::AppSettings('AccessTokenSecret'),
ConfigurationManager::AppSettings('ConsumerKey'),
ConfigurationManager::AppSettings('ConsumerSecret'));
$serviceContext = new ServiceContext($oauth['RealmID'], $serviceType, $requestValidator); //d($serviceContext);
if (!$serviceContext) exit("Problem while initializing ServiceContext.\n");
// query for Balance Sheet Report - https://developer.intuit.com/docs/api/accounting/balance%20sheet
$report = 'BalanceSheet';
$query = "start_date=$start_date&end_date=$end_date";
$uri = "company/{1}/reports/$report?{2}";
$uri = str_replace("{1}", $oauth['RealmID'] , $uri);
$uri = str_replace("{2}", $query , $uri);
// Creates request parameters
$requestParameters = new RequestParameters($uri,'GET',CoreConstants::CONTENTTYPE_APPLICATIONJSON, NULL);
$restRequestHandler = new RestServiceHandler($serviceContext);
// Make the request
list($responseCode,$responseBody) = $restRequestHandler->GetReportsResponse($requestParameters, NULL, NULL);
$responseArray = json_decode($responseBody, true);
Related
I can get data from the Trello API using this:
private function get_card_info($card_id) {
$client = new \GuzzleHttp\Client();
$base = $this->endpoint . $card_id;
$params = "?key=" . $this->api_key . "&token=" . $this->token;
$cardURL = $base . $params;
$membersURL = $base . "/members" . $params;
$attachmentsURL = $base . "/attachments" . $params;
$response = $client->get($cardURL);
$this->card_info['card'] = json_decode($response->getBody()->getContents());
$response = $client->get($membersURL);
$this->card_info['members'] = json_decode($response->getBody()->getContents());
$response = $client->get($attachmentsURL);
$this->card_info['attachments'] = json_decode($response->getBody()->getContents());
}
However, this is broken into three calls. Is there a way to get card information, the member information, and the attachment information all in one call? The docs mention using &fields=name,id, but that only seems to limit what's returned from the base call to the cards endpoint.
It's absurd to have to hit the API 3 times every time I need card information, but I can't find any examples gathering all that's needed.
Try hitting the API with following parameters:
/cards/[id]?fields=name,idList&members=true&member_fields=all&& attachments=true&&attachment_fields=all
Trello replied to me, and stated that they would have answered much like Vladimir did. However, the only response I got from that was the initial card data, sans attachments and members. However, they also directed me to this blog post that covers batching requests. They apparently removed it from the docs because of the confusion it created.
To summarize the changes, you essentially make a call to /batch, and append a urls GET parameter with a comma separated list of endpoints to hit. The working final version ended up looking like this:
private function get_card_info($card_id) {
$client = new \GuzzleHttp\Client();
$params = "&key=" . $this->api_key . "&token=" . $this->token;
$cardURL = "/cards/" . $card_id;
$members = "/cards/" . $card_id . "/members";
$attachmentsURL = "/cards/" . $card_id . "/attachments";
$urls = $this->endpoint . implode(',', [$cardURL, $members, $attachmentsURL]) . $params;
$response = $client->get($urls);
$this->card = json_decode($response->getBody()->getContents(), true);
}
I'm getting this error " Ooop! Error: Element {}item invalid at this location " at the time of calling Salesforce web service in PHP.
Bellow are my approaches:
require_once('salesforceAPI/soapclient/SforceEnterpriseClient.php');
require_once('salesforceAPI/soapclient/SforceHeaderOptions.php');
$sfdc = new SforceEnterpriseClient();
$SoapClient = $sfdc->createConnection('enterprise.wsdl.xml');
$loginResult = false;
$loginResult = $sfdc->login(USER, PASSWORD . SECURITY_KEY);
$parsedURL = parse_url($sfdc->getLocation());
define("_SFDC_SERVER_", substr($parsedURL['host'], 0, strpos($parsedURL['host'], '.')));
define("_WS_NAME_", 'salesforceAPI/Ctest');
define("_WS_WSDL_", _WS_NAME_ . '.xml');
define("_WS_ENDPOINT_", 'https://' . _SFDC_SERVER_ . '.salesforce.com/services/wsdl/class/' . _WS_NAME_);
define("_WS_NAMESPACE_", 'http://soap.sforce.com/schemas/class/' . _WS_NAME_);
$client = new SoapClient(_WS_WSDL_);
$sforce_header = new SoapHeader(_WS_NAMESPACE_, "SessionHeader", array("sessionId" => $sfdc->getSessionId()));
$client->__setSoapHeaders(array($sforce_header));
$method = $client->__getFunctions();
$wsParams = array('accName' => 'dasarathi');
$client->cInsert($wsParams);
I have no clue for solution.
It was a file path issue. Below is the rectification:
define("_WS_NAME_", 'salesforceAPI/Ctest');
// there is no such path http://soap.sforce.com/schemas/class/slesforceAPI/Ctest
define("_WS_NAMESPACE_", 'http://soap.sforce.com/schemas/class/' . _WS_NAME_);
I just redeclared the WS_NAME constant:
define("_WS_NAME_", 'Ctest');
Im able to put a file (image.png) on to my Google Cloud Storage bucket using the google-api-php-client, but now im having trouble trying to create a signed url to get access to the file from my website. Sample code:
$bucketName = 'bucket-name';
$id = 'image.png';
$serviceAccountName = '123456789-xxxx#developer.gserviceaccount.com';
$privateKey = file_get_contents($location_to_key_file);
$signer = new \Google_P12Signer($privateKey, "notasecret");
$ttl = time() + 3600;
$stringToSign = "GET\n" . "\n" . "\n" . $ttl . "\n". '/' . $bucketName . '/' . $id;
$signature = $signer->sign(utf8_encode($stringToSign));
$finalSignature = \Google_Utils::urlSafeB64Encode($signature);
$host = "https://".$bucketName.".storage.googleapis.com";
echo $host. "/".$id."?GoogleAccessId=" . $serviceAccountName . "&Expires=" . $ttl . "&Signature=" . $finalSignature;
Returns:
<Error><Code>SignatureDoesNotMatch</Code>
<Message>The request signature we calculated does not match the signature you provided. Check your Google secret key and signing method.</Message>
<StringToSign>
GET 1387590477 /bucketname/image.png</StringToSign></Error>
im using google-api-php-client with php 5.5
ive followed a few examples:
https://groups.google.com/forum/#!topic/gs-discussion/EjPRAWbWKbw
https://groups.google.com/forum/#!msg/google-api-php-client/jaRYDWdpteQ/xbNTLfDhUggJ
Maybe a config value im not passing correctly ?
i assume the Service Account email should be used. Also tried to include md5hash and content-type in the $stringToSign, same results.
any help/tips would be appreciated.
The rdb almost do the trick for me. I used a working python example from GoogleCloudPlatform for python in order to debug what was wrong with the url and find the following:
The GoogleAccessId have to be urlencoded
You've to replace in the Signature the following characters: '-' => '%2B', '_' => '%2F
The signature must end with '%3D'
Code:
$host. "/".$id."?Expires=" . $ttl . "&GoogleAccessId=" .
urlencode($serviceAccountName) . "&Signature=" .
str_replace(array('-','_',), array('%2B', '%2F'),urlencode($finalSignature)).'%3D';
Now the url should work and you can use some advanced operators like response-content-disposition or response-content-type
Can you try constructing signed URL by using $host as -
$host = "https://".$bucketName.".commondatastorage.googleapis.com";
There is one difference I found with the doc you are referring.
Thanks
can you try this codes :)
$finalSignature = base64_encode($signature);
echo $host. "/".$id."?GoogleAccessId=" . $serviceAccountName . "&Expires=" . $ttl . "&Signature=" . urlencode($finalSignature);
I think your error is in the $finalSignature = \Google_Utils::urlSafeB64Encode($signature); line. This method does something weird with the URL and replaces certain characters.
In the end I got it all working with the following code:
$expires = time() + 60 * 30; // Half an hour
// Get the key from the key file
$privateKeyPath = Config::get('gcs.signing.key');
$privateKey = file_get_contents($privateKeyPath);
$signer = new Google_Signer_P12($privateKey, Config::get('gcs.signing.password'));
//Signing does not like spaces, however it also doesn't like urlencoding or html entities
$cloudStoragePath = str_replace(' ', '%20', $cloudStoragePath);
//Create string to sign
$stringToSign = "GET\n\n\n" . $expires . "\n" . "/" . $cloudStoragePath;
//Sign
$signature = $signer->sign(utf8_encode($stringToSign));
$query = array(
'GoogleAccessId' => Config::get('gcs.signing.service_account'),
'Expires' => $expires,
'Signature' => base64_encode($signature)
);
$url = self::$storageBaseUrl . '/' . $cloudStoragePath . '?' . http_build_query($query);
I am new in EAN development. I am developing hotel booking system in PHP using EAN. I want to fetch the reservation details from EAN API.
Following is my code:
$itinerary = xxxxxx;
$cid = 55505;
$minorRev = 13;
$apiKey = "y2dfnyvwbwkvgth76hfjdej7";
$locale = "en_US";
$currencyCode = "USD";
$customerSessionId;
$customerUserAgent;
$customerIpAddress;
$url = "http:api.ean.com/ean-services/rs/hotel/v3/";
$urlBook = "https:book.api.ean.com/ean-services/rs/hotel/v3/";
$url = ($service == 'res') ? $urlBook : $url;
$url .= $service
. "?minorRev={$minorRev}"
. "&cid={$cid}"
. "&apiKey={$apiKey}"
. "&customerUserAgent=" . rawurlencode($customerUserAgent)
. "&customerIpAddress={$customerIpAddress}"
. "&customerSessionId={$customerSessionID}"
. "&locale={$locale}"
. "¤cyCode={$currencyCode}";
$xml = "
<HotelItineraryRequest>
<itineraryId>{$itinerary}</itineraryId>
<email>customer#mail.com</email>
</HotelItineraryRequest>
";
$curl = new Curl();
$info = $curl->exec($xml, $url, "ItinerarySearch");
print_r($info);
It showing the following error :
Cannot service this request.Authentication failure
What is the problem with this code. Is there any solution that how can I get Reservation details from EAN.
I use the demo php code library from expedia : http://developer.ean.com/code_library/samples/PHP_Booking
Thanks in advance.
I am able to get access_token for multiple permissions like emails, contacts, docs, etc. using oAuth 2.0. I have access_token
I got contacts using the following code.
$url = 'https://www.google.com/m8/feeds/contacts/default/full?max- results='.$max_results.'&oauth_token='.$access_token;
$response_contacts= curl_get_file_contents($url);
Now i want to get users Emails using this access_token.
i used this url . but it gives 401 unauthorized Error
$url = 'https://mail.google.com/mail/feed/atom&oauth_token='.$access_token;
$response_emails= curl_get_file_contents($url);
please guide me how can i get emails using access_token.
I've seen references to the Gmail feed using oauth_token as a request parameter. However, once I used the OAuth Playground I discovered that you need to pass your OAuth information as an Authorization header, as you'll see below.
<?php
$now = time();
$consumer = ...; // your own value here
$secret = ...; // your own value here
$nonce = ...; // same value you've been using
$algo = "sha1";
$sigmeth = "HMAC-SHA1";
$av = "1.0";
$scope = "https://mail.google.com/mail/feed/atom";
$path = $scope;
$auth = ...; // an object containing outputs of OAuthGetAccessToken
$args = "oauth_consumer_key=" . urlencode($consumer) .
"&oauth_nonce=" . urlencode($nonce) .
"&oauth_signature_method=" . urlencode($sigmeth) .
"&oauth_timestamp=" . urlencode($now) .
"&oauth_token=" . urlencode($auth->oauth_token) .
"&oauth_version=" . urlencode($av);
$base = "GET&" . urlencode($path) . "&" . urlencode($args);
$sig = base64_encode(hash_hmac($algo, $base,
"{$secret}&{$auth->oauth_token_secret}", true));
$url = $path . "?oauth_signature=" . urlencode($sig) . "&" . $args;
// Create a stream
$opts = array(
"http" => array(
"method" => "GET",
"header" => "Authorization: OAuth " .
"oauth_version=\"{$av}\", " .
"oauth_nonce=\"{$nonce}\", " .
"oauth_timestamp=\"{$now}\", " .
"oauth_consumer_key=\"{$consumer}\", " .
"oauth_token=\"{$auth->oauth_token}\", " .
"oauth_signature_method=\"{$sigmeth}\", " .
"oauth_signature=\"{$sig}\"\r\n"
)
);
$context = stream_context_create($opts);
$out = file_get_contents($path, false, $context);
?>