I am looking to update the custom fields on a product.
I found in the guide on how to do it manually via the admin interface
The API docs suggest that you can't directly modify the custom fields on a product, only access them:
My next thought was to update the product
This is the existing custom_field on the product.
{
"url"=> "https://storename.mybigcommerce.com/api/v2/products/32/customfields.json",
"resource"=>"/products/32/customfields"
}
When I try to modify the url/resource and send the hash back to update, I am greeted with a 400 Bad Request :(
new_custom_fields = {
"url" => "https://storename.mybigcommerce.com/api/v2/products/75/customfields.json",
"resource" => "/products/75/customfields"
}
api.update_products(75, {"custom_fields" => new_custom_fields})
RuntimeError: Failed to parse Bigcommerce response: 400 Bad Request
Thoughts?
this seems to be a bug in the Bigcommerce APIs. Currently only GET requests on the custom fields are supported.
http://developer.bigcommerce.com/api/products/customfields
That is probably the reason why you are hitting a 400.
Not sure if this will help with Ruby, but it might help those using PHP... I'm able to create a custom field on a product using php. Just need the product id and the values for the custom field, "name" and "text".
$data_array = array('name' => 'gender', 'text' => 'male');
BigCommerce::createProductCustomField('17', $data_array);
I haven't tried updating a custom field, but if creating one works, then the following should also work to update a current custom field:
BigCommerce::updateProductCustomField($product_id, $id, $object);
You'll need the $product_id of the product you want to update, the $id of the custom field that you want to update, and $object should be an array like $data_array above.
More info on PHP client for BC: https://github.com/bigcommerce/bigcommerce-api-php
Good luck!
Try this Code :
$headers = array(
"Content-type: application/json",
//"Authorization: Basic " . base64_encode($credentials)
);
$name='Bullet Point ';
$data_array = array('name'=>'Bullet Point','text'=>'Bullet Point value');
$body=json_encode($data_array);
//Get the current url and split it at the '?'
$ch = curl_init('https://www.abc.mybigcommerce.com/api/v2/products/1122/customfields.json'); //open connection
curl_setopt($ch, CURLOPT_TIMEOUT, 60); //set to 60 seconds from BC API Guide v1 PDF example
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); //load all header data
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); //comment out this PUT line to change to a POST statement
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, 0 );
curl_setopt( $ch, CURLOPT_USERPWD, "admin:api-key");
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, 0 );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
$result = curl_exec($ch); //execute post
curl_close($ch);
Related
Dear stackoverflow community,
Recently PayPal contacted me to upgrade my 'old-style' CodeIgniter e-commerce cart (an old standard paypal gateway with a simple form to related paypal endpoint) to a solution with access token and client_id + secret. I used omnipay-paypal, following a guide like this:
https://artisansweb.net/paypal-payment-gateway-integration-in-php-using-paypal-rest-api/
And everything seems working fine, but with old standard cart I used a notifyUrl to send payment post data to a controller that made something like this:
foreach ($_POST as $key => $value) {
$request .= '&' . $key . '=' . urlencode(html_entity_decode($value, ENT_QUOTES, 'UTF-8'));
}
$curl = curl_init('https://www.paypal.com/cgi-bin/webscr');
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $request);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_TIMEOUT, 120);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($curl);
If that $response is VERIFIED, I enable related order for delivery (paid).
Issue is that notifyUrl isn't triggered at all with Omnipay and this avoids to fit the shoe.
I tried to setup notifyUrl parameter on purchase, completePurchase method, but nothing to do: no call is sent after payment confirmation and no payment data in the related $_POST object.
Someone could give me some hint or help?
I tried to force the notifyUrl in any possible way, but after transaction is complete and payment confirmed, the notifyUrl is not receiving the expected data with post.
I have a list of custom fields for a Deals in Pipedrive. (Located here https://your-instance.pipedrive.com/settings/fields?type=DEAL)
Each custom field has a custom API Key which looks like this a56aff894af47285d3bbcd67fe06ee5143fb1123
I try to update these fields in a Deal in bulk.
According to the Update a deal documentation https://developers.pipedrive.com/docs/api/v1/#!/Deals/put_deals_id there is no information about these custom fields.
The question is how to update custom field value in a certain Deal?
To achieve this you can send custom field key - value pairs just in the request body.
According to this example:
// Pipedrive API token
$api_token = '659c9fddb16335e48cc67114694b52074e812';
// Custom field key value pairs
$data = array(
'dcf558aac1ae4e8c4f849ba5e668430d8df9be12' => 'Custom field value'
);
// Deal ID
$deal_id = 260;
// URL for updating a Deal
$url = 'https://your-instance.pipedrive.com/api/v1/deals/' . $deal_id . '?api_token=' . $api_token;
// Prepare CURL Request
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
$output = curl_exec($ch);
curl_close($ch);
Can i use the first script or i need to use the curl option for mailchimp 3.0? I read some posts that the first one may be depreciated.. is that correct? Note that i'm not running on WordPress. Thank you for your fast answers.
<?php
require("vendor/autoload.php");
use \DrewM\MailChimp\MailChimp;
$mc = new MailChimp('apikey');
$email = $_POST['email'];
$subscriber_hash = $mc->subscriberHash($email);
$response = [];
$list_id = 'listid';
$resp = $mc->get("/lists/$list_id/members/$subscriber_hash";
if ($mc->success()) {
$response['message'] = 'Thank you for subscribing to the mailing list';
// User successfully subscribed - set HTTP status code to 200
http_response_code(200);
} else {
$response['message'] = $mc->getLastError();
// User not subscribed - set HTTP status code to 400
http_response_code(400);
}
// Return json-formatted response
echo json_encode($response);
?>
Or should i use this one?
function mc_checklist($email, $debug, $apikey, $listid, $server) {
$userid = md5($email);
$auth = base64_encode( 'user:'. $apikey );
$data = array(
'apikey' => $apikey,
'email_address' => $email
);
$json_data = json_encode($data);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://'.$server.'.api.mailchimp.com/3.0/lists/'.$listid.'/members/' . $userid);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json',
'Authorization: Basic '. $auth));
curl_setopt($ch, CURLOPT_USERAGENT, 'PHP-MCAPI/2.0');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json_data);
$result = curl_exec($ch);
if ($debug) {
var_dump($result);
}
$json = json_decode($result);
echo $json->{'status'};
}
This row is only for stackoverflow not alowing me to post that much code without including more details.
The first is not deprecated. It uses this wrapper to make API calls using the same API version that the second block of code uses. It's just simpler to work with so you don't have to write separate CURL requests for every call. You can also take a look at some of its source code and notice that it uses CURL anyway to make its calls.
So either way will use CURL, and whichever option you choose is simply a matter of preference.
Hopefully that clears it up for you!
If I have api key of Business API, i just want example of URL, like how to put the place id and api key.
If Google have authorized you to use Google Business API then you need to
Authenticate the user via OAuth.
After authentication which will give you the token, API will return you the users's account.
Now to get the reviews you have to make Http Get request to the endpoint below
https://mybusiness.googleapis.com/v4/accounts/{accountId}/locations/{locationid}/reviews
Your Http Get request must have Access Token
For Example: https://mybusiness.googleapis.com/.../reviews??access_token={tokenHere}
this will return you all the reviews.
Ref: https://developers.google.com/my-business/reference/rest/v4/accounts.locations.reviews
Hope that answered your Question.
*Please note, support of v3 of the API ended on March 10, 2018; v3 will no longer be available on May 10th 2018. So we encourage you to migrate to v4.1 as soon as possible to prevent any interruption in functionality. In addition, the deprecation schedule can be found here
You can get Google My business (GMB) reviews in same ways
Please find the below working code for review reply with PHP HTTP request
$access_token = "<your_access_token_here>";
$query = array('comment' => 'Thank you for visiting our business!');
$request_uri = "https://mybusiness.googleapis.com/v4/accounts/111050869667910417441/locations/17405754705905257334/reviews/AIe9_BFu3rdicGrPrzdyu4PDXmqMAu-9BCJf9_HF0DxzGxsjAGw5KGl1XsdqSkbsAMdl_W2XBG4bwO3wCp0_l_8KLAV7mckl5cSyJItwPqSYGiH3ktK6nrI/reply?access_token=" . $access_token;
$curinit = curl_init($request_uri);
curl_setopt($curinit, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curinit, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($curinit, CURLOPT_POSTFIELDS, json_encode($query));
curl_setopt($curinit, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curinit, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen(json_encode($query)))
);
$json = curl_exec($curinit);
$phpObj = json_decode($json, true);
var_dump($phpObj);
This code worked for me. I used the curl library to answer a review. I hope it serves you
$url = "https://mybusiness.googleapis.com/v4/accounts/{accountId}/locations/{locationId}/reviews/{reviewId}/reply";
$access_token = {access token google}
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$query = array('comment' => 'Thank You!');
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query));
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Authorization: Bearer '.$access_token.'',
'Content-Type: application/json',
'Content-Length: ' . strlen(json_encode($query)))
);
$response = curl_exec($ch);
echo $response;
curl_close($ch);
The following code is working and subscribing new members successfully. However, the status returns 200 even if the email address is already subscribed. I have checked that $member_id is hashing correctly, and despite identical values it still returns 200.
$result = array(
'status' => sync_mailchimp($data)
);
var_dump($result) // 200
function sync_mailchimp($data) {
// Setup our Mailchimp info
$api_key = 'xxxxx';
$list_id = 'ab8abde5bb';
$member_id = md5(strtolower($data['email'])); // lowercase hash of the email
$datacenter = 'us16';
$url = 'https://' . $datacenter . '.api.mailchimp.com/3.0/lists/' . $list_id . '/members/' . $member_id;
$json = json_encode([
'email_address' => $data['email'],
'status' => $data['status']
]);
// Send via curl
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_USERPWD, 'user:' . $api_key);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
$result = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
return $httpcode;
}
I was also having the same issue while using a similar snippet.
Reading the MailChimp API 3.0 docs relating to managing subscribers (specifically the section Subscribe an Address), it was clear that this method was not the correct way to add a new subscriber.
The request type needs to be a POST
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
and must be sent to the endpoint
https://<data_center>.api.mailchimp.com/3.0/lists/<list_id>/members/
The request body containing the JSON is identical.
The response code will be 200 when an email address is added to the list successfully, and 400 when the email address already exists on the list.
Note that this method will not work for updating an existing subscriber – to do that, the request type must be PATCH, and you must use the original endpoint ending with the hashed email address.