ChannelApe / shopify-sdk

Java SDK for Shopify REST APIs
Apache License 2.0
166 stars 112 forks source link

ShopifyErrorCodeFactory - Could not parse error message from shopify for response body #121

Closed DoboszKacper closed 1 year ago

DoboszKacper commented 1 year ago

Hi, I am trying to run tests for example product. But what i get is 406 from shopify. Do you know what i might be doing wrong?

Error: [main] WARN com.shopify.exceptions.ShopifyErrorCodeFactory - Could not parse error message from shopify for response body: com.fasterxml.jackson.databind.JsonMappingException: No content to map due to end-of-input com.shopify.exceptions.ShopifyErrorResponseException: Received unexpected Response Status Code of 406

Code:

@Test
    public void givenSomeProductCreationRequestWhenCreatingProductThenCreateAndReturnProduct()
            throws JsonProcessingException {
        final ShopifyProductRoot shopifyProductRoot = new ShopifyProductRoot();
        final ShopifyProduct shopifyProduct = new ShopifyProduct();
        shopifyProduct.setId("123");
        final Image image = new Image();
        image.setName("Some image 1");
        image.setPosition(0);
        image.setProductId("123");
        image.setSource("http://channelape.com/1.png");
        shopifyProduct.setImages(Arrays.asList(image));
        shopifyProduct.setProductType("Shoes");
        shopifyProduct.setBodyHtml("Some Description");
        shopifyProduct.setTags(new HashSet<>(Arrays.asList("Shoes", "Apparel")));
        shopifyProduct.setPublished(true);
        shopifyProduct.setTitle("Some Title");
        shopifyProduct.setVendor("Some Vendor");
        shopifyProduct.setPublishedAt("2018-01-01T00:00:00");

        final ShopifyVariant shopifyVariant = new ShopifyVariant();
        shopifyVariant.setId("999");
        shopifyProduct.setVariants(Arrays.asList(shopifyVariant));
        shopifyProductRoot.setProduct(shopifyProduct);

        final BigDecimal somePrice = BigDecimal.valueOf(42.11);
        final ShopifyVariantCreationRequest shopifyVariantCreationRequest = ShopifyVariantCreationRequest.newBuilder()
                .withPrice(somePrice).withCompareAtPrice(somePrice).withSku("ABC-123").withBarcode("XYZ-123")
                .withWeight(somePrice).withAvailable(13).withFirstOption("Shoes").withSecondOption("Red")
                .withThirdOption("Green").withImageSource("http://channelape.com/1.png")
                .withDefaultInventoryManagement().withDefaultInventoryPolicy().withDefaultFulfillmentService()
                .withRequiresShipping(true).withTaxable(true).build();
        final ShopifyProductCreationRequest shopifyProductCreationRequest = ShopifyProductCreationRequest.newBuilder()
                .withTitle("Some Product Title").withMetafieldsGlobalTitleTag("Some Metafields Global Title Tag")
                .withProductType("Shoes").withBodyHtml("Some Description")
                .withMetafieldsGlobalDescriptionTag("Some Metafields Tag").withVendor("Some Vendor")
                .withTags(Collections.emptySet()).withSortedOptionNames(Collections.emptyList())
                .withImageSources(Arrays.asList("http://channelape.com/1.png", "http://channelape.com/2.png"))
                .withVariantCreationRequests(Arrays.asList(shopifyVariantCreationRequest)).withPublished(true).build();

        final ShopifyProduct actualShopifyProduct = shopifySdk.createProduct(shopifyProductCreationRequest);
        System.out.println(actualShopifyProduct);
    }
DoboszKacper commented 1 year ago

Of course, there is no problem with connecting to shopify, this I tested. The only problem I found was creating an example product.

DoboszKacper commented 1 year ago

Okay resolved this issue, in partner site shop had set different subdomian that provided in sdk. Both subdomains were referencing the same site, but only one had partners access to create products.

ShopifySdk shopifySdk = ShopifySdk.newBuilder() .withSubdomain("example") .withAccessToken("example_api") .withApiVersion("2023-07") .build();