salesforce-marketingcloud / FuelSDK-Java

Salesforce Marketing Cloud Java SDK
BSD 3-Clause "New" or "Revised" License
72 stars 123 forks source link

[BUG] Can't create Asset #147

Open ypiel-talend opened 1 year ago

ypiel-talend commented 1 year ago

Describe the bug We can't create Asset since we can't set AssetType.

To Reproduce We tried this code:

ETAsset asset = new ETAsset();
asset.setName("Asset Test 1");
asset.setContent("Asset Test 1 content");
asset.setContentType("text/plain");

ETResponse<ETAsset> etAssetETResponse = client.create(asset);

And this issue is returned:

{"message":"Request contained some validation errors.","errorcode":10006,"documentation":"","validationErrors":[{"message":"You must provide a valid AssetType for the Asset.","errorcode":118075,"documentation":""}]}

We also tried with a direct HTTP call. We have the same issue if AssetType is not set, but successful with this code:

String payload = """
        {
          "Name": "Asset 1",
          "AssetType": {
            "Id": 1
          },
          "Data": {
            "message": "A message"
          }
        }
""";

String rest_endpoint = this.getConf().get("endpoint") + "asset/v1/content/assets";

HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
        .uri(URI.create(rest_endpoint))
        .header("Content-Type", "application/json")
        .header("Authorization", "Bearer " + token)
        .POST(HttpRequest.BodyPublishers.ofString(payload, StandardCharsets.UTF_8))
        .build();

HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());

Expected behavior There is no ETAssetType attribute in ETAsset, but it is mandatory to create an Asset.

Environment

The bug has the severity

Additional context Add any other context about the problem here.

ypiel-talend commented 1 year ago

We have created a sub class to fix it successfully:

@Data
@RestObject(path = "/asset/v1/content/assets",
        primaryKey = "id",
        collection = "items",
        totalCount = "count")
public class ETAssetFixed extends ETAsset {

    @Expose
    @ExternalName("AssetType")
    private AssetType assetType = null;

    @Data
    public static class AssetType {

        @Expose
        @ExternalName("id")
        private int id;

    }
}

And then:

       ETAssetFixed.AssetType assetType = new ETAssetFixed.AssetType();
        assetType.setId(2);

        ETAssetFixed asset = new ETAssetFixed();
        asset.setName("Asset Test 1");
        asset.setContent("Asset Test 1 content");
        asset.setContentType("text/plain");
        asset.setAssetType(assetType);

        ETResponse<ETAsset> etAssetETResponse = client.create(asset);

Works well.