Skip to content

401 invalid signature when doing a GET with "after" or "before" as parameter #23

Closed

Description

@lucasmorita

The error occurs when trying to retrieve all orders from the api, passing "after" or "before" as parameter. The following code reproduces the error:

        Map<String, String> param = new HashMap<>();
        param.put("after", "2019-08-08T00:00:00");

        OAuthConfig config = new OAuthConfig(url, consumerKey, consumerSecret);
        WooCommerce api = new WooCommerceAPI(config, ApiVersionType.V2);

        List orders = api.getAll(EndpointBaseType.ORDERS.getValue(), param);

The stack trace:

java.lang.RuntimeException: Can't parse retrieved object: {code=woocommerce_rest_authentication_error, message=Assinatura inválida - a assinatura fornecida não corresponde., data={status=401}}

	at com.icoderman.woocommerce.DefaultHttpClient.getEntityAndReleaseConnection(DefaultHttpClient.java:127)
	at com.icoderman.woocommerce.DefaultHttpClient.getAll(DefaultHttpClient.java:49)
	at com.icoderman.woocommerce.WooCommerceAPI.getAll(WooCommerceAPI.java:44)
	at br.com.xxxxxxxxxx.SeoxApplicationTests.apiCall(SeoxApplicationTests.java:57)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.springframework.test.context.junit4.statements.RunBeforeTestExecutionCallbacks.evaluate(RunBeforeTestExecutionCallbacks.java:74)
	at org.springframework.test.context.junit4.statements.RunAfterTestExecutionCallbacks.evaluate(RunAfterTestExecutionCallbacks.java:84)
	at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
	at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
	at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:251)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
	at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
	at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
	at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)

Activity

  1. changed the title [-]401 invalid signature when doing a GET with "after" as parameter[/-] [+]401 invalid signature when doing a GET with "after" or "before" as parameter[/+] on Sep 4, 2019
  2. ngocnd0242 commented on Apr 15, 2020

    @ngocnd0242

    @lucasmoriita I faced same as your issue, Have you fixed it? Could you help me fix it?

  3. ngocnd0242 commented on Apr 15, 2020

    @ngocnd0242

    I'm trying to get the newest order after the time ISO8061 point...

  4. ngocnd0242 commented on Mar 12, 2021

    @ngocnd0242

    @innoventry I took two days and I gave up and I changed my project to use laravel framework

  5. ngocnd0242 commented on Mar 12, 2021

    @ngocnd0242

    someday, If I use java again, I will try it

  6. ngocnd0242 commented on Mar 12, 2021

    @ngocnd0242

    @lucasmorita Please try it.

  7. lucasmorita commented on Mar 13, 2021

    @lucasmorita
    Author

    @ngocnd0242 Sorry for the delay in responding.
    Actually, I gave up too, and it's been a while since I don't even touch at the code. But, as a workaround, I've decided to use OkHttp to make the requests as a workaround 😄

  8. shakila-rajaiah commented on Oct 13, 2021

    @shakila-rajaiah

    You need to percentEncode the date string before setting that as parameter value. params.put( "after", OAuthSignature.percentEncode( "2019-11-16T15:02:30" ) );

    This does not work as well.

  9. ngocnd0242 commented on Oct 13, 2021

    @ngocnd0242

    @shakila-rajaiah you try it https://gist.github.com/JakeWharton/f26f19732f0c5907e1ab I think you should write reset + oauth1 yourself, I used by chilkat, It's works fine

    WooCkRest rest = new WooCkRest();
            OrderEntity newOrder = orderRepository.findFirstByStatusOrderByDateCreatedDesc(OrderStatus.NEW.getVal());
            if (Objects.nonNull(newOrder)) {
                rest.AddQueryParam("after", newOrder.getDateCreatedOriginal());
            } else {
                OrderEntity checkedOrder = orderRepository.findFirstByStatusOrderByDateCreatedDesc(OrderStatus.CHECKED.getVal());
                if (Objects.nonNull(checkedOrder)) {
                    rest.AddQueryParam("after", checkedOrder.getDateCreatedOriginal());
                }
            }
            rest.AddQueryParam("per_page", "100");
    
            rest.SetAuthOAuth1(oauth1, true);
            boolean success = rest.Connect(url, url.contains("https") ? 443 : 80, false, true);
            if (success != true) {
                log.error("rest.Connect" + rest.lastErrorText());
                return null;
            }
    
  10. Jookus commented on May 8, 2022

    @Jookus

    Pull request #37 fixed it for me

  11. lucasmorita commented on Jul 1, 2022

    @lucasmorita
    Author

    Closing issue as it is fixed by #37

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions