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

Re: [Ftpapi] HTTP Headers in REST GET



If you have the YAJL library then they are described in the ..._H source file.   Sorry on a plane and can't easily check the full name.

If you look at authory.com/jonparisandSusanGanter and select JSON you'll see the stuff I've written on the topic.


Jon


On Apr 21, 2021, at 11:20 AM, Danforth, Ken <kdanforth@xxxxxxxxxx> wrote:

Thanks, again.
 
Where can I find documentation on the YAJL APIs and all the processing options?
 
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: Tuesday, April 20, 2021 19:57
To: FTPAPI/HTTPAPI mailing list <ftpapi@xxxxxxxxxxxxxxxxxxxxxx>
Subject: Re: [Ftpapi] HTTP Headers in REST GET
 
Yes - there seems to be a lot of that about ... thanks for the reminder i need to talk to IBM about this scenario.
 
In the meantime - I have clients who use the raw YAJL APIs to drill down and see what format they have i.e. is return_info null and only do the full DATA-INTO if you have something to process.  
 
Best I can suggest right now unless Scott has been inspired.
 
 
Jon


On Apr 20, 2021, at 3:42 PM, Danforth, Ken <kdanforth@xxxxxxxxxx> wrote:
 
Thanks, Jon.  Your site was instrumental to getting my DATA-INTO working with the YAJL parser.  I have one niggling issue that I can’t seem to figure out…
 
Nested in the JSON response is an object called “return_info”.  This can come in one of following two flavors:
 
If there is no return information:
“return_info”:null
 
If there is return information:
“return_info”:
{
“id”:12345678,
“third_party”:false,
“contact_name”:”Someone Special”,
“email”:”me@xxxxxxxxx
}
 
If I code a nested DS to match the return info, YAJL returns an error if the return info is null.  Any idea how I can handle this?
 
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 14, 2021 12:20
To: FTPAPI/HTTPAPI mailing list <ftpapi@xxxxxxxxxxxxxxxxxxxxxx>
Subject: Re: [Ftpapi] HTTP Headers in REST GET
 
Glad it was useful.
 
Data-Gen is pretty simple - only an issue if you need to have different names for the JSON elements than the RPG versions. i.e. the reverse effect to case=convert on the DATA-INTO side.
 
I have a couple fo articles covering the basics,  You can find them on my Authory site in the JSON collection.  
 
 
 
Jon



On Apr 14, 2021, at 11:56 AM, Danforth, Ken <kdanforth@xxxxxxxxxx> wrote:
 
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
 
***************************************************************** *************************************************************************************************************** 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

-- 
_______________________________________________
Ftpapi mailing list
Ftpapi@xxxxxxxxxxxxxxxxxxxxxx
http://scottklement.com/mailman/listinfo/ftpapi