I am trying to use the Magento API to UPDATE a product. I am getting error code #1 with the following message:<b>Fatal error</b>: Uncaught SoapFault exception: [1] Internal Error. Please see log for details.
Below is my PHP that calls the service and should update three attributes. The Magento api documentation leaves a lot to the imagination so I am stuck
$ItemNmbr = $itemData->Item->ItemNmbr;
$ItemDesc = $itemData->Item->ItemDesc;
$UnitPrce = $itemData->Item->UnitPrce;
$client = new SoapClient('http://website.com/store/api/?wsdl');
$session = $client->login('apiname', 'apipassword');
$result = $client->call($session, 'catalog_product.update', array(168, array(
'description' => $ItemDesc,
'price' => $UnitPrce,
'weight' => $Weight
)));
var_dump ($result);
I am statically setting the ProductID above for now. Any information that will help me understand what I am doing wrong would be much appreciated.
Related
I am using PHP and have a webhook generated with invoice.created. When the invoice is created, Stripe lets the draft invoice sit there for about an hour which gives us time to edit the invoice or adjust it. I use this time to check the database (via webhook) to see how many referrals this person has in the system to the adjust the coupons accordingly. I can't seem to adjust the invoice properly as I get errors in all the ways I have tried, which are:
$inv = {the invoice id and I get no error from the invoice ID being incorrect
define('STRIPE_API_KEY', 'sk_test_******************');
$stripe = new \Stripe\StripeClient(
STRIPE_API_KEY
);
$stripe->invoices->update(
$inv,
['discounts.coupon' => '20OFF']
);
Error is unknown object discounts.coupon
and
$stripe->invoices->update(
$inv,
['discount' => '20OFF']
);
Error = Fatal error: Uncaught (Status 400) (Request req_hsX1QTOxzWMiQn) Received unknown parameter: discount. Did you mean discounts? thrown in /home/searchoscn/public_html/vendor/stripe/stripe-php/lib/Exception/ApiErrorException.php on line 38
and
$stripe->invoices->update(
$inv,
['coupon' => '20OFF']
);
ERROR = Fatal error: Uncaught (Status 400) (Request req_yEwwOLoukR6j6Z) Received unknown parameter: coupon thrown in /home/searchoscn/public_html/vendor/stripe/stripe-php/lib/Exception/ApiErrorException.php on line 38
$stripe->invoices->update(
$inv,
['discounts' => ['coupon' => '20OFF']]
);
Fatal error: Uncaught (Status 400) (Request req_IDRP1Rjv1YoBZR) Invalid array thrown in /home/searchoscn/public_html/vendor/stripe/stripe-php/lib/Exception/ApiErrorException.php on line 38
I'm pretty sure I need to use 'discounts' but don't know how to structure the array to pass the coupon properly.
Trying to predict some questions or comments:
Yes, I do have an existing coupon with id of 20OFF. This is for 20% off
$inv does fetch the correct ID of the invoice at the time the webhook is sent.
Here is the link of the API documentation that I've been reading, but it isn't very helpful.
Instead of:
$stripe->invoices->update(
$inv,
['discounts.coupon' => '20OFF']
);
try:
$stripe->invoices->update(
$inv,
['discounts' => ['coupon' => $couponId]]
);
It looks like it must be the id of the coupon and not the customer facing code, e.g. 20OFF.
You would be able to get the id of the coupon from the dashboard (https://dashboard.stripe.com/coupons/) or by making another api request.
It's
$stripe->invoices->update(
$inv,
[
'discounts' => [
['coupon' => '20OFF']
]
]
);
As in, it's an array that then contains objects (in PHP those are both square brackets) and the objects refer to the coupon.
I'm trying out the ActiveCollab API for my first time. I had to use StackOveflow to figure out how to get the API token since the docs don't tell me this.
Below is my code:
/* GET INTENT */
$url = 'https://my.activecollab.com/api/v1/external/login';
$fields = array(
'email' => "email#email.com",
'password' => "****"
);
$intent = curl_post_connector($url, $fields);
$intent = $intent->user->intent;
/* GET TOKEN */
$url = 'https://app.activecollab.com/my_app_id/api/v1/issue-token-intent';
$fields = array(
'intent' => $intent,
'client_name' => 'My App Name',
'client_vendor' => 'My Company Name'
);
$token = curl_post_connector($url, $fields);
$token = $token->token;
Everything above works and get's the token properly. What I find really weird is that I have to use API v1 to get this, and the docs on ActiveCollab's site don't mention any URL for API v5. It seems like this is the approach everything is taking here on StackOverflow.
Now with the token, I try to get my list of projects:
/* GET PROJECT */
$url = 'https://app.activecollab.com/my_app_id/api/v1/users';
$headers = array (
"X-Angie-AuthApiToken" => $token
);
$projects = curl_get_connector($url, $headers);
var_dump($projects);
But this does not work. There is no error returned - it instead returns an array of languages for some reason! I don't want to paste the massive json object here, so instead I'll link you to a photo of it: https://www.screencast.com/t/7p5JuFB4Gu
UPDATE:
When attempting to use the SDK, it works up until I try getting the token (which is just as far as I got without the SDK). I'm getting Server Error 500, and when looking at the logs, it says:
/home/working/public_html/ac/index.php(21): ActiveCollab\SDK\Authenticator\Cloud->issueToken(123456789)
#1 {main}
thrown in /home/working/public_html/ac/SDK/Authenticator/Cloud.php on line 115
This is line 115 of Cloud.php:
throw new InvalidArgumentException("Account #{$account_id} not loaded");
I honestly don't think I did anything wrong... there must be something wrong with my account ID.
Just for kicks, I commented out that line, and the error disappears and the page loads fine - except now I have no token...
While using Google Cloud Compute's API in PHP, I am able to start, stop, delete instances as well as create and delete disks.
However, when trying to create an Instance, I keep getting this error
Invalid value for field 'resource.disks'
PHP Fatal error: Uncaught exception 'Google_Service_Exception' with message 'Error calling POST https://www.googleapis.com/compute/v1/projects/project/zones/zone/instances: (400) Invalid value for field 'resource.disks': ''. Boot disk must be specified.' in /var/www/html/google/google-api-php-client/src/Google/Http/REST
Here is the request I am making
self::connectClient();
$computeService = new Google_Service_Compute($this->client);
if ($this->client->getAccessToken())
{
$googleNetworkInterfaceObj = new Google_Service_Compute_NetworkInterface();
$network = self::DEFAULT_NETWORK;
$googleNetworkInterfaceObj->setNetwork($network);
$diskObj = self::getDisk($instance_name);
$new_instance = new Google_Service_Compute_Instance();
$new_instance->setName($instance_name);
$new_instance->setMachineType(self::DEFAULT_MACHINE_TYPE);
$new_instance->setNetworkInterfaces(array($googleNetworkInterfaceObj));
$new_instance->setDisks(array(
"source"=>$diskObj->selfLink,
"boot"=>true,
"type"=>"PERSISTENT",
"deviceName"=>$diskObj->name,
));
$insertInstance = $computeService->instances->insert(self::DEFAULT_PROJECT,self::DEFAULT_ZONE_NAME, $new_instance);
Any help will be highly appreciated, thank you.
Ok the solution was really simple (and silly)
Instead of
$new_instance->setDisks(array(
"source"=>$diskObj->selfLink,
"boot"=>true,
"type"=>"PERSISTENT",
"deviceName"=>$diskObj->name,
));
It's supposed to be
$new_instance->setDisks(array(
array(
'source'=>self::getDisk($instance_name)->selfLink,
'boot'=>true,
'type' => "PERSISTENT",
'deviceName'=>self::getDisk($instance_name)->name,
)
));
Hey can anyone explain to me why I get this error when I try to save the registration form.
Fatal error: Cannot unset string offsets in /home/wolf/public_html/wp-content/plugins/userpro/admin/admin-functions.php on line 252
Here is the line in question for the php.
/** List all groups **/
function userpro_admin_list_groups(){
global $userpro;
$output = null;
$groups = $userpro->groups;
unset($groups['register']);
unset($groups['edit']);
unset($groups['view']);
unset($groups['login']);
unset($groups['social']);
$array = array(
'register' => __('Registration Fields','userpro'),
'edit' => __('Edit Profile Fields','userpro'),
'login' => __('Login Fields','userpro'),
'social' => __('Social Fields','userpro')
);
IF anyone can shed some liht on this that would be great as far as i see theres nothing written wrong, and even the plugin maker is scrating his head on this....
the config for the php is 5.4
And the Apache is 2.4
Mysql is running 5.6
I am having a tough time and have spent like 4 hrs trying to debug this. I am new to PHP, but did not expect this to be so hard.
This is the code, i am trying to update a contact table. i tried upsert and update nothign seems to work
this is the update" version of the code.
$id = '003A000000XRVFxIAP';
$updateFields = array (
'Id' => $id,
'MailingCity' => 'New York',
'MailingState' => 'NY'
);
$sObject1 = new SObject();
//$sObject1->fields = $updateFields;
//$sObject1->MailingCity= 'New York';
$sObject1->type = 'Contact';
try{
$updateResponse = $client->update(array($sObject1),'Contact');
$myID = $updateResponse->id;
}
Strict Standards: Creating default object from empty value in C:\xampp\htdocs\Proj1\ForceToolkit\soapclient\SforceEnterpriseClient.php on line 89 INVALID_FIELD: No such column 'fields' 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. Error Info SoapFault exception: [sf:INVALID_FIELD] INVALID_FIELD: No such column 'fields' 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. in C:\xampp\htdocs\Proj1\ForceToolkit\soapclient\SforceBaseClient.php:508 Stack trace: #0 C:\xampp\htdocs\Proj1\ForceToolkit\soapclient\SforceBaseClient.php(508): SoapClient->__call('update', Array) #1 C:\xampp\htdocs\Proj1\ForceToolkit\soapclient\SforceBaseClient.php(508): SoapClient->update(Object(stdClass))
#2 C:\xampp\htdocs\Proj1\ForceToolkit\soapclient\SforceEnterpriseClient.php(90): SforceBaseClient->_update(Object(stdClass))
#3 C:\xampp\htdocs\Proj1\createAccount.php(95): SforceEnterpriseClient->update(Array, 'Contact') #4 {main}
Looking at your trace you appear to be using the enterprise client and I can assume enterprise WSDL. This is strongly typed and you should be using the WSDL specific to your Salesforce org. If you are not using the WSDL downloaded from your org it will not have the correct objects and fields defined within it.
I would recommend using the partner client and partner WSDL. This is loosely typed and far more flexible. It would be easier to work with particularly if you aren't familiar with the PHP or the webservices.
The following should do your update...
$sObject1 = new stdClass();
$sObject1->type = 'Contact';
$sObject1->Id = $id;
$sObject1->fields['MailingCity'] = 'New York';
$sObject1->fields['MailingState'] = 'NY';
try
{
$updateResponse = $client->update( array( $sObject1 ) );
}
catch( Exception $exception )
{
// Do something
}
Note that the Id is a property of $sObject and not a value in the fields array. Also there is no need to specify the 'Contact' in your update call as you have it set in the type property of $sObject.
When using the Enterprise WSDL, don't create a new SObject, just create a new stdClass. See the examples in the PHP Getting Started Guide; SObjects are only for use with the partner WSDL.
I have encountered the same issue updating while using the Enterprise client. I experienced the same issue while updating a custom field on an Account object.
The issue that I had with the SObject was that it tried to update a parameter called 'fields' during the update. With the Enterprise WSDL not including that field, I used unset() to remove the 'fields' attribute from the SObject.
I appreciate this is a bit of a hacky solution, but it could come in useful for others that encounter this issue.
$sUpdateObject = new SObject();
$sUpdateObject->id = $record->Id;
$sUpdateObject->MyCustomField__c = 0;
unset($sUpdateObject->fields);
$updateResponse = $mySforceConnection->update(array($sUpdateObject), 'Account');
print_r($upsertResponse);