× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Tim,

There's no 'authorization' option in HTTPAPI for http_setOption(), so that won't do anything.

Instead, use http_setAuth() to set authorization.  If you run the string you're providing into a base64 decoder, you'll see that it consists of a userid and password separated by a colon character. (In your case, this appears to be hex data, which makes things a little more complicated, since it'll get translated from EBCDIC to UTF-8 which will change the values.  Ugh.  So you have to figure out what EBCDIC values will translate to the same UTF-8/ASCII value the site requires.)

If you can't use http_setAuth(), then you have to use http_xproc() to add a custom header.

-SK


On 4/16/19 4:00 PM, tim wrote:
I am trying to use rest to access usaepay system (https://help.usaepay.info/developer/rest-api/) (code below).

Im getting the following error "HTTP/1.1 401 Valid authentication required". I generated the key using the PHP sample code on the site.


H DFTACTGRP(*NO) BNDDIR('HTTPAPI':'QC2LE')

D myJSON          s            500a   varying
D authorization   s            500a   varying
D rc              s             10i 0

 /copy LIBHTTP/QRPGLESRC,httpapi_h

   *inlr = *on;

   myjson = ' +
     {"command": "cc:sale", +
      "amount": "5.00", +
      "amount_detail": +
       { +
       "tax": "1.00", +
       "tip": "0.50" +
       }, +
      "creditcard": +
       { +
         "cardholder": "John doe", +
         "number": "4000100011112224", +
         "expiration": "0919", +
         "cvc": "123", +
         "avs_street": "1234 Main", +
         "avs_zip": "12345" +
       }, +
      "invoice": "12356" +
     } +
     ';

   http_debug(*on: '/home/tim/result.txt');

   http_setOption( 'content-type'  : 'application/json' );
   http_setOption( 'user-agent'    : 'uelib v6.8');
   authorization = 'Basic +
v0dIcexyabhyMEdIOTdeSnBVWVNddvFSNevKODl6vVk6czvvYdJvd+
vgmZ2hpamtsbd5vcC8zrDJhYdU1YTEyNT2xMmY4NzVhZmU2M+
zg5NDc4YdNhdjd5MdUdYggdYTJdNvddYzEdOWFkdTvwZTFkdvVldTv2';
   http_setOption( 'Authorization' : authorization);
   rc = http_post( 'https://sandbox.usaepay.com/api/v2/transactions'
                    : %addr( myJSON : *data )
                    : %len( myJSON )
                    : '/home/tim/result.json'
                    : HTTP_TIMEOUT
                    : HTTP_USERAGENT
                    : 'application/json' );


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.