Shopware 6 custom entity fields are not updated via admin api - shopware6

i have a custom entity defined in entities.xml:
<?xml version="1.0" encoding="utf-8" ?>
<entities xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/shopware/platform/trunk/src/Core/System/CustomEntity/Xml/entity-1.0.xsd">
<entity name="custom_entity_search">
<fields>
<string name="media_hash" store-api-aware="true" />
<json name="data" store-api-aware="true" />
</fields>
</entity>
</entities>
when i use the admin api to insert a new custom entity i don't get all my fields updated.
request url:
http://localhost/api/custom-entity-search
request body:
{
"name": "custom-entity-search",
"fields": {
"media_hash": "123hashmedia",
"data": {"test": "1234"}
}
}
The entity is created but fields "media_hash" and "data" remain null.
How can i update those fields ?

You need to pass the fields directly in the payload there is no need to specify the entity name in the payload itself, the mapping to the concrete custom entity is done over the REST-API endpoint api/custom-entity-search
so the request body should look like this:
{
"media_hash": "123hashmedia",
"data": {"test": "1234"}
}
Edit (to many relations)
{
"media_hash": "123hashmedia",
"data": {"test": "1234"},
"customer_to_many_field": [
{
"id": "my first customer id",
"firstName": "The new name",
},
{
... // data for second customer if needed
}
]
}

Related

how to remove the xmlns attribute that gets added after my transformation?

I'm facing an issue when I transform a json input to an xml output. After transformation i want to remove the xmlns namespace before closing tag. These Namespace (xmlns:ind="." and xmlns:att="d") need to be removed
sample input:
{
"order": "Electronic",
"productId": 6548790,
"status": "COMPLETED",
"recieved": "YES",
"orderId": "12453",
"desc": "NASQ123",
"details": [{
"attributes": [{
"linetype": "DFU"
}]
}]
}
I'm using this below dataweave script:
%dw 2.0
output application/xml writeDeclaration=false
ns soapenv http://schemas.xmlsoap.org/soap/envelope/
ns ind .
ns att d
---
{
soapenv#Envelope:{
soapenv#Header: {},
soapenv#Body: {
ind#updateorder: {
ind#orderId: payload.orderId,
ind#orderName: payload.order,
ind#quantity: "5",
ind#order: {
att#productId: payload.productId,
att#desc: payload.desc,
att#shipping: "MAIL",
att#status: payload.status,
att#type1: payload.order,
att#recieved: payload.recieved,
att#otherDetails: payload. *details map ()-> {
att#details1: $.attributeS.linetype,
},
}
}
}
}
}
Current Ouput:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
<soapenv:Body>
<ind:updateorder xmlns:ind=".">
<ind:orderId>12453</ind:orderId>
<ind:orderName>Electronic</ind:orderName>
<ind:quantity>5</ind:quantity>
<ind:order>
<att:productId xmlns:att="d">6548790</att:productId>
<att:desc xmlns:att="d">NASQ123</att:desc>
<att:shipping xmlns:att="d">MAIL</att:shipping>
<att:status xmlns:att="d">COMPLETED</att:status>
<att:type1 xmlns:att="d">Electronic</att:type1>
<att:recieved xmlns:att="d">YES</att:recieved>
<att:otherDetails xmlns:att="d">
<att:details1/>
</att:otherDetails>
</ind:order>
</ind:updateorder>
</soapenv:Body>
</soapenv:Envelope>
However, This is my expected Output After Transformation is done:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
<soapenv:Body>
<typ:updateorder>
<ind:orderId>12453</typ:orderId>
<ind:orderName>Electronic</typ:orderName>
<ind:quantity>5</typ:quantity>
<ind:order>
<att:productId>6548790</pur:productId>
<att:desc>NASQ123</pur:desc>
<att:shipping>MAIL</pur:shipping>
<att:status>COMPLETED</pur:status>
<att:type1>NA</pur:type1>
<att:recieved>YES</pur:recieved>
<att:otherDetails>
<pur:details1/>
</pur:otherDetails>
</typ:order>
</typ:updateorder>
</soapenv:Body>
</soapenv:Envelope>
What you are trying to get is not a valid XML. Because all name spaces used in an XML needs to be declared within the XML. While writing dataweave, when you add an element like ind#updateorder what you mean is "Add an element with name updateorder from the namespace ind".
If you really want the output without namespace declaration. you can think of it as you need an element with name ind:updateorder and not updateorder from ind.
In other words, replace ind#updateorder with "ind:updateorder" and similarly at other places. something like this
%dw 2.0
ns soapenv http://schemas.xmlsoap.org/soap/envelope/
output application/xml writeDeclaration=false
---
{
soapenv#Envelope: {
soapenv#Header: {},
soapenv#Body: {
"ind:updateorder": {
"ind:orderId": payload.orderId,
"ind:orderName": payload.order,
"ind:quantity": "5",
"ind:order": {
"att:productId": payload.productId,
"att:desc": payload.desc,
"att:shipping": "MAIL",
"att:status": payload.status,
"att:type1": payload.order,
"att:recieved": payload.recieved,
"att:otherDetails": payload.*details map () -> {
"att:details1": $.attributeS.linetype
}
}
}
}
}
}
However, as I mentioned earlier, this is not a valid XML. You can try the w3school validator or any other online tool to validate to check.

