Shopware 6 API Bulk Update entity product and other issue single error dont update all - entity

Require a small help in API updating the products
https://shopware.stoplight.io/docs/admin-api/faf8f8e4e13a0-bulk-payloads#performance
We have products 1, 2, 3 .....upto 100 and we update quantity in BULK from our ERP (single operation)
Due to some reason (suppose) instead of integer we send string to 80th product --- so the API response gives error (which is ok)
But not only 80th product fails to update but the complete batch fails so 1 to 100 product fails - non of them are updated
Please help how to fix this or correct us if we are wrong??
Using the reference
https://shopware.stoplight.io/docs/admin-api/faf8f8e4e13a0-bulk-payloads#performance
- We are updating "entity": "product", and "action": "upsert" with headers
// --header 'single-operation: 1'
// --header 'indexing-behavior: use-queue-indexing'
All working very good but as we are using the entity in bulk if any one of the entity fails the complete bulk gives error and non of the product from the bulk list gets updated
If we are sending 1 to 100 products and problem is only at 80th product, only that does not get updated -- but rest 99 products should get updated

The behavior you describe is the expected behavior when you use single-operation: 1, as it is described in the reference you linked.
With single-operation: 1 all operations you sent are executed inside a single database transaction, so when one of the operations fails, the others are also rollbacked.
From what you describe you want to use single-operation: 0, which means that each operation you sent has it's own database transaction, so that when one operation fails the others still go through.

Reference URL
https://shopware.stoplight.io/docs/admin-api/faf8f8e4e13a0-bulk-payloads#examples
Update product stocks
{
"stock-updates": { // Name of the transaction, choose freely
"entity": "product", // Name of the entity you would like to update
"action": "upsert", // Available actions are upsert and delete,
"payload": [ // A list of objects, each representing a subset of the entity scheme referenced in `entity`. `id` is required for upsert operations.
{
"id": "c197170c60ab472b8dc1218acaba220e",
"stock": 41
},
{
"id": "a10c59fce8214fdaa552d74e0c6347ff",
"stock": 'XXXXX'
},
{
"id": "1b13176b6e0f4bb496c9a31b4fd7e97b",
"stock": 43
}
]
}
}
We have tried the following to update the stock -- but instead of integer sending string XXXXX for one product in the bulk, so that we can see the error for one product which does not update other products. (complete bulk not updated )
Below are the scenario 1 ( single-operation: 1 ) and scenario 2 ( single-operation: 0 ) in both our stock is not getting updated.
As both scenario are not updating the stock which we feel is wrong.
Our Problem
Single Operation: 0 (Separate transaction) - ideally should work and atleast update the stock of c197170c60ab472b8dc1218acaba220e to 41 and 1b13176b6e0f4bb496c9a31b4fd7e97b to 43 but the complete bulk is update is ignored by API.
==========
Scenario 1 = single-operation: 1
Response 1: Array
(
[error] => 1
[message] => Array
(
[errors] => Array
(
[0] => Array
(
[code] => ba785a8c-82cb-4283-967c-3cf342181b40
[status] => 400
[detail] => This value should be of type int.
[template] => This value should be of type {{ type }}.
[meta] => Array
(
[parameters] => Array
(
[{{ value }}] => "XXXXX"
[{{ type }}] => int
)
)
[source] => Array
(
[pointer] => /product/2/stock
)
)
)
)
)
==========
Scenario 2 = single-operation: 0
Response 2: Array
(
[error] => 1
[message] => Array
(
[success] =>
[data] => Array
(
[product] => Array
(
[result] => Array
(
[0] => Array
(
[entities] => Array
(
)
[errors] => Array
(
)
)
[1] => Array
(
[entities] => Array
(
)
[errors] => Array
(
[0] => Array
(
[code] => ba785a8c-82cb-4283-967c-3cf342181b40
[status] => 400
[detail] => This value should be of type int.
[template] => This value should be of type {{ type }}.
[meta] => Array
(
[parameters] => Array
(
[{{ value }}] => "XXXXX"
[{{ type }}] => int
)
)
[source] => Array
(
[pointer] => /2/stock
)
)
)
)
[2] => Array
(
[entities] => Array
(
)
)
)
[extensions] => Array
(
)
)
)
)
)

Related

Parsing nested JSON fields in Snowflake

