2

I am writing an program to integrate with AppDirect. Link is: http://info.appdirect.com/developers/docs/api_integration/subscription_management

I successfully handle subscription order, change, and cancel events. Now, I want to send metered usage to appdirect and I followed instruction on this page http://info.appdirect.com/developers/docs/api_integration/subscription_management/metered_usage_api

However, it always returns me HTTP/1.1 401 Unauthorized and a long html page. This is my HTTP request to AppDirect:

POST https://www.appdirect.com/api/integration/v1/billing/usage?oauth_consumer_key=mykey&oauth_nonce=775137&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1422880351&oauth_version=1.0&oauth_signature=q17RzR1KvuxHXvle0Uxrnn16IIA%3d HTTP/1.1
Content-Type: application/xml
Host: www.appdirect.com
Content-Length: 318
Expect: 100-continue
Accept-Encoding: gzip, deflate
Connection: Keep-Alive

<?xml version="1.0" encoding="utf-16"?>
<usage xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <account>
    <accountIdentifier>123456</accountIdentifier>
  </account>
  <item>
    <unit>DOCUMENT</unit>
    <quantity>10</quantity>
  </item>
</usage>

My program uses MVC5, CookieAwareWebClient to send http request (code: How do I log into a site with WebClient?)

Are there anything wrong in my request? Please let me know if you need more information. Any help would be highly appreciated. Thank heaps.

Community
  • 1
  • 1
Tung Nguyen
  • 574
  • 8
  • 16

1 Answers1

3

I figured out what happened. That was a wrong OAuth Signature calculation. HTTP method included in OAuth calculation was GET, but it supposes to be POST.

As soon as I change it to POST, it works.

Tung Nguyen
  • 574
  • 8
  • 16
  • Glad you got it working. i havent published my app yet, testing metered now, but all i get in response is :Order not found. seen that one before? – Havihavi Oct 28 '18 at 19:39
  • @Havihavi nope, i didn't get that one. The one I did was a long time back and AppDirect now support json so it is worth to look at their new documentation. – Tung Nguyen Oct 28 '18 at 23:33
  • yeah, i'm following that. its the same as it was besides ability to post json. sent an email to them, hopefully they'll have some insight to share. thanks for replying! – Havihavi Oct 29 '18 at 23:10