How to send Metered Usage to AppDirect

520 Views Asked by At

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.

1

There are 1 best solutions below

3
Tung Nguyen On BEST ANSWER

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.