I am pretty new to Snowflake and I am now trying to parse a JSON field and pull its attributes to return in the response.
I tried a few variations but every time, the attribute is populating as null.
attributes column in my table has this JSON:
{
"Status": [
"ACTIVE"
],
"Coverence": [
{
"Sub": [
{
"EndDate": [
"2020-06-22"
],
"Source": [
"Test"
],
"Id": [
"CovId1"
],
"Type": [
"CovType1"
],
"StartDate": [
"2019-06-22"
],
"Status": [
"ACTIVE"
]
}
]
}
]
}
What I tried:
SELECT DISTINCT *
from
(
TRIM(mt."attributes":Status, '[""]')::string as STATUS,
TRIM(r.value:"Sub"."Id", '[""]')::string as ID,
TRIM(r.value:"Sub"."Source", '[""]')::string as SOURCE
from "myTable" mt,
lateral flatten ( input => mt."attributes":"Coverence", outer => true) r
)
GROUP BY
STATUS,
ID,
SOURCE;
Later I tried:
SELECT DISTINCT *
from
(
TRIM(mt."attributes":Status, '[""]')::string as STATUS,
TRIM(r.value:"Id", '[""]')::string as ID,
TRIM(r.value:"Source", '[""]')::string as SOURCE
from "myTable" mt,
lateral flatten ( input => mt."attributes":"Coverence":"Sub", outer => true) r
)
GROUP BY
STATUS,
ID,
SOURCE;
But nothing worked. The STATUS is populating as expected. But ID and SOURCE are populating null.
Am I missing something or have I done something dumb? Please shed some light.
Assuming that Coverence could contain multiple Sub, therefore FLATTEN twice. At lowest level only first element is chosen (EndDate[0], Source[0] etc):
SELECT
mt."attributes":Status[0]::TEXT AS Status
,r2.value:EndDate[0]::TEXT AS EndDate
,r2.value:Source[0]::TEXT AS Source
,r2.value:Id[0]::TEXT AS Id
FROM myTable AS mt,
LATERAL FLATTEN(input => mt."attributes",
path => 'Coverence',
outer => true) r1,
LATERAL FLATTEN(input => r1.value,
path => 'Sub',
outer => true) r2;
Output:
All your elements are array type and the overall JSON is not making much sense... so to access all your individual elements, you have to use [] notation and then you can access the element values. You don't need to use flatten also, if you just have to access individual elements via index.

How to get a set of not null documents in FaunaDB

I am going along this official tutorial and I create a similar index.
Below is my code that calculate the difference of a start and an end, which end is nullable.
CreateIndex({
name: "foo_index",
source: {
collection: Collection("bar_collection"),
fields: {
interval: Query(
Lambda(
"bazDoc",
If(
Or(
IsNull(Select(["data", "start"], Var("bazDoc"), null)),
IsNull(Select(["data", "end"], Var("bazDoc"), null))
),
null,
Subtract(
Select(["data", "end"], Var("bazDoc")),
Select(["data", "start"], Var("bazDoc"))
)
)
)
)
}
},
values: [
{ binding: "interval"},
{ field: ["ref", "id"]}
]
})
This is the return, which I want to filter out all docs that the interval is null. How should I achieve this.
{
data: [
[9, "353542771515064533"],
[10, "353542807600758997"],
[null, "353542787197567188"],
[null, "353542814197350613"]
]
}
Btw, I'm new to FaunaDB, please suggest some resources to learn other than Fauna's own document.
The docs state
When a document is indexed, and all of the index’s defined values evaluate to null, no index entry is stored for the document.
Since you are also including the ref ID, which is never null, there will always be an index entry created.
However, you can add another binding that also returns null in case the interval is null or the Ref otherwise. This way, both values will be null, and no entry will be created.
CreateIndex({
name: "foo_index",
source: {
collection: Collection("bar_collection"),
fields: {
interval: Query(
Lambda(
"bazDoc",
If(
Or(
IsNull(Select(["data", "start"], Var("bazDoc"), null)),
IsNull(Select(["data", "end"], Var("bazDoc"), null))
),
null,
Subtract(
Select(["data", "end"], Var("bazDoc")),
Select(["data", "start"], Var("bazDoc"))
)
)
)
),
ref: Query(
Lambda(
"bazDoc",
If(
Or(
IsNull(Select(["data", "start"], Var("bazDoc"), null)),
IsNull(Select(["data", "end"], Var("bazDoc"), null))
),
null,
Select(["ref"], Var("bazDoc"))
)
)
)
}
},
values: [
{ binding: "interval" },
{ binding: "ref" }
]
})
I’ve included the whole Ref as the value here, which is what I recommend. It makes it easier to reuse in combination with other queries, and all the drivers let you use the Ref values in additional queries and get the ID like ref.id in your app where you need it.
please suggest some resources to learn other than Fauna's own document.
I hope that others can also pitch in here, too. I am on the Customer Support team at Fauna and want to highlight that we have discourse forums and a discord server. Myself and other Fauna employees make a best effort to see that every forums question is addressed in a reasonable time, either by the community, or by answering ourselves; and we’re active in discord, which is better for general discussions.

Cannot update document by index in FaunaDB

