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.
Related
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
...
I am using google shopping Api from last one year it is working properly. But now I want to add new attributes in it such as CustomLabel5. For that I have used setCustomAttributes() method and passed three attributes name, type ,value.
But it is working showing error 400 invalid attribute values. following is my code please check and suggest proper answer for that.
$product = new Google_Service_ShoppingContent_Product();
$data= new Google_Service_ShoppingContent_ProductCustomAttribute();
$data->setName('CustomLabel5');
$data->setType('text');
$data->setValue('test');
$product->setCustomAttributes($data);
Please give answer.
Fairly simple fix here.
setCustomAttributes expects an array of Google_Service_ShoppingContent_ProductCustomAttribute instances.
What you need is:
$attributesArray = array($data);
$product->setCustomAttributes($attributesArray);
I'm using CakePHP 2.X in my project and stuck at one point.
First of all let you know that i implemented search functionality using form's POST Method, But for this i found error in pagination. Filter will not sustain for next page. So i changed form method to GET. now its working OK ( Not exactly what i required, All requested data displaying in URL ), but now i'm at the point where its create another issue.
I got below error when i trying to search anything ( Existing data in DB ), and go to next page using pagination, now i changed search keyword with not matched in DB ( Data Not Exist in DB ).
Error: The requested address was not found on this server
Which was not there at the time of POST method.
I have tried with all the option in debug mode (Configure::write('debug', 2)). but not getting any help from it.
Can anyone help me out from this? It will be really appreciated!
Thanks.
The answer is simple.
lib/Cake/Controller/PaginatorComponent.php
if ($requestedPage > $page) {
throw new NotFoundException();
}
So just catch the error in your controller.
public function index() {
try {
$this->Paginator->paginate();
} catch (NotFoundException $e) {
//Do something here like redirecting to first or last page.
//$this->request->params['paging'] will give you required info.
}
}
This is why: http://book.cakephp.org/2.0/en/core-libraries/components/pagination.html#out-of-range-page-requests
I'm using the SalesForce PHP Toolkit and getting a connection just fine. But when I use any of the example code - see here
INVALID_FIELD: No such column '' on entity 'Contact'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names.
I might just be struggling to find the answer because Google won't let me search for ''
The environment is CentOS 6 with PHP 5.3.
I just created an account here to answer this question. It took me all day long to find out this bug in PHP Toolkit. The problem is caused by the "fieldsToNull" property. I read an approx. solution here that gave me an idea where to look for the solution.
So a correct example would be:
$fields = array('LastName' => 'Doe');
$sObject = new SObject();
$sObject->fields = $fields;
$sObject->fieldsToNull = NULL;//this is the solution! :)
$sObject->type = 'Contact';
Then, proceed as usual with the remaining part of the examples of the PHP Toolkit. It worked fine with my Partner WSDL+Developer SF Account.
Hope it helps!
I have a file (js.phtml) where my code executes. I need to access some user data. When I error_log($this) in js.phtml, it displays, "Mage_Core_Block_Template" - which is confusing to me. I would expect that to be the parent class, not the value of the class getting passed to my .phtml file.
So, how do I supply the .phtml file with custom objects or methods? I'm super new to Magento and I've just been dropped into a task, so I apologize for possibly using incorrect terminology.
Edit:
My full file path is:
/app/design/frontend//default/template/customer/welcome/js.phtml
There is also a full module dir here:
/app/code/local//Customer/
Edit:
I need access to the users country and userid. It's ok if country is null.
Edit:
I've been doing additional research, it looks like I can do something like this:
Current user in Magento?
But I haven't tried it in code yet ....
Edit: Figured it out:
error_log(print_r(Mage::getSingleton('customer/session')->getCustomer()->getEntityId(), true));
error_log(print_r(Mage::getSingleton('customer/session')->getCustomer()->getCountry(), true));
To get customer ID:
echo Mage::getSingleton('customer/session')->getCustomer()->getId();
To get country - depends from which address. Here's an example of getting the country code from the default billing address:
echo Mage::getSingleton('customer/session')->getCustomer()->getDefaultBillingAddress()->getCountry();
I am somewhat new to Magento, but I think this should work.
$customer = Mage::getSingleton('customer/session')->getCustomer();
That gets the customer object. Then...
echo $customer->getAddresses();
That should get the country somewhere in the address. As for userid...I don't see it on the documentation page..You could try
echo $customer->getAttributes();
And see what is in there. The documentation page is at:
http://docs.magentocommerce.com/Mage_Customer/Mage_Customer_Model_Customer.html