I need to do some basic Fedex package tracking. I'm using Jeremy Dunn's php-fedex-api-wrapper. My FedEx developer credentials are setup and I am able to authenticate via the FedEx api.
The problem: when I run a basic track request using the api-wrapper code I get back a result that I am unsure how to interpret. It looks like a structure that I should have no trouble parsing but I cannot.
Here are the first few lines of the result code that I see when I var_dump($trackReply)
object(FedEx\TrackService\ComplexType\TrackReply)#66 (2) {
["name":protected]=>
string(10) "TrackReply"
["values":protected]=>
array(4) {
If I cast the result as an array and print_r it looks like this (truncated version):
Array
(
[0] => FedEx\TrackService\ComplexType\TrackReply Object
(
[name:protected] => TrackReply
[values:protected] => Array
(
[HighestSeverity] => SUCCESS
[Notifications] => Array
(
[0] => FedEx\TrackService\ComplexType\Notification Object
(
[name:protected] => Notification
[values:protected] => Array
(
[Severity] => SUCCESS
[Source] => trck
[Code] => 0
[Message] => Request was successfully processed.
[LocalizedMessage] => Request was successfully
processed.
)
)
)
The $trackResult is obviously an object, but I cannot figure out how to access its specific properties. When it is cast as an array, element zero is clearly an object, so I would think I could access the object properties with
I tried $test = $trackResult[0];// which should now be an object, right?
and then
I looked at this StackOverflow post and it seems to be relevant: Convert a PHP object to an associative array
So I tried one of the solutions from the link above:
$array = json_decode(json_encode($nested_object), true);
But, when I print_r($array) I get essentially an empty array like this:
Array
(
)
I'm using Facebooks Webhooks for lead generations. I successfully can fetch leadgen_id from the Facebooks callback.
So this is what Facebook returns for the leadgen field:
Array
(
[entry] => Array
(
[0] => Array
(
[changes] => Array
(
[0] => Array
(
[field] => leadgen
[value] => Array
(
[ad_id] => 0
[form_id] => 1109138149146076
[leadgen_id] => 1109157429144148
[created_time] => 1467887375
[page_id] => 152161181508654
[adgroup_id] => 0
)
)
)
[id] => 152161181508654
[time] => 1467887376
)
)
[object] => page
)
Is it possible to somehow get campaign ID from these values that Facebook returns?
There is no clue to campaign in leadgen itself and in the form that I fetched with leadgen_id and form_id.
I also tried to fetch all ad account campaigns with
/v2.6/<ad_account_id>/campaigns
endpoint and thought that I will see some connection there with form or leadgen, but nothing there as well.
So, I need to fetch it so that I can group leadgen forms in Facebook. With current implementation, unfortunately it is not possible - I guess Facebook didn't thought of that :(
Just in case someone will struggle with this as well:
We can grab ad id info from:
'https://graph.facebook.com/v2.6/<AD_ID>?access_token=<ACCESS_TOKEN>&fields=campaign_id';
And this will return us campaign id.
Reason why I didn't try this in first place, was because in initial response, Facebook returned ad_id as 0, but after some while I realised that this is probably because it was a test lead from https://developers.facebook.com/tools/lead-ads-testing
I am trying to execute queries on statements stored in Learning Locker via PHP and TinCanPHP API. Going by this answer, I was able to fetch a response from Learning Locker. Here is a part of the response:
TinCan\LRSResponse Object
(
[success] => 1
[content] => TinCan\StatementsResult Object
(
[statements:protected] => Array
(
[0] => TinCan\Statement Object
(
[id:protected] => 9ea9e6b6-8278-4545-a02c-c46113f3ba30
[stored:protected] => 2016-02-28T12:04:01.670600+00:00
[authority:protected] => TinCan\Agent Object
(
[objectType:protected] => Agent
[name:protected] => New Client
[mbox:protected] => mailto:hello#learninglocker.net
[mbox_sha1sum:protected] =>
[openid:protected] =>
[account:protected] =>
)
[version:protected] => 1.0.0
[attachments:protected] => Array
(
)
[actor:protected] => TinCan\Agent Object
(
[objectType:protected] => Agent
[name:protected] => Subhayan Roy
[mbox:protected] => mailto:subhayanroy5#gmail.com
[mbox_sha1sum:protected] =>
[openid:protected] =>
[account:protected] =>
)
[verb:protected] => TinCan\Verb Object
(
[id:protected] => http://activitystrea.ms/schema/1.0/search
[display:protected] => TinCan\LanguageMap Object
(
[_map:protected] => Array
(
[en-US] => Searched
)
)
)
The list of statements returned has permission protected, so I'm not being able to access them. How do I access the statements? What am I missing here?
You need to use the methods built into the library. In this case the one you want is getStatements.
$statementResult->content->getStatements();
See the documentation here: http://rusticisoftware.github.io/TinCanPHP/doc/api/latest/classes/TinCan.StatementsResult.html#method_getStatements
To answer the question which you will ask next (Why aren't I getting all statements returned in the result?), Take a look at the Statement Result getMore method which gives you the more URL and the Remote LRS moreStatements method which accepts a more URL and fetches the next batch of statements. See this code sample: https://github.com/garemoko/TinBadgesPHP/blob/b8789042f4af23f0f7927596e8e7f2a06655db72/TinBadges/RemoteLRS.php#L84-L96
When I do a query (for example 'gluue') utilizing PHP's Solr plugin I get different spellcheck collation results then when using Solr's url based system.
http://xxx:8080/solr/example/browse?q=gluue%0A&wt=xml&spellcheck=true
returns :
<lst name="spellcheck"><lst name="suggestions"><lst name="gluue"><int name="numFound">10</int><int name="startOffset">0</int><int name="endOffset">5</int><arr name="suggestion"><str>glue</str><str>gauge</str><str>glide</str><str>glove</str><str>glued</str><str>globe</str><str>glaze</str><str>gluten</str><str>gauze</str><str>glues</str></arr></lst><lst name="collation"><str name="collationQuery">glue
</str><int name="hits">74</int><lst name="misspellingsAndCorrections"><str name="gluue">glue</str></lst></lst><lst name="collation"><str name="collationQuery">gauge
</str><int name="hits">6</int><lst name="misspellingsAndCorrections"><str name="gluue">gauge</str></lst></lst><lst name="collation"><str name="collationQuery">glide
</str><int name="hits">7</int><lst name="misspellingsAndCorrections"><str name="gluue">glide</str></lst></lst></lst></lst>
PHP plugin (replicating the query above exactly confirming within solrs log file)
[spellcheck] => SolrObject Object
(
[suggestions] => SolrObject Object
(
[gluue] => SolrObject Object
(
[numFound] => 10
[startOffset] => 0
[endOffset] => 5
[suggestion] => Array
(
[0] => glue
[1] => gauge
[2] => glide
[3] => glove
[4] => glued
[5] => globe
[6] => glaze
[7] => gluten
[8] => gauze
[9] => glues
)
)
[collation] => SolrObject Object
(
[collationQuery] => glide
[hits] => 7
[misspellingsAndCorrections] => SolrObject Object
(
[gluue] => glide
)
)
)
)
Note the 3 collationQuery values in the first response and only one in the PHP plugin.
The boss likes the first response ("glue") better so I'm going to have to bypass the plugin just for the spellcheck feature (and add an additional query to my system) because of this. Any ideas? I would really like to avoid this.
I am using SugarCRM Pro 6.5.5. I am trying to do some integration into another application, so I need to do some API calls from that other application. I am using the REST API v2. At this point, I need to get a Contact that is related to an Account via the account ID. I have tried both get_relationships() and get_entry_list(), but I can't get either of them to work.
Here's my input for get_relationships():
{"session":"eujfbfsfjgni98m0mivl6jm6r2","module_name":"Accounts","module_id":"c03d0649-0525-2f90-1206-50881e87d7dd","link_field_name":"contacts"}
I have tried many variations of this, and several other options, but nothing did what I wanted. This is the output from above:
stdClass Object
(
[entry_list] => Array
(
[0] => stdClass Object
(
[id] =>
[module_name] => Contacts
[name_value_list] => stdClass Object
(
[deleted] => stdClass Object
(
[name] => deleted
[value] => 0
)
[do_not_call] => stdClass Object
(
[name] => do_not_call
[value] => 0
)
)
)
)
[relationship_list] => Array
(
)
)
I don't see how this information could ever be useful.
Next up, I tried get_entry_list() with a query to select only the Contacts that had the given account ID. Here's my input for that:
{"session":"8mol33e7kdq6girugu30dnt074","module_name":"Contacts","query":"accounts.id = 'c03d0649-0525-2f90-1206-50881e87d7dd'"}
I am using accounts.id because I have read in similar questions, that is correct. I've tried many other things, like: contacts.account_id, account_id, etc. In every case, I get a MySQL error in the log stating the column is invalid.
SugarCRM: how to get all contacts for an account via REST API
This question is relevant, and seems to be the exact same problem. I tried adding a link_name_to_fields_array option to my input, but no matter what value I provide, it results in the following MySQL error in the log:
AND jt11.deleted=0 where (Array) AND contacts.deleted=0: MySQL error 1054: Unknown column 'Array' in 'where clause'
Dafuq?
Thanks.
Thanks to ychaouche, I figured it out.
I was able to use the get_relationships() method after all. I had tried before adding the related_fields to my input, but all that did was result in an empty result set. The answer? Set related_module_query to an empty string... and now the result set is not empty. Yep, my 3+ hours of furious Googleing last night is because of that.
So, here is some working code in case anyone else has this problem:
{
"session": "iov9pg9kvvl60librung1h5fh6",
"module_name": "Accounts",
"module_id": "c03d0649-0525-2f90-1206-50881e87d7dd",
"link_field_name": "contacts",
"related_module_query": "",
"related_fields": [
"first_name",
"last_name"
],
"deleted": false
}
This got me the following result set:
stdClass Object
(
[entry_list] => Array
(
[0] => stdClass Object
(
[id] =>
[module_name] => Contacts
[name_value_list] => stdClass Object
(
[first_name] => stdClass Object
(
[name] => first_name
[value] => John
)
[last_name] => stdClass Object
(
[name] => last_name
[value] => Smith
)
)
)
)
[relationship_list] => Array
(
)
)
You can of course specify different fields in related_fields and get different pieces of data.
Take a look at sugarcrm/tests/service/RESTAPI4Test.php. It's got plenty of examples on how to use the REST API. It's a common practice to look at test code for code examples on how to use a library/framework/API. Tests are in this sense a very good documentation.
Hope that helps.