[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Unsupported_grant_type



Tony,

I'm not familiar with this web service or the error that you're getting.

Please understand that HTTPAPI is just a communication tool. It communicates your message to an HTTP server, and communicates that server's response to you. If the server (as opposed to HTTPAPI) sends back an error message, it does not indicate a problem in HTTPAPI. In fact, quite the opposite, it tells you that HTTPAPI is doing it's job and handling the communication.

As an analogy, a telephone is a communications device for humans (whereas HTTPAPI is for programs.) Consider the situation where you call your boss and ask for a raise. Of course we'd all like nothing better than to hear "yes, absolutely!" But, if he gives you a negative response like "sorry, can't do that", it does NOT mean your telephone is broken.

Likewise, HTTPAPI has sent your data to the web service just as you asked it to. We'd all love to get back "success! good job!", but if the message is negative like "unsupported grant type" (or any other message) it does NOT mean that HTTPAPI is broken. If you want to know why you're getting that message, you need to discuss that with whomever the expert on the web service is.

Having said that, I could take some guesses...

You're sending a content-type of application/x-www-form-urlencoded -- this does not seem to match the data you're sending. That is the content-type that a browser uses when submitting an HTML <form> tag, or data formatted in that same way. But you are sending raw JSON data -- seems very unlikely that that is the correct type for that. You might try "application/json" instead? Or ask the web service provider what the proper content-type would be?

The other strong possibility is that you've formatted your JSON data wrong. I can't comment on this since I haven't a clue what the right format is, and I'm also not familiar with the jsonNode() stuff you're using. Of course, creating a debug log with the http_debug() API would show exactly what is sent -- but without knowing what the web service requires, I couldn't tell you if it is right/wrong.

-SK



On 6/29/2016 4:14 PM, Tony Cesarios wrote:
     [cid:image001.gif@01D1D29E.B68350E0]

    Hi,


    Attempting to create a simple RPG program which will obtain a
    access-token, however when doing the http_url_post I receive back an
    error "unsupported_grant_type".


    Program is using a combination of HTTPAPI and powerEXT.


    Here's the code as it stands:


    /copy pextcd2/qsrc,pxapihdr      General
    H-Spec's



     * powerEXT Service Program
    Connector

     /copy pextcd2/qsrc,pxapicgicn    Basic HTTP connecter & Productivity
    Services

     /copy pextcd2/qsrc,pxapijsncn    YAJL JSON connector



     * Support for HTTPAPI by Scott
    Klement

     /copy
    qrpglesrc,httpapi_h



     * Declare Internal
    Variables

    d dsp             s
    50A

    d dspwait         s
    1A



    d rc              s             10I
    0

    d i               s             10I
    0



    d url             s           2048A   Varying



    d tmpFile         s            256a
    varying


     /free

      // Clear powerEXT Service Program & Responce Object

      clearSrvPgm();


      // construct a JSON message with powerEXT JSON support


      setContent('*none');


      jsonNode('*object');

          jsonNode('*string':'grant_type=':'password');

          jsonNode('*string':'username=':'PSI');

          jsonNode('*string':'password=':'Rohit66');

      jsonEndNode();


      // Construct a temporary result file name for HTTPAPI


      tmpFile = '/tmp/tst'+uniqueKey+'.json';


      // Setup HTTPAPI Url and parms

      HTTP_debug(*on);

      HTTP_SetCCSIDs(1208:0);

      HTTP_SetFileCCSID(1208);

      url = 'https://202.47.1.145/adfAPI/token';


      // Send HTTPAPI Request

      rc = http_url_post( url

                        : bufAddr()

                        : bufSize()

                        : tmpfile

                        : HTTP_TIMEOUT

                        : HTTP_USERAGENT

                        : 'application/x-www-form-urlencoded');


      // HTTPAPI Error Handling

      if rc <> 1;

        dsply %char(rc);

        dsp = http_error;

        dsply  dsp;

        *inlr = *on;

        return;

      endif;


      // Display HTTPAPI result with qcmd method

      qcmd('dspf (''' + tmpFile + ''')');


      // Delete object with qcmd method

      qcmd('del (''' + tmpFile + ''')');


      *inlr = *on;

     /end-free





    Regards,

    Tony Cesarios



-----------------------------------------------------------------------
This is the FTPAPI mailing list.  To unsubscribe, please go to:
http://www.scottklement.com/mailman/listinfo/ftpapi
-----------------------------------------------------------------------

-----------------------------------------------------------------------
This is the FTPAPI mailing list.  To unsubscribe, please go to:
http://www.scottklement.com/mailman/listinfo/ftpapi
-----------------------------------------------------------------------