I'm attempting to update a document using an index in my FaunaDB collection using FQL.
Update(
Match(
Index('users_by_id'),
'user-1'
),
{
data: {
name: 'John'
}
}
)
This query gives me the following error:
Error: [
{
"position": [
"update"
],
"code": "invalid argument",
"description": "Ref expected, Set provided."
}
]
How can I update the document using the index users_by_id?
Match returns a set reference, not a document reference, because there could be zero or more matching documents.
If you are certain that there is a single document that matches, you can use Get. When you call Get with a set reference (instead of a document reference), the first item of the set is retrieved. Since Update requires a document reference, you can then use Select to retrieve the fetched document's reference.
For example:
Update(
Select(
"ref",
Get(Match(Index('users_by_id'), 'user-1'))
),
{
data: {
name: 'John'
}
}
)
If you have more than one match, you should use Paginate to "realize" the set into an array of matching documents, and then Map over the array to perform a bulk update:
Map(
Paginate(
Match(Index('users_by_id'), 'user-1')
),
Lambda(
"ref",
Update(
Var("ref"),
{
data: {
name: "John",
}
}
)
)
)
Note: For this to work, your index has to have an empty values definition, or it must explicitly define the ref field as the one and only value. If your index returns multiple fields, the Lambda function has to be updated to accept the same number of parameters as are defined in your index's values definition.

Oracle Reading from json respond

i have the next problem. Having this query:
select apex_web_service.make_rest_request(
p_url => 'https://something.com/rest/Discount'
,p_http_method => 'GET'
,p_username => 'username'
,p_password => 'password'
) as custom
from dual;
That return this:
{"hasMore":false,"items":[{"id":12,"Origin":"ALL","Part":"PO423S","Channel":"RC"},{"id":13,"Origin":"ALL","Part":"LO123D","Channel":"RC"},{"id":14,"Origin":"ALL","Part":"SD765S","Channel":"AP"}]}
I want to make a Channel group by to see how many Channels i have to insert into another table.
i try this just to list:
select d.custom.items
from (
select apex_web_service.make_rest_request(
p_url => 'https://something.com/rest/Discount'
,p_http_method => 'GET'
,p_username => 'username'
,p_password => 'password'
) as custom
from dual) d;
but i have this error:
ORA-22806: no es un objeto ni un elemento REF
22806. 00000 - "not an object or REF"
*Cause: An attempt was made to extract an attribute from an item that is
neither an object nor a REF.
*Action: Use an object type or REF type item and retry the operation.
Error en la línea: 12, columna: 8
I also test the next:
create table temp_json (
json_data blob not null
);
alter table temp_json
add constraint temp_data_json
check ( json_data is json );
insert into temp_json
select apex_web_service.make_rest_request(
p_url => 'https://something.com/rest/Discount'
,p_http_method => 'GET'
,p_username => 'username'
,p_password => 'password
) as customDiscAplicability
from dual
;
select d.json_data.items
from temp_json d;
And teh result is this:
ITEMS
-----
(null)
I follow this tutorial: LINK
Can somebody help me ?
Regards
When you select apex_web_service.make_rest_request, it returns a string. The database doesn't know this is JSON data.
If you're on Oracle Database 18c or higher, you should be able to get around this by using treat ... as json:
select d.custom.items.id from (
select treat ( '{
"hasMore": false,
"items": [ {
"id": 12,
"Origin": "ALL",
"Part": "PO423S",
"Channel": "RC"
}, {
"id": 13,
"Origin": "ALL",
"Part": "LO123D",
"Channel": "RC"
}, {
"id": 14,
"Origin": "ALL",
"Part": "SD765S",
"Channel": "AP"
}
]
}' as json ) custom from dual
) d;
ITEMS
[12,13,14]
To understand why inserting the response into the table, then selecting it returns null, we'd need to see the exact JSON that's in there!

Creating Customer on Balanced Payments

I am confused by the Balanced Payment documentation, specifically for creating customers:
The Balanced docs say to create a customer with this code:
$marketplace = Balanced\Marketplace::mine();
$customer = $marketplace->customers->create(array(
'address' => array(
'postal_code' => '48120',
),
'dob_month' => '7',
'dob_year' => '1963',
'name' => 'Henry Ford',
));
The goal is to get a json response:
{
"customers": [
{
"address": {
"postal_code": "48120",
//more key -> value pairs
},
//more key -> value pairs
"href": "/customers/CU3SSJgvA5Z69kt05MusbPeE",
}
The problem that I am having is that I cannot find any reference as to how to send the info to Balanced. Do I use balanced.js to tokenize it the same way I tokenize a credit card?
Take a look at https://docs.balancedpayments.com/1.1/api/customers/#create-a-customer . You would use one of the clients, such as the Python or PHP clients found at https://docs.balancedpayments.com/1.1/overview/getting-started/#client-libraries .
Balanced.js is just for card tokenizations to aid with PCI-compliance -- using it, sensitive card information is posted directly to Balanced and never has to touch your own servers.