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

Re: [Ftpapi] HTTP Headers in REST GET



Your suggestion was spot on, Jon.  Thank you!  I was able to send the required headers and got the expected JSON response back.  Now I’m trying to muddle my way through the YAJL Data-Gen, but that’s another issue. 😊  Thanks again.

 

Ken Danforth | Amscan Inc. | Dir - International Business Systems

80 Grasslands Road | Elmsford, NY 10523

O: 914-784-4161 | M: 914-589-3614 | F: 914-784-8819 | E: kdanforth@xxxxxxxxxx

 

From: ftpapi-bounces@xxxxxxxxxxxxxxxxxxxxxx <ftpapi-bounces@xxxxxxxxxxxxxxxxxxxxxx> On Behalf Of Jon Paris
Sent: Wednesday, April 7, 2021 18:48
To: FTPAPI/HTTPAPI mailing list <ftpapi@xxxxxxxxxxxxxxxxxxxxxx>
Subject: Re: [Ftpapi] HTTP Headers in REST GET

 

You're building too much into the request Ken - HTTPAAPI will do most of that for you.  Here's a snippet of code that does a very similar thing but using a JWT token for authorization - but you should be able to spot the differences.

 

Most (all?) of what you have put in request should be in the header and HTTPAPI builds that - except for the bit that I added via the addSpecialHeaders procedure. 

 

// Get token and setup for adding additional header etc to request

authorizationToken = 'Bearer ' + GetJWTKey();

 

http_xproc( HTTP_POINT_ADDL_HEADER

             : %paddr(addSpecialHeaders)

             : %addr(authorizationToken) );

 

       + '/participants?page_size=300';   // Get 300 results at a time

 

Monitor;

   response = HTTP_string( 'GET' : url ); 

...

 

EndMon;

 

 

 

Dcl-Proc addSpecialHeaders;

Dcl-Pi *N;

   headersToAdd    Varchar(32767);

   var             like(authorizationToken) const;

End-Pi;

 

Dcl-c  CRLF  x'0d25';

 

   headersToAdd = 'authorization: ' + var + CRLF;

 

End-Proc;

 



On Apr 7, 2021, at 4:56 PM, Danforth, Ken <kdanforth@xxxxxxxxxx> wrote:

 

My RPG code to try to replicate the HTTPGETCLOB previously posted:

 

       Ctl-Opt bnddir( 'LIBHTTP142/HTTPAPI' : 'LIBHTTP142/EXPAT' :

                       'YAJL/YAJL');

       Ctl-Opt option( *srcstmt : *nodebugIO );

 

       /include libhttp142/qrpglesrc,httpapi_h

       /include yajl/qrpglesrc,yajl_h

 

       Dcl-DS responseData Qualified Inz;

         id                      int(10);                  

         created_at              varchar(25);              

         updated_at              varchar(25);             

         site_code               varchar(15);         

         reference               varchar(20);             

         custom_reference        varchar(20);             

         custom_label_printer    varchar(40);             

         special_instructions    varchar(80);             

         despatch_date           Date;                    

         account_payable         varchar(10) ;            

         charge_account          varchar(40) ;            

         carrier_service         varchar(10) ;            

         service_type            varchar(10) ;            

         pickup_at               varchar(25) ;            

         deliver_by              varchar(25) ;            

         deliver_at              varchar(25) ;            

         return_type             varchar(20) ;            

         consignment_number      varchar(30) ;            

         estimated_delivery_date varchar(25) ;            

         actual_delivery_date    varchar(25) ;            

         carrier_name            varchar(30) ;            

         service_name            varchar(30) ;            

         service_code            varchar(10) ;            

         service_rate            varchar(15) ;            

         service_rate_excl_gst   varchar(15) ;            

         poa_carrier             varchar(10) ;            

         cheapest_carrier_service varchar(40) ;         

         cheapest_carrier_rate    varchar(15) ;      

         cheapest_carrier_rate_excl_gst varchar(15) ;

         manifest_id             int(10) ;                

         carrier_selection_by    varchar(40);             

         despatched_at           varchar(25);             

         despatch_by             varchar(40);             

         state                   varchar(20);             

         url                     varchar(100);            

         public_tracking_url     varchar(100);            

         has_quote_origin        varchar(10);             

         has_tickets             varchar(10);             

       End-Ds;

 

       Dcl-S request  Varchar(2000);

       Dcl-S url      Varchar(1000);

       Dcl-S response Varchar(2000);  // Holds web service response

 

           + '21973599';

 

       request = '<HttpHeader>'

               + '<header name="accept" '

               + 'value="application/vnd.public.api.v1+json" /> '

               + '<header name="content-type" value="application/json" /> '

               + '<header name="request" value="application/json" /> '

               + '<header name="authorization" '

               + 'value="Basic ***obscured***" />'

               + '</HttpHeader>';

 

       Monitor;

         response = HTTP_string('GET'

                               :url

                               :request);

 

         Data-Into responseData

                   %Data( response : 'case=any' )

                   %PARSER( 'YAJL/YAJLINTO' );  // Extracted data now in responseData

 

         Dump(a) '**RESULTS***';

 

         On-error;  // If HTTP_string failed for any reason report the error

           Dump(a) '**ERROR***';

       EndMon;

 

       *InLr = *On;

       Return;

 

 

Ken Danforth | Amscan Inc. | Dir - International Business Systems

80 Grasslands Road | Elmsford, NY 10523

O: 914-784-4161 | M: 914-589-3614 | F: 914-784-8819 | E: kdanforth@xxxxxxxxxx

 

From: ftpapi-bounces@xxxxxxxxxxxxxxxxxxxxxx <ftpapi-bounces@xxxxxxxxxxxxxxxxxxxxxx> On Behalf Of Scott Klement
Sent: Wednesday, April 7, 2021 14:06
To: ftpapi@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: [Ftpapi] HTTP Headers in REST GET

 

Hi Ken,

Sure!  Go ahead and post your http_string logic and we'll take a look.

-- 
Scott Klement
sk@xxxxxxxxxxxxxxxx

 

On 4/7/2021 10:32 AM, Danforth, Ken wrote:

[SNIP]


 

 

Can anyone tell me how to format the HTTP_string to work the same as the above HTTPGETCLOB?  Any help is appreciated.  Thanks.

 

 

***************************************************************** *************************************************************************************************************** Legal Disclaimer: The information contained in this message may be privileged and confidential. It is intended to be read only by the individual or entity to whom it is addressed or by their designee. If the reader of this message is not the intended recipient, you are on notice that any distribution of this message, in any form, is strictly prohibited. If you have received this message in error, please immediately notify the sender and delete or destroy any copy of this message. ****************************************************************** ************************************************************************************************************* -- 
_______________________________________________
Ftpapi mailing list
Ftpapi@xxxxxxxxxxxxxxxxxxxxxx
http://scottklement.com/mailman/listinfo/ftpapi

 

***************************************************************** *************************************************************************************************************** Legal Disclaimer: The information contained in this message may be privileged and confidential. It is intended to be read only by the individual or entity to whom it is addressed or by their designee. If the reader of this message is not the intended recipient, you are on notice that any distribution of this message, in any form, is strictly prohibited. If you have received this message in error, please immediately notify the sender and delete or destroy any copy of this message. ****************************************************************** *************************************************************************************************************
-- 
_______________________________________________
Ftpapi mailing list
Ftpapi@xxxxxxxxxxxxxxxxxxxxxx
http://scottklement.com/mailman/listinfo/ftpapi