I'm using Laravel to consume the Bigcommerce V3 API.
I have ben able to succesfully create a new cart. But when trying to add an item to it, I keep getting a 422: Missing required fields error.
I'm making my request trough Guzzle like this:
return json_decode($this->client->getRestClient()
->post('carts/'.$cartId.'/items?include=line_items.physical_items.options', [
'Accept' => 'application/json',
'json' => [
'line_items' => [
'product_id' => 86,
'quantity' => 1
],
],
])
->getBody())
->data;
The product I'm trying to add has no options or modifiers, so I don't understand what could wrong with my request. According to the docs, this should be all that's needed.
Does anyone have any idea what could be wrong? I tried contacting support, but to no avail.
Thanks in advance!
line_items is an array of objects. Try wrapping your product data in an object.
Like this:
'line_items' => [
{
'quantity' => 1,
'product_id' => 86
}
]
Your line_items field needs to have an array of objects, like this:
[
{
"product_id":86,
"quantity":1
}
]
Related
I am using REST API using PHP for fetching data from Elastic search with following code
$params = [
'index' => $search_index,
'type' => $search_type,
'from' => $_POST["from"],
'size' => $_POST["fetch"],
'body' => [
'query' => [
'bool' => [
'must' => [
[ 'match' => [ 'is_validated' => false ] ],
[ 'query_string' => [ 'query' => $search_str, 'default_operator' => 'OR' ] ]
]
]
]
]
];
Now, this is working perfectly and giving me my desired results.
The data that is returned from ES, has one column "result_source" and it has predefined values like CNN, BBC or YouTube etc.
What I need is, I want to filter results on "result_source" column in a way that, I can only fetch the results with the option I want. Like I want results that have "result_source" value only "YouTube" or only "BBC & CNN" or only "CNN or YouTube" etc.
I have already tried "Should" option, but it also returns the data with other values that I don't need. Not sure how to skip those values of "result_source" column in fetching results from ES.
Any help on this will be appreciated.
Thanks
Solved!!
I am replying to my own question, because I found a solution for it. May be it can help someone else in future.
If anyone is looking for a solution of searching within the field / column of Elastic search, here is what can be done.
[ 'query_string' => [ 'query' => $search_str.'(result_source:CNN OR result_source:BBC)', 'default_operator' => 'OR' ] ]
"result_source" is actually the field / column name of ES on which filter is applied to return results that have result_source=BBC or result_source=CNN.
This actually solved my issue.
I am working on Elasticsearch (ES) for last couple of weeks. There are millions of records currently present in different search indices in ES.
I have noticed that in different search indices, there is duplication of records and it is creating problem.
We can search for duplicate records via code and remove those records. May be this can be applicable, but I have more than 100 million records so it will take lot of time.
My requirement is, while we fetch records from ES, we can apply different filters. Is there any filter or way we can only fetch distinct records? I am currently using REST API using PHP.
Here is the code that I am currently using and filters are working perfectly.
$params = [
'index' => 'MyIndex',
'type' => 'MyType',
'from' => 0,
'size' => 10,
'body' => [
'query' => [
'bool' => [
'must' => [
[ 'match' => [ 'image' => true ] ],
[ 'simple_query_string' => [ 'query' => 'MyQuery' ] ]
]
]
]
]
];
I also tried looking something from "Aggregations", but couldn't find something related to my requirement.
Quick help will be highly appreciated.
Thanks in advance.
I think what you are looking for is "collapsing".
Elasticsearch supports it from 6.x:
https://www.elastic.co/guide/en/elasticsearch/reference/6.x/search-request-collapse.html
I am using elasticsearch 6.2 with elasticsearch-php 6.0 client. There is situation i got stuck. I need to update field userid = 987 where userid = 123. I went through update API, Here in every query we need to pass document ID in API (like POST test/_doc/1/_update). First i need to fetch _id and then i have to make update query with POST test/_doc/{_id}/_update
It won't possible to every time produce _id. It didn't help me.
I found another option to use _update_by_query. In which i got success by using following API:
curl -XPOST 'localhost:9200/my_index/my_type/_update_by_query?pretty' -H 'Content-Type: application/json' -d '
{
"query":{
"term":{
"userid":123
}
},
"script":{
"lang":"painless",
"inline":"ctx._source.userid = params.value",
"params":{
"value":987
}
}
}'
I am not finding any reference which shows how i can use _update_by_query with elasticserach-php client. Plus let me know if you guyz have better way to tackle this. Thanks!
I got solution So i would like to share:
$client = \Elasticsearch\ClientBuilder::create()->setHosts(['127.0.0.1:9200'])->build();
$update = [
'index' => 'my_index',
'type' => 'my_type',
'conflicts' => 'proceed',
'body' => [
'query' => [
'term' => [
"userid" => 987
]
],
'script' => [
'lang' => 'painless',
'inline' => 'ctx._source.userid = params.userid',
'params' => [
'userid' => 123
]
]
]
];
$results = $client->updateByQuery($update);
It solve my problem. I think elasticserach should document this.
I'm using Stripe for my recurring payment for my SAAS.
The problem I'm facing today is : I would like to offer to my client the choice to upgrade or downgrade their subscription to my service.
So the code I have actually is the following (according to the doc here):
\Stripe\Subscription::update($subscriptionID, [
'items' => [
'id' => $itemID,
'plan' => $planId
]
]);
The $subscriptionID, $itemID and $planId return my the right value I need but no update on the Stripe side.
I have just this error:
{
"error": {
"type": "invalid_request_error",
"message": "Invalid array",
"param": "items"
}
}
Any help on his please ?
Thanks.
You just need to cover items in one more array level, like so:
\Stripe\Subscription::update($subscriptionID, [
'items' => [
[
'id' => $itemID,
'plan' => $planId
]
]
]);
It was working using this code:
$customer = \Stripe\Customer::retrieve($CustomerId);
$subscription = $customer->subscriptions->retrieve($subscriptionID);
$customer->updateSubscription(['plan' => $planId]);
$customer->save();
Strange that the Stripe API do not talk about this solution.
I am trying to override the discount amount i have created from Braintree control panel by calling the function below.
$result = Braintree_Subscription::create([
'paymentMethodToken' => 'the_payment_method_token',
'planId' => 'the_plan_id',
'addOns' => [
'add' => [
[
'inheritedFromId' => 'abcd',
'amount' => 20.00
]
]
]
]);
But it is returning me this error
NotFound in Util.php line 64:; Util::throwStatusCodeException('404') in Http.php line 47 Appreciate any help. Thanks!
Full disclosure: I work at Braintree. If you have any further questions, feel free to contact support.
The 404 error you're seeing is likely being thrown due to one or more ID's specified in your API call not matching what you have in your control panel. The two ID's from your example code are the following:
A Plan with the ID the_plan_id
An add-on with the ID abcd
You'll want to ensure that you have a plan and add-on with those ID's in your control panel before using them in an API call. Since there isn't a way to generate plans or ID's from the API, you can follow the guide below on how to make them.
Making a Plan
The other potential issue here is that in your question, you mentioned you wanted to use a discount, where in your code, you're specifying an add-on. This might itself be the source of the problem. I would change these lines:
'addOns' => [
'add' => [
[
'inheritedFromId' => 'abcd',
'amount' => 20.00
]
]
to
'discounts' => [
'add' => [
[
'inheritedFromId' => 'abcd',
'amount' => 20.00
]
]