Shopware 6 Admin Api - Updating existing record through patch method. Not working

shopware 6 admin api patch - why it's failing? I get error "Only single write operations are supported"
Following is api for rule-condition entity in the database, I update it with Id.
For same api get method is working!
url: api/rule-condition/dbb0d904c7c14860a9a94cf26b94eca6
method: patch
json body
[
{
"op": "replace",
"path": "/data/attributes/value/email",
"value": "test#gmail.com"
}
]
response:
{
"errors": [
{
"code": "0",
"status": "400",
"title": "Bad Request",
"detail": "Only single write operations are supported. Please send the entities one by one or use the /sync api endpoint.",
.......
I also tried changing json body to following
{
"data": {
"attributes": {
"value": {
"email": "test#gmail.com"
}
}
} }
Still it's not updating. Can somebody check and let me know what am i missing?
Documentation I followed:
https://shopware.stoplight.io/docs/admin-api/ZG9jOjEyMzA4NTQ5-writing-entities
This website has all apis and example methods. https://swagger.docs.fos.gg/,
rule-condition entity can also be found there.
Btw : I used postman for testing api
You're passing an array of objects in the request body, suggesting you want to update multiple records, but the endpoint only supports updating a single record. The correct payload in your case should look like this:
{
"value": {
"operator": "=",
"email": "test#gmail.com"
}
}
Notice that value is a json field and not only includes a single value. The exact content and the names of the properties of value depend on the type of condition used and usually it also includes the operator used in the condition.

How to post event with metadata to stream through HTTP API

I'm using EventStore and want to post a message (event) to it. I use the HTTP API for testing purposes. I've managed to post the event itself, with an event type specified, but I can't figure out how to specify metadata for my event. (and I must provide this metadata because my consuming application on the other side expects it).
This is what my HTTP request looks like:
Content-Type: application/json
ES-EventType: My.own.event.type
POST http://10.0.75.2:2113/web/index.html#/streams/foobar
{
"props": "andvalues"
}
Do I specify metadata in the body in through headers? I can't find much docs about this, only the official that doesn't mention it.
The documentation mentions the full schema for an event being written. It looks like this:
[
{
"eventId" : "string",
"eventType" : "string",
"data" : "object",
"metadata" : "object"
}
]
For example:
[
{
"eventId": "fbf4a1a1-b4a3-4dfe-a01f-ec52c34e16e4",
"eventType": "event-type",
"data": { "a": "1" },
"metadata": { "b": "2" }
}
]
Note that it's an array, and that you must pass content-type as application/vnd.eventstore.events+json
Check this page, scroll to Event Store Events Media Type.

How to add a simple flow rule via OpenDaylight DLUX using the /operations/sal-flow:add-flow api

I am trying to add a simple flow rule via Lithium's DLUX using the /operations/sal-flow:add-flow api call but getting nothing but errors, please can someone help?
Even a preview of a sample flow someone has added would be really helpful?
My current input as displayed in the preview frame is:
http://localhost:8181/restconf/operations/sal-flow:add-flow
{
"add-flow": {
"input": {
"match": {
"ethernet-match": {
"ethernet-type": {
"type": "2048"
}
},
"ipv4-source": "10.0.0.1/32"
},
"instructions": {
"instruction": [
{
"order": "0",
"apply-actions": {
"action": [
{
"drop-action": {},
"order": "0"
}
]
}
}
]
},
"flow-name": "test",
"table_id": "0"
}
}
}
The current error is:
"Server Error : The server encountered an unexpected condition which prevented it from fulfilling the request. - : The operation encountered an unexpected error while"
The same request in Postman gives the error:
{
"errors": {
"error": [
{
"error-type": "protocol",
"error-tag": "malformed-message",
"error-message": "Error parsing input: Schema node with name add-flow wasn't found under (urn:opendaylight:flow:service?revision=2013-08-19)add-flow."
}
]
}
}
I have seen examples using xml but nothing that seems to work. I am able to view the network topology via dlux so I presume I am connected to everything ok.
Many thanks in advance.
Remove the add-flow and the corresponding brackets from the input data. Use things like
{
input: {...},
output: {...}
}
I am having the same problem using DLUX. Anyway I managed to find a solution using XML POST requests from this link https://wiki.opendaylight.org/view/OpenDaylight_OpenFlow_Plugin:End_to_End_Flows. You can use POSTMAN application on Chrome to send requests. The body of the request should be something like:
POST http://localhost:8080/restconf/operations/sal-flow:add-flow
Add authentication header too.
Content-type: application/xml
Accept: application/xml
Body:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<input xmlns="urn:opendaylight:flow:service">
<barrier>false</barrier>
<node xmlns:inv="urn:opendaylight:inventory">/inv:nodes/inv:node[inv:id="openflow:1"]</node>
<cookie>55</cookie>
<flags>SEND_FLOW_REM</flags>
<hard-timeout>0</hard-timeout>
<idle-timeout>0</idle-timeout>
<installHw>false</installHw>
<match>
<ethernet-match>
<ethernet-type>
<type>2048</type>
</ethernet-type>
</ethernet-match>
<ipv4-destination>10.0.10.2/32</ipv4-destination>
</match>
<instructions>
<instruction>
<order>0</order>
<apply-actions>
<action>
<output-action>
<output-node-connector>1</output-node-connector>
</output-action>
<order>0</order>
</action>
</apply-actions>
</instruction>
</instructions>
<priority>0</priority>
<strict>false</strict>
<table_id>0</table_id>
</input>

return user photo url via SCIM in UnboundID

In the SCIM core schema there is a simple multivalued attribute "photos" defined to hold the urls of a user's photos.
In the UnboundID Data Store config directory the scim-resources.xml file has the following commented out under the User resource:
<!-- Mapping must be defined to use this attribute
<attribute name="photos" schema="urn:scim:schemas:core:1.0"
readOnly="false" required="false">
<description>URL of photos of the User</description>
<simpleMultiValued childName="photo" dataType="string">
<canonicalValue name="photo"/>
<canonicalValue name="thumbnail"/>
</simpleMultiValued>
</attribute>
-->
Further down in the spec is an example output:
"photos": [
{
"value": "https://photos.example.com/profilephoto/72930000000Ccne/F",
"type": "photo"
},
{
"value": "https://photos.example.com/profilephoto/72930000000Ccne/T",
"type": "thumbnail"
}
],
I have User entries with the jpegPhoto attribute populated. Questions:
Does UnboundID already have an endpoint defined to access these
photos? I don't want just the encoded binary string value of jpegPhoto
If such an endpoint exists (or I create one), do I then need to write a transformation class and reference it in a <subMapping> child element of the <canonicalValue> elements?
If how to do this is documented somewhere I haven't been able to find it.
Any guidance appreciated.
Grant
Since the SCIM photos attribute refers to an array of external URLs to the photos, you could create a Data Store virtual attribute which maps in SCIM to an array of URLs that reference a hosted servlet to retrieve the photo(s). There is no existing server endpoint for returning jpegPhoto attributes from an ldap entry and you've said you don't want the base64-encoded binary data via SCIM.
An HTTP Servlet Extension which returns photos would ideally accept the same credentials as the SCIM user for authentication and perform an LDAP search as the SCIM user that will honor ACI access control for the jpegPhoto attribute, e.g.
GET https://server:8443/photosEndpoint/{entryUUID}[/attribute-option]
Authorization: <scim user credentials>
Since jpegPhoto is a multi-value attribute, if there is one (or the first, if many) jpegPhoto attributes, this can return an img/jpeg content-type entity. It looks like you're attempting to select from multiple photos using a qualifier, e.g. /F for full size? and /T for thumbnail but there is no way to tell multi-values attribute values apart in LDAP without an attribute option, e,g,
jpegPhoto returned via /photosEndpoint/{entryUUID}
jpegPhoto;size=fullsize returned via /photosEndpoint/{entryUUID}[/fullsize | /F]
jpegPhoto;size=thumbnail returned via /photosEndpoint/{entryUUID}[/thumbnail | /T]
The servlet could also be written to handle multiple photos by returning them in a multi-part MIME response with a jpegPhoto per part. The part names would include the attribute options, if available. One downside is this kind response would not render easily in a browser.
Overall this is a nice-to-have idea but some amount of work in practice. UnboundID support might be able to help.
As a starting point I wrote a simple servlet to return the first value of jpegPhoto (if present) as an image/png via an LDAP query against the uid. I then wrote a simple transform class to return the relevant photo URL based on the uid:
import com.unboundid.asn1.ASN1OctetString;
import com.unboundid.scim.schema.AttributeDescriptor;
import com.unboundid.scim.sdk.SCIMAttributeValue;
import com.unboundid.util.ByteString;
public class PhotoTransform extends com.unboundid.scim.ldap.Transformation {
#Override
public String toLDAPFilterValue(String scimFilterValue) {
// TODO Auto-generated method stub
return null;
}
#Override
public ASN1OctetString toLDAPValue(AttributeDescriptor descriptor, SCIMAttributeValue value) {
// TODO Auto-generated method stub
return null;
}
#Override
public SCIMAttributeValue toSCIMValue(AttributeDescriptor descriptor, ByteString value) {
return SCIMAttributeValue.createStringValue("http://localhost:4567/photo/" + value.stringValue());
}
I then referenced the class in the SCIM resources.xml passing the uid as the LDAP attribute:
<attribute name="photos" schema="urn:scim:schemas:core:1.0"
readOnly="false" required="false">
<description>URL of photos of the User</description>
<simpleMultiValued childName="photo" dataType="string">
<canonicalValue name="photoUrl">
<subMapping name="value" ldapAttribute="uid"
transform="com.example.scim.PhotoTransform">
</subMapping>
</canonicalValue>
<canonicalValue name="thumbnail"/>
</simpleMultiValued>
</attribute>
and a SCIM query (against the reference implementation)
curl 'http://localhost:8080/Users?filter=userName%20eq%20%22jsmith%22' -u bjensen:password
now returns:
{
"totalResults" : 1,
"itemsPerPage" : 1,
"startIndex" : 1,
"schemas" : ["urn:scim:schemas:core:1.0", "urn:scim:schemas:extension:enterprise:1.0"],
"Resources" : [{
"name" : {
"formatted" : "Mr. John Smith",
"familyName" : "Smith",
"givenName" : "John"
},
"phoneNumbers" : [{
"value" : "tel:555-555-1256",
"type" : "work"
}
],
"userName" : "jsmith",
"emails" : [{
"value" : "jsmith#example.com",
"type" : "work"
}
],
"photos" : [{
"value" : "http://localhost:4567/photo/jsmith",
"type" : "photoUrl"
}
],
"id" : "fb4134dc-0a93-476a-964a-c29847f3bf79",
"meta" : {
"created" : "2015-09-09T00:17:12.768Z",
"lastModified" : "2015-09-09T00:17:12.768Z",
"location" : "http://localhost:8080/v1/Users/fb4134dc-0a93-476a-964a-c29847f3bf79",
"version" : "\"20150909001712.768Z\""
}
}]
}