skip to Main Content

I want to get orders for the specific date but getting below error tried several date formates but getting the same error. This only happens when I am adding date parameters(before and after). This api works fine for per_page or without any param.

WooCommerce wooCommerce = new WooCommerceAPI(config, ApiVersionType.V3);
Map<String, String> params = new HashMap<>();
params.put("per_page","10");
params.put("after","2016-11-20T13:57:31.2311892-04:00");
params.put("before","2017-11-20T13:57:31.2311892-04:00");

List<Map<String, Object>>  orders = wooCommerce.getAll(EndpointBaseType.ORDERS.getValue(), params);

This code is giving me an error
Exception in thread "main" java.lang.RuntimeException: Can’t parse retrieved object: {code=woocommerce_rest_authentication_error, message=Invalid signature – provided signature does not match., data={status=401}}

2

Answers


  1. Chosen as BEST ANSWER

    I got the solution for the date issue here is the solution. we need to encode the dates.

    params.put("after", percentEncode("01-01-2021T00:00:00"));
    
    public String percentEncode(String s) {
            final String UTF_8 = "UTF-8";
    
            try {
                return URLEncoder.encode(s, UTF_8)
                        // OAuth encodes some characters differently:
                        .replace(SpecialSymbol.PLUS.getPlain(), SpecialSymbol.PLUS.getEncoded())
                        .replace(SpecialSymbol.STAR.getPlain(), SpecialSymbol.STAR.getEncoded())
                        .replace(SpecialSymbol.TILDE.getEncoded(), SpecialSymbol.TILDE.getPlain());
            } catch (UnsupportedEncodingException e) {
                throw new RuntimeException(e.getMessage(), e);
            }
        } 
    

  2. For me just using this format 2021-07-01T11:51:36 helped.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search