How to set an access point in ups API wrapper? - php

I am using the gabrielbull ups api wrapper and it is working fine, except when I want to add an UPS access point; the documentation says I have to declare a "AlternateDeliveryAddress". The access point data should then be printed on the ups label, but they are not appearing.
Since there isn't an example for this case on the wrapper GitHub page, I searched for methods on my own and found one but I have the feeling I forgot something since I don't receive any errors. I tried this code for the specific part. The surrounding code is like in the shipping class example
$address = new \Ups\Entity\Address();
$address->setAddressLine1($ap_addressline1);
$address->setPostalCode($ap_postal);
$address->setCity($ap_city);
$address->setCountryCode($ap_country);
$alternateTo = new \Ups\Entity\AlternateDeliveryAddress;
$alternateTo->setAddress($address);
$alternateTo->setUpsAccessPointId($ap_id);
$alternateTo->setName($ap_name);
$alternateTo->setAttentionName($ap_name);
$shipment->setAlternateDeliveryAddress($alternateTo);
Edit: I got this info of setting up the accesspoint from UPS support. The guy told me to set an alternate address with the AccessPoint data that will be printed at the bottom line of the label (where it's currently missing). If I misunderstood something (though we did a video conference and he showed me the result) and you know another way, feel free to tell me.

Ok after re-reading the official docs I found out what was missing.
If you want to use an accesspoint as address you also have to set the Indication Type via setShipmentIndicationType. There are 2 codes: 01 and 02 depending on the way you want to send it. Ofcourse I didn't add them before...
I haven't finished it yet because I get some errors but that's more about what information ups needs from me and so on. At least I can work with that.
As I mentioned in my initial post I used the example of the api wrapper as base and insert the required part before the request was send:
...
// Set Reference Number
...
// this is the part where you set shipment indication type for the accesspoint
$accesspoint = new \Ups\Entity\ShipmentIndicationType;
$accesspoint->setCode(Ups\Entity\ShipmentIndicationType::CODE_HOLD_FOR_PICKUP_ACCESS_POINT); // for "01"
#$accesspoint->setCode(Ups\Entity\ShipmentIndicationType::CODE_ACCESS_POINT_DELIVERY); // for "02"
$shipment->setShipmentIndicationType($accesspoint);
// Set payment information
...
// Ask for negotiated rates (optional)
...
// Get shipment info
...

Related

Analytics track custom events in new Web+App

I used to track custom events (API hits) with google analytics and PHP via cURL, but now analytics is deprecating this method. I understood that the new analytics Web+App is used to track this kind of events, but i cannot find anything that allows me to track those events.
my current code:
$response = $client->post('https://www.google-analytics.com/collect', [
'form_params' => [
'v' => 1,
't' => 'event',
'ec' => 'ap1-v1-xxx',
'ea' => 'invoke',
'el' => 'MY-API',
'tid' => 'XXXXXXXX',
'cid' => '555'
]
]);
Doing this, i was able to track every hit and have statistics about API usage, this is what the analytics panel looked-like:
But, as i said, analytics is deprecating this method, and it stopped tracking my hits:
https://support.google.com/firebase/answer/9167112?ref_topic=6386699
There is a way to keep track these custom events? I can't find anything alike in PHP or cURL whatsoever.
Thanks!
It's not so much the method (measurement protocol) has been deprecated, it's that it is using a new, as of yet apparently undocumented, version 2 of the measurement protocol.
That makes sense - you cannot sent hit type anymore (because there is now a single type event, whose name can be customized), and you cannot send event category, action and label, since those no longer exist, and have been replaced by event parameters.
Since there does not seem to be documentation yet, you can do a bit of reverse engineering. I looked at the request issued by the code from a web&app property (actually gtag.js) for a pageview:
https://www.google-analytics.com/g/collect? // endpoint, remains the same
v=2 // protocol version, v2
&tid=G-XXXXXXXXXX // tracking id
&_p=1253409603 // no idea, don't think this needs to be set
&sr=1920x1080 // screen resolution, not applicable to a serverside call
&ul=de-de // user agent language, probably not relevant for a serverside call
&cid=533127994.1575982871 // client id
&_s=1 // no idea
&en=pageview // event - this corresponds broadly to hit type t in the previous version
&dl=http://localhost/test2.html // document location
&dr= // document referrer, not relevant for a serverside call
&dt=Title // document title
&sid=1575982870 // no idea
&sct=1 // no idea
&seg=1 // no idea
I think for a serverside application you can ignore all parameters marked with "no idea" (I assume that is something determined by the Javascript tracking code).
Instead of "v=1" you need to set "v=2", and instead of "t" for hit type you need "en" for event name. I will see if I can work out how to sent event parameters (I am in the office and don't really have time to experiment), but in any case this should be enough to get you started (I tested a call via curl and it showed up in the realtime section of a web&app property, so it should work for you, too).

Switching to GetSingleItem instead of findItemsAdvanced with the ebay-api

I am using the ebay-api's to pull out listing information using the itemId the user enters to import the current live auction on ebay into my site. I have been using the FindItemsAdvanced which is pretty straight forward grabbing the information using the SingleXMLElement
$itemid = (string) $xml->searchResult->item->itemId;
$shipcost = (string) $xml->searchResult->item->shippingInfo->shippingServiceCost;
I dont really need to use the FindItemsAdvanced because some information is missing, ie: quantity of a item listed.
I have looked at the documentation for GetSingleItem and it doesnt have a searchResult member, my question is, how is the above done with GetSingleItem to get the details.
This is the process i used but cant grab any details
url2 is - http://open.api.ebay.com/shopping?callname=GetSingleItem&responseencoding=XML&appid=myIdApp&siteid=0&version=967&ItemID=192401461174&IncludeSelector=Details
then the contents
$resp2 = file_get_contents($url2);
then the xml object
$xml2 = new SimpleXMLElement($resp2);
At this stage i have my object but i cant extract any details like a can with FindItemsAdvanced
Thanks to the comments i'm adding more information, the file_get_contents only gives me this
2017-12-24T12:33:55.736Z Success E1033_CORE_APILW_18542200_R1 1033 false 192401461174 2018-01-17T10:29:17.000Z 2017-12-18T10:29:17.000Z http://www.ebay.com/itm/Aspire-CF-SUB-OHM-Mod-Battery-Ecig-Vape-Kit-Carbon-Fibre-Aspire-k3-Samsung-25r-/192401461174 FixedPriceItem wigan, Lancashire PayPal http://thumbs3.ebaystatic.com/pict/1924014611748080_1.jpg https://i.ebayimg.com/00/s/NTQ1WDczMQ==/z/6PkAAOSwttFaD~0~/$_1.PNG?set_id=8800005007 https://i.ebayimg.com/00/s/NzIwWDI5MA==/z/kccAAOSwtGlZCa0C/$_1.JPG?set_id=880000500F https://i.ebayimg.com/00/s/OTAyWDYwMA==/z/Gk8AAOSw42JZCa0D/$_1.JPG?set_id=880000500F https://i.ebayimg.com/00/s/Nzg3WDExODE=/z/eNkAAOSwQcJaBAo8/$_1.JPG?set_id=880000500F https://i.ebayimg.com/00/s/OTAwWDkwMA==/z/zQgAAOSwyP5aD~1K/$_1.JPG?set_id=8800005007 https://i.ebayimg.com/00/s/NTAwWDUwMA==/z/6RIAAOSwttFaD~1L/$_1.PNG?set_id=8800005007 wn69jt 183498 Health & Beauty:E Cigarettes, Vapes & Accs:E Cigarettes, Vapes & Mods 5 improveyourlife Purple 525 100.0 0 31.94 23.9 Active 0 Worldwide UK P23DT21H55M22S 184 26395:183497:183498 GB 14 days Returns Accepted Only if broken Buyer false false 0 1000 New false 0 false true true
I understand i need to get the xml into a string to use namespaces but i'm not sure how to do that. The crazy thing is, the only thing i need out of GetSingleItem is the quantity because FindItemsAdvanced does not have it.
Try using $xml2 = simplexml_load_string($resp2); and then you should be able to get the information needed normally, with $quantity = $xml2->Item->Quantity;.
As a tip, I highly recommend you give a try to this SDK. I am using it for a long time, to manage multiple shops and it's extremely helpful. Saved me a huge amount of time. The guy who created it also made a ton of examples. You could have a look at those before using the SDK, and you'll see how much simpler everything is.

PHP: Docusign API autopopulate tabs for template

Objective: Autopopulate some values using the tabLabel/value key pair for server templates, using the beta Docusign PHP Client.
I've looked at quite a few stackoverflow posts and unfortunately the one that seems to be the closest related to me seems unanswered: Docusign API - prefilling tab values on envelope created from template
I was unable to find this "SecureField" option in any sort of preferences.
Currently, the name field fills in automatically just because of the template role being set accurately. I didn't have to do this with the tabLabel key, this was done automatically. I have tried creating a company tab, and that fails to autopopulate, so does a random text tab I have tried.
I have currently forked the library and made it PSR-4 compatible, and to achieve this objective I changed the following files:
TemplateRole Model: Modified the constructor to include $tabs, and set $this->tabs if $tabs is set. I added two functions getTabs()/setTabs($tabs) that behave the same as get/set RoleName, Name, Email, etc.
RequestSignatureResource: In the foreach ($templateRoles as $templateRole) I added a 'tabs' key to the array_pusy, and put $templateRole->getTabs().
I created a new TemplateRole('role name', 'person name', 'email', $tabs).
I can see the tabs in the JSON request data. Is there anything I'm missing?
I should also note that I used this post for inspiration, too: How to pre-fill tabs on a server template with the DocuSign API. The issue with this is that if I put textTabs:{text:{tabLabel:"something", value:"some value"}} then I get a response from the API that my request was invalid. I can provide that specific error upon request if needed.
The following worked for me :
$templateRole = new DocuSign\eSign\Model\TemplateRole();
$templateRole->setClientUserId($email);
$templateRole->setEmail($email);
$templateRole->setName($recipientName);
$templateRole->setRoleName($templateRoleName);
$textTab = new \DocuSign\eSign\Model\Text();
// I added this text field manually on docuSign site.
$textTab->setTabLabel("Field Label");
$textTab->setValue('Value');
$tabs = new DocuSign\eSign\Model\Tabs();
$tabs->setTextTabs(array($textTab));
$templateRole->setTabs($tabs);

Trying to complete a simple Dial action, and record the call - Twilio - have tried these 4 things

I am trying to make a Dial/Conference call in Twilio and to record it.
This works without error (Dial/Conference), but it doesn't record:
$response = new Response();
$dial = new Dial();
$conference = new Conference('name_of_conference_call', array('startConferenceOnEnter'=>"true", 'endConferenceOnExit'=>'false'));
$dial->append($conference);
$response->append($dial);
$response->Respond();
I just can't get the record element working. I only want it to record so it shows a recording in https://www.twilio.com/user/account/log/recordings, I don't need the recording on my server, or any record in a database.
I have seen this, but it doesn't resolve it: Twilio - Dial with Record attribute error
I have tried these, but always get the same "Error on line 1 of document : Premature end of file. Please ensure that the response body is a valid XML document." error.
(1) Adding 'record'=>true on either Dial or Conference causes that error:
$dial = new Dial(array('record'=>true));
OR
$conference = new Conference('name_of_conference_call', array('startConferenceOnEnter'=>"true", 'endConferenceOnExit'=>'false', 'record' => true));
(2) Adding the record=true parameter mentioned above and then also specifying an action (for Dial) or a eventCallbackUrl (for Conference) parameter. The URL (on my server) has exactly this PHP:
<?php
header("content-type: text/xml");
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
?>
<Response>
<Hangup/>
</Response>
I think this should be okay, as I don't want it to do anything else. I only want the recording in https://www.twilio.com/user/account/log/recordings, I don't need the recording on my server, or any record in a database.
Regardless, doing this causes the error mentioned above too.
(3) I then tried using the addRecord method in the Dial and Conference classes (separately), example:
(a) Without parameter:
$conference->addRecord();
AND
(b) With parameter:
$conference->addRecord(array('eventCallbackUrl' => 'http://domain.com/file_to_handle.php'));
(4) I also tried using the addRecord method on the Response class. This just got ignored, and didn't actually error.
$response->addRecord(); // Etc.
$response->Respond();
So, I just need to be able to record a call and see it in https://www.twilio.com/user/account/log/recordings
Twilio evangelist here.
The record attribute on the <Conference> noun does not take a boolean value. Instead if you want to tell Twilio to record the conference, set the attributes value to record-from-start.
The Conference noun docs have more details and if you scroll all the way to the bottom a TwiML example of using the record attribute.
https://www.twilio.com/docs/api/twiml/conference#attributes-record
https://www.twilio.com/docs/api/twiml/conference#examples-7
Hope that helps.

Highrise API Returning Error Code 500

I am attempting to use the PHP Wrapper for the Highrise API located here:
https://github.com/ignaciovazquez/Highrise-PHP-Api
I need to set a custom field for a HighrisePerson object. According to the code this should be pretty straightforward...
$person->setCustomField("Field Name", $value); // Pulled almost straight out of the documentation
Unfortunately when I try to save this back to highrise using $person->save(); I get the following error:
Uncaught exception 'Exception' with message 'API for Person returned Status Code: 500 Expected Code: 200'
So the error isn't in the code... Highrise just isn't accepting the custom field. Any ideas as to why this is?
In order to use 37signals throught Highrise-PHP-Api, you should provide an account name and access token;
$hr = new HighriseAPI();
$hr->setAccount("accountname");
$hr->setToken("token");
and then you can execute your other functions
$person->setCustomField("Field Name", $value);
If you carefully look at tests for this api, you will see;
if (count($argv) != 3)
die("Usage: php users.test.php [account-name] [access-token]\n");
Ok... I figured it out...
In the API the following:
$person->setCustomField("Field Name", $value);
creates a new custom field within Highrise. So if there isn't already a custom field named "Field Name" it would create it. If that field already exists, it returns the 500 error.
To the best of my knowledge there's no way to set the value of an existing field using that wrapper. You can only create new fields, which is kind of jank.
I found a fork off that wrapper that's working pretty well for me. It's hosted here: https://github.com/AppSaloon/Highrise-PHP-Api
The usage in this one is confusing and took me a while to figure out.
Basically you want to do a search for all the custom fields in Highrise. Once you find the one you want, you assign it the requisite value... So the code looks like this:
// Load up all the custom fields out of Highrise
$cfields = $highrise->findAllCustomfields();
// Search each custom field until we find the "Field Name" one. When we do, add it to our Highrise Person.
foreach ($cfields as $c) {
if ($c->getSubjectFieldLabel() == "Field Name")
{
// Assign that custom field to the person
$highrisePerson->addCustomfield($c, "Field Value");
}
}
I hope this helps someone else down the road who runs into the same issue. I discovered the forked PHP wrapper from another Stack Overflow question, but they were never able to get custom fields to work either.

Categories