Closed jclaramo closed 1 year ago
Hello,
I checked with your code and it works for me.
In our api documentation, the property product
takes the ResourceIdentifier of the Product.
You can find same behavior in our JavaDoc
I would suggest you check if the API specification is correctly updated on your side.
Which SDK version do you have? I cannot find the 11.0.0
Hello, I messed writing the SDK version, the SDK version that I am using the latest version 2.10.0.
Sorry, I missclicked and closed the issue.
so because the behavior is right, and it should work with the product Resource Identifier and it looks like it doesn't take the right API, could you please send us the exact error you are receiving?
The error is ErrorResponseException, the full error message is:
detailMessage: Request body does not contain valid JSON.
summary: POST https://api.europe-west1.gcp.commercetools.com/product-selections/f3a16f3e-3d49-4319-8a93-bc37220f8419 failed with response code 400 with X-Correlation-ID `{{project-key}}/7b986149-ac8b-4225-bd6a-f8e45a4af48a` on 2023-01-04T12:58:07.376942900Z
http response formatted body: {
"statusCode" : 400,
"message" : "Request body does not contain valid JSON.",
"errors" : [ {
"code" : "InvalidJsonInput",
"message" : "Request body does not contain valid JSON.",
"detailedErrorMessage" : "actions -> product: Missing required value"
} ]
}
http response: io.sphere.sdk.http.HttpResponseImpl@37052337[statusCode=400,headers={date=[Wed, 04 Jan 2023 12:58:03 GMT], content-length=[172], server=[istio-envoy], x-envoy-upstream-service-time=[3], access-control-allow-headers=[Accept, Authorization, Content-Type, Origin, User-Agent, X-Correlation-ID], content-encoding=[gzip], x-correlation-id=[{{project-key}}/7b986149-ac8b-4225-bd6a-f8e45a4af48a], access-control-allow-methods=[GET, POST, DELETE, OPTIONS], access-control-expose-headers=[X-Correlation-ID], via=[1.1 google], access-control-allow-origin=[*], x-http-status-caused-by-external-upstream=[false], access-control-max-age=[299], content-type=[application/json; charset=utf-8], server-timing=[projects;dur=2], alt-svc=[h3=":443"; ma=2592000,h3-29=":443"; ma=2592000]},associatedRequest=<null>,textInterpretedBody={"statusCode":400,"message":"Request body does not contain valid JSON.","errors":[{"code":"InvalidJsonInput","message":"Request body does not contain valid JSON.","detailedErrorMessage":"actions -> product: Missing required value"}]}]
SDK: 2.9.0
project: {{project-key}}
endpoint: POST /product-selections/f3a16f3e-3d49-4319-8a93-bc37220f8419
Java: 11.0.13
cwd: C:\Users\{{user}}\Desktop\Personal\Java\{{project-key}}
sphere request: ProductSelectionUpdateCommandImpl[additionalHttpQueryParameters=[],baseEndpointWithoutId=/product-selections,creationFunction=io.sphere.sdk.productselections.commands.ProductSelectionUpdateCommandImpl$$Lambda$271/0x000000080030e440@6f2cfcc2,expansionModel=ProductSelectionExpansionModelImpl[pathExpressions=[]],expansionPaths=[],javaType=[simple type, class io.sphere.sdk.productselections.ProductSelection],updateActions=[AddProduct[productResourceIdentifier=ResourceIdentifierImpl[id=<null>,key=51860,typeId=product],action=addProduct]],versioned=ProductSelectionImpl[createdAt=2023-01-03T08:00:38.695Z,createdBy=CreatedByImpl[anonymousId=<null>,clientId=<null>,customer=<null>,externalUserId=<null>],custom=<null>,id=f3a16f3e-3d49-4319-8a93-bc37220f8419,key=eurosur-products,lastModifiedAt=2023-01-04T09:17:45.138Z,lastModifiedBy=LastModifiedByImpl[anonymousId=<null>,clientId=Xem4Cf0iFbZFM5xCsSRCDcrn,customer=<null>,externalUserId=<null>],name=LocalizedString(en -> , es -> Productos Eurosur),productCount=1,type=INDIVIDUAL,version=2]]
http request: HttpRequestImpl[body=io.sphere.sdk.http.StringHttpRequestBody@3ecd267f[body={"version":2,"actions":[{"action":"addProduct","productResourceIdentifier":{"key":"51860","typeId":"product"}}]}],headers={},httpMethod=POST,url=https://api.europe-west1.gcp.commercetools.com/product-selections/f3a16f3e-3d49-4319-8a93-bc37220f8419]
http request formatted body: {
"version" : 2,
"actions" : [ {
"action" : "addProduct",
"productResourceIdentifier" : {
"key" : "51860",
"typeId" : "product"
}
} ]
}
additional notes: []
Javadoc: https://commercetools.github.io/commercetools-jvm-sdk/apidocs/io/sphere/sdk/client/ErrorResponseException.html
Thanks.
So from what I can see, the error is in the request, would you mind trying it this way, please?
AddProduct addProduct = AddProduct.of(product.toResourceIdentifier());
and then pass this result in the request like you did before.
I tried and it keeps sending the same json wrong body with the "productResourceIdentifier" instead of "product".
I opened a PR for this problem. I'll let you know once we will issue a new release.
Ok, thank you very much.
I just released version 2.11.0 with the fix
Describe the bug When using the UpdateAction AddProduct instead of "product" it creates a "resourceIdentifierProduct" which it's not match with the API.
To Reproduce
This is the json request body that crashes;
Expected behavior
Stack information (please complete the following information):
Additional context![image](https://user-images.githubusercontent.com/121937166/210530068-90e1875a-0e69-4c14-9ba8-6f0b728abe6b.png)