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

RE: UPS PLD Upload sample



Debra,

Attached is what I use to get rate data from UPS.  Don't know if this will help in what you are doing but thought I would give it a shot.  This one handles both UPS and FEDEX rates.

Eric Hill
Integrated Corporate Solutions
ehill@xxxxxxxxxxxxx
256-760-8239

-----Original Message-----
From: ftpapi-bounces@xxxxxxxxxxxxxxxxxxxxxx [mailto:ftpapi-bounces@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of Debra Abelow
Sent: Tuesday, July 02, 2013 3:29 PM
To: ftpapi@xxxxxxxxxxxxxxxxxxxxxx
Subject: UPS PLD Upload sample

Good Afternoon,
Does anyone have a working example of a UPS PLD upload using Httpapi? Or perhaps some suggestions on how to build the request message.
I have attached the link to the UPS documentation  - see create the request message beginning on page 10.
It seems like they are asking for a stream file using sockets that resembles an HTTP Document with content type equal to multipart/mixed.

http://www.ups.com/uoltools/manifest/pdf/Electronic_Manifesting.pdf

I would appreciate your help.

Thanks,
Debra Abelow
Systems Analyst/Developer III
2915 Weston Road
Weston, FL 33331
1-800-331-ANDA (2632) x 74784
Fax 954-217-4377
Debra.Abelow@xxxxxxxxxxx


     ?*************************************************************
     ?* WEB030 - OE Parts Entry Validation Return Shipping Charges
     ?*************************************************************
     H DEBUG OPTION(*SRCSTMT:*NODEBUGIO)
     H DFTACTGRP(*NO) ACTGRP(*NEW) BNDDIR('HTTPAPI') BNDDIR('QC2LE')
    ??*************************************************************
     Foehdr     if   e           k disk
     Fweb25fl   if   e           k disk
     F/COPY QCPYLESRC,SYCDXF
    ??*************************************************************
     D Parm_List       PR                  ExtPgm('WEB030')
     D  Parm_Order                    8
     D  Parm_Keyin                    7
     D  Parm_Type                     1
     D  Parm_Charge                  10
     D  Parm_Error                   30

     D Parm_List       PI
     D  Parm_Order                    8
     D  Parm_Keyin                    7
     D  Parm_Type                     1
     D  Parm_Charge                  10
     D  Parm_Error                   30

      /copy libhttp/qrpglesrc,httpapi_h

     D StartOfElement  PR
     D   UserData                      *   value
     D   depth                       10I 0 value
     D   name                      1024A   varying const
     D   path                     24576A   varying const
     D   attrs                         *   dim(32767)
     D                                     const options(*varsize)
     D EndOfElement    PR
     D   UserData                      *   value
     D   depth                       10I 0 value
     D   name                      1024A   varying const
     D   path                     24576A   varying const
     D   value                    65535A   varying const
     D   attrs                         *   dim(32767)
     D                                     const options(*varsize)


     D ParseXML        PR
     D   save                          *   value
     D   depth                       10I 0 value
     D   name                      1024A   varying const
     D   path                     24576A   varying const
     D   value                    65535A   varying const
     D   attrs                         *   dim(32767)
     D                                     const options(*varsize)
     D/copy qcpylesrc,ldauds400
     D/copy qcpylesrc,sycdxd

     D                 DS                  INZ
     D inkez                   1      8
     D intype                  1      1
     D indoc#                  2      7  0
     D inbr                    8      8

     D UPS_USERID      C                   'xxxxxxx'
     D UPS_PASSWD      C                   '99999999'
     D UPS_LICENSE     C                   '****************'

     D FDX_KEY         C                   'xxxxxxxxxxxxxxxx'
     D FDX_PASSWD      C                   '9999999999999999999999999'
     D FDX_ACCTNO      C                   '*********'
     D FDX_METER       C                   '$$$$$$$$$'

     D tot_pathu       C                   '/RatingServiceSelectionResponse/Rat-
     D                                     edShipment/TotalCharges'

     D err_pathu       C                   '/RatingServiceSelectionResponse/Res-
     D                                     ponse/Error'

     D tot_pathf       C                   '/SOAP-ENV:Envelope/SOAP-ENV:Body/Ra-
     D                                     teReply/RateReplyDetails/RatedShipme-
     D                                     ntDetails/RatedPackages/PackageRateD-
     D                                     etail/NetCharge'

     D rc              s             10I 0
     D postData        s           4800A   varying
     D soap            s          32767A   varying
     D resp            s          65535A   varying

     D tran_key        s              7  0 inz(0)
     D result          s              5  0 inz(0)

     D Sym             S              1    DIM(4) CTDATA PERRCD(4)
     D err_msg         s            100    inz(' ')
     D x               s              5  0 inz(0)
     D ss              s              5  0 inz(0)
     D total_charges   s             10    inz(' ')

     D error_len       s              5  0 inz(0)

     D hard_error      s              1    inz(' ')

     D from_name       s             30    inz(' ')
     D from_adr1       s             30    inz(' ')
     D from_adr2       s             30    inz(' ')
     D from_city       s             30    inz(' ')
     D from_state      s              5    inz(' ')
     D from_zip        s             15    inz(' ')
     D to_name         s             30    inz(' ')
     D to_adr1         s             30    inz(' ')
     D to_adr2         s             30    inz(' ')
     D to_city         s             30    inz(' ')
     D to_state        s              5    inz(' ')
     D to_zip          s             15    inz(' ')

     D tot_wgt         s              9  3 inz(0)
     D hld_wgt         s              9  3 inz(0)
     D rem_wgt         s              9  3 inz(0)
     D ups_wgt         s              9  3 inz(0)

     D scan_res        s              5  0 inz(0)

     I/copy qcpylesrc,sycdxi
     ?**********************************************************************
      /free

       *in95 = *on;
       inkez = Parm_Order;
       tran_key = %dec(Parm_Keyin:7:0);
       clear tot_wgt;

       chain (udcomp:intype:indoc#:inbr) oehdr;

       if not %found(oehdr);
          parm_error = 'OEHDR record not found';
          *inlr = *on;
          return;
       endif;

       setll (udcomp:tran_key) web25fl;

       dou %eof(web25fl);

          reade (udcomp:tran_key) web25fl;

          if %eof(web25fl);
             iter;
          endif;

          if wbsts = 'C';
             tot_wgt += wbwten;
          endif;

       enddo;

       if tot_wgt = *zero;
          parm_error = 'Total Weight Cannot Be Zero';
          eval *inlr = *on;
          return;
       endif;

       exsr $get_frominfo;

       if hard_error = 'Y';
          parm_error = 'Branch record not found';
          eval *inlr = *on;
          return;
       endif;

       exsr $get_toinfo;

       if hard_error = 'Y';
          parm_error = 'Customer record not found';
          eval *inlr = *on;
          return;
       endif;

       exsr $rmv_symbol;

       select;

          when Parm_Type = 'U' or
               Parm_Type = '1';
             exsr $ups_api;

          when Parm_Type = 'F' or
               Parm_Type = '2';
             exsr $fedex_api;

          other;
             exsr $ups_api;

       endsl;

       *inlr = *on;

    ?  //***********************************************************************
    ?  //*** $get_frominfo - Get Data to Populate From Information           ***
    ?  //***********************************************************************
       begsr $get_frominfo;

          hard_error = 'N';

          sxcomp = oecomp;
          sxnem = 'BR';
          sxrgn = oergn;
          sxcde = oebr;

          chain sxkey sycdx;

          if not %found(sycdx);
             hard_error = 'Y';
             leavesr;
          endif;

          from_name = scbnam;
          from_adr1 = scbad1;
          from_adr2 = scbad2;
          from_city = scbcty;
          from_state = scbst;
          from_zip = scbzip;

          sxnem = 'BRPR';

          chain sxkey sycdx;

          if not %found(sycdx);
             hard_error = 'Y';
             leavesr;
          endif;

       endsr;
    ?  //***********************************************************************
    ?  //*** $get_toinfo - Get Data to Populate To Information               ***
    ?  //***********************************************************************
       begsr $get_toinfo;

          hard_error = 'N';

          if oesnam = '*SAME';
             to_name = oecnam;
             to_adr1 = oecad1;
             to_adr2 = oecad2;
             to_city = oecity;
             to_state = oest;
             to_zip = oezip;
          else;
             to_name = oesnam;
             to_adr1 = oesad1;
             to_adr2 = oesad2;
             to_city = oescty;
             to_state = oesst;
             to_zip = oeszip;
          endif;

       endsr;
    ?  //***********************************************************************
    ?  //*** $rmv_symbol - Remove Special Symbols from Data                  ***
    ?  //***********************************************************************
       begsr $rmv_symbol;

          clear scan_res;

          for ss = 1 to 4;

             dou scan_res = *zero;

                scan_res = %scan(sym(ss):from_name:1);

                if scan_res > *zero;
                   %subst(from_name:scan_res:1) = *blanks;
                endif;

             enddo;

             dou scan_res = *zero;

                scan_res = %scan(sym(ss):from_adr1:1);

                if scan_res > *zero;
                   %subst(from_adr1:scan_res:1) = *blanks;
                endif;

             enddo;

             dou scan_res = *zero;

                scan_res = %scan(sym(ss):from_adr2:1);

                if scan_res > *zero;
                   %subst(from_adr2:scan_res:1) = *blanks;
                endif;

             enddo;

             dou scan_res = *zero;

                scan_res = %scan(sym(ss):from_city:1);

                if scan_res > *zero;
                   %subst(from_city:scan_res:1) = *blanks;
                endif;

             enddo;

             dou scan_res = *zero;

                scan_res = %scan(sym(ss):from_state:1);

                if scan_res > *zero;
                   %subst(from_state:scan_res:1) = *blanks;
                endif;

             enddo;

             dou scan_res = *zero;

                scan_res = %scan(sym(ss):from_zip:1);

                if scan_res > *zero;
                   %subst(from_zip:scan_res:1) = *blanks;
                endif;

             enddo;

             dou scan_res = *zero;

                scan_res = %scan(sym(ss):to_name:1);

                if scan_res > *zero;
                   %subst(to_name:scan_res:1) = *blanks;
                endif;

             enddo;

             dou scan_res = *zero;

                scan_res = %scan(sym(ss):to_adr1:1);

                if scan_res > *zero;
                   %subst(to_adr1:scan_res:1) = *blanks;
                endif;

             enddo;

             dou scan_res = *zero;

                scan_res = %scan(sym(ss):to_adr2:1);

                if scan_res > *zero;
                   %subst(to_adr2:scan_res:1) = *blanks;
                endif;

             enddo;

             dou scan_res = *zero;

                scan_res = %scan(sym(ss):to_city:1);

                if scan_res > *zero;
                   %subst(to_city:scan_res:1) = *blanks;
                endif;

             enddo;

             dou scan_res = *zero;

                scan_res = %scan(sym(ss):to_state:1);

                if scan_res > *zero;
                   %subst(to_state:scan_res:1) = *blanks;
                endif;

             enddo;

             dou scan_res = *zero;

                scan_res = %scan(sym(ss):to_zip:1);

                if scan_res > *zero;
                   %subst(to_zip:scan_res:1) = *blanks;
                endif;

             enddo;

          endfor;

       endsr;
    ?  //***********************************************************************
    ?  //*** $ups_api - Subroutine to Access UPS API                         ***
    ?  //***********************************************************************
       begsr $ups_api;

          if (  %subst(UPS_USERID:1:1) = '<'
             or %subst(UPS_PASSWD:1:1) = '<'
             or %subst(UPS_LICENSE:1:1) = '<' );
               http_comp('You must be registered with UPS! See +
                          comments in EXAMPLE14 member.');
               parm_error = 'UPS Authoritication Error';
               *inlr = *on;
               return;
          endif;

          exsr $ups_setup;

          http_debug(*ON);

          rc = http_url_post_xml('https://wwwcie.ups.com/ups.app/xml/Rate'
                                : %addr(postData) + 2
                                : %len(postData)
                                : %paddr(StartOfElement)
                                : %paddr(EndOfElement)
                                : *NULL );
          if (rc <> 1);
             err_msg = http_error();
             parm_error = %subst(err_msg:1:30);
             *inlr = *on;
             return;
          endif;

          Parm_Charge = total_charges;

       endsr;
    ?  //***********************************************************************
    ?  //*** $ups_setup - Setup UPS XML data                                 ***
    ?  //***********************************************************************
       begsr $ups_setup;

          clear postdata;

          postdata =
             '<?xml version="1.0"?>'                                           +
             '<AccessRequest>'                                                 +
               '<AccessLicenseNumber>'                                         +
                 UPS_LICENSE                                                   +
               '</AccessLicenseNumber>'                                        +
               '<UserId>'                                                      +
                UPS_USERID                                                     +
               '</UserId>'                                                     +
               '<Password>'                                                    +
                UPS_PASSWD                                                     +
               '</Password>'                                                   +
             '</AccessRequest>'                                                +
             '<?xml version="1.0"?>'                                           +
             '<RatingServiceSelectionRequest xml:lang="en-US">'                +
               '<Request>'                                                     +
                 '<TransactionReference>'                                     +
                   '<CustomerContext>Rating and Service</CustomerContext>'    +
                   '<XpciVersion>1.0</XpciVersion>'                           +
                 '</TransactionReference>'                                    +
                 '<RequestAction>Rate</RequestAction>'                        +
                 '<RequestOption>Rate</RequestOption>'                        +
               '</Request>'                                                    +
              '<Shipment>'                                                     +
                '<Description>Rate Description</Description>'                  +
                  '<Shipper>'                                                  +
                    '<CompanyName>'                                            +
                     %TRIM(FROM_NAME)                                          +
                    '</CompanyName>'                                           +
                      '<Address>'                                              +
                        '<AddressLine1>'                                       +
                         %TRIM(FROM_ADR1)                                      +
                        '</AddressLine1>'                                      +
                        '<AddressLine2>'                                       +
                         %TRIM(FROM_ADR2)                                      +
                        '</AddressLine2>'                                      +
                        '<City>'                                               +
                         %TRIM(FROM_CITY)                                      +
                        '</City>'                                              +
                        '<StateProvinceCode>'                                  +
                         %TRIM(FROM_STATE)                                     +
                        '</StateProvinceCode>'                                 +
                        '<PostalCode>'                                         +
                         %TRIM(FROM_ZIP)                                       +
                        '</PostalCode>'                                        +
                        '<CountryCode>US</CountryCode>'                        +
                      '</Address>'                                             +
                  '</Shipper>'                                                 +
                  '<ShipTo>'                                                   +
                    '<CompanyName>'                                            +
                     %TRIM(TO_NAME)                                            +
                    '</CompanyName>'                                           +
                      '<Address>'                                              +
                        '<AddressLine1>'                                       +
                         %TRIM(TO_ADR1)                                        +
                        '</AddressLine1>'                                      +
                        '<AddressLine2>'                                       +
                         %TRIM(TO_ADR2)                                        +
                        '</AddressLine2>'                                      +
                        '<City>'                                               +
                         %TRIM(TO_CITY)                                        +
                        '</City>'                                              +
                        '<StateProvinceCode>'                                  +
                         %TRIM(TO_STATE)                                       +
                        '</StateProvinceCode>'                                 +
                        '<PostalCode>'                                         +
                         %TRIM(TO_ZIP)                                         +
                        '</PostalCode>'                                        +
                        '<CountryCode>US</CountryCode>'                        +
                      '</Address>'                                             +
                  '</ShipTo>';

          exsr $xml_package;

          postdata = %trim(postdata)                                           +
                  '<Service><Code>03</Code></Service>'                         +
              '</Shipment>'                                                    +
             '</RatingServiceSelectionRequest>';

       endsr;
    ?  //***********************************************************************
    ?  //*** $xml_package - Subroutine to Build the XML Package Detail      ***
    ?  //***********************************************************************
       begsr $xml_package;

          clear rem_wgt;
          clear ups_wgt;
          hld_wgt = tot_wgt;

          dou hld_wgt = *zero;

             rem_wgt = hld_wgt - 150;

             if rem_wgt > *zero;
                ups_wgt = 150;
                hld_wgt = rem_wgt;
             else;
                ups_wgt = hld_wgt;
                clear hld_wgt;
             endif;

             postdata = %trim(postdata)                                        +
                  '<Package>'                                                  +
                    '<PackagingType>'                                          +
                      '<Code>02</Code>'                                        +
                      '<Description>Customer Supplied</Description>'           +
                    '</PackagingType>'                                         +
                    '<Description>Rate</Description>'                          +
                    '<PackageWeight>'                                          +
                      '<UnitOfMeasurement>'                                    +
                        '<Code>LBS</Code>'                                     +
                      '</UnitOfMeasurement>'                                   +
                      '<Weight>'                                               +
                       %TRIM(%EDITC(ups_wgt:'3'))                              +
                      '</Weight>'                                              +
                    '</PackageWeight>'                                         +
                  '</Package>';

          enddo;

       endsr;
    ?  //***********************************************************************
    ?  //*** $fedex_api = Subroutine to Acess FedEx API                      ***
    ?  //***********************************************************************
       begsr $fedex_api;

          exsr $fedex_setup;

          http_debug(*ON);
          http_XmlStripCRLF(*ON);

          rc = http_url_post_xml('https://wsbeta.fedex.com:443/web-services'
                                : %addr(soap) + 2
                                : %len(soap)
                                : *NULL
                                : %paddr(ParseXML)
                                : %addr(RESP)
                                : HTTP_TIMEOUT
                                : HTTP_USERAGENT
                                : 'text/xml;charset=UTF-8'
                                : '"track"');

          if (rc <> 1);
             err_msg = http_error();
             parm_error = %subst(err_msg:1:30);
             *inlr = *on;
             return;
          endif;

       endsr;
    ?  //***********************************************************************
    ?  //*** $fedex_setup - Setup FEDEX SOAP data                            ***
    ?  //***********************************************************************
       begsr $fedex_setup;

          clear soap;

          soap =
             '<?xml version="1.0" encoding="iso-8859-1" standalone="no"?>' +
             '<soapenv:Envelope +
                xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"; +
                xmlns:v13="http://fedex.com/ws/rate/v13";> +
                <soapenv:Body> +
                 <v13:RateRequest> +
                  <v13:WebAuthenticationDetail> +
                   <v13:UserCredential> +
                    <v13:Key>' +
                    %TRIM(FDX_KEY)    +
                   '</v13:Key> +
                    <v13:Password>' +
                    %TRIM(FDX_PASSWD) +
                   '</v13:Password> +
                   </v13:UserCredential> +
                  </v13:WebAuthenticationDetail> +
                  <v13:ClientDetail> +
                   <v13:AccountNumber>' +
                   %TRIM(FDX_ACCTNO) +
                  '</v13:AccountNumber> +
                   <v13:MeterNumber>' +
                   %TRIM(FDX_METER) +
                  '</v13:MeterNumber> +
                  </v13:ClientDetail> +
                  <v13:TransactionDetail> +
                   <v13:CustomerTransactionId> +
                    Rate A Package v13</v13:CustomerTransactionId> +
                  </v13:TransactionDetail> +
                  <v13:Version> +
                   <v13:ServiceId>crs</v13:ServiceId> +
                   <v13:Major>13</v13:Major> +
                   <v13:Intermediate>0</v13:Intermediate> +
                   <v13:Minor>0</v13:Minor> +
                  </v13:Version> +
                  <v13:RequestedShipment> +
                   <v13:DropoffType>REGULAR_PICKUP</v13:DropoffType> +
                   <v13:ServiceType>FEDEX_GROUND</v13:ServiceType> +
                   <v13:Shipper> +
                    <v13:Contact> +
                     <v13:CompanyName>' +
                     %TRIM(FROM_NAME) +
                    '</v13:CompanyName> +
                    </v13:Contact> +
                    <v13:Address> +
                     <v13:StreetLines>' +
                     %TRIM(FROM_ADR1) +
                    '</v13:StreetLines>  +
                     <v13:City>' +
                     %TRIM(FROM_CITY) +
                    '</v13:City> +
                     <v13:StateOrProvinceCode>' +
                     %TRIM(FROM_STATE) +
                    '</v13:StateOrProvinceCode>  +
                     <v13:PostalCode>' +
                     %TRIM(FROM_ZIP) +
                    '</v13:PostalCode>  +
                     <v13:CountryCode>US</v13:CountryCode> +
                    </v13:Address> +
                   </v13:Shipper> +
                   <v13:Recipient> +
                    <v13:Contact> +
                     <v13:CompanyName>' +
                     %TRIM(TO_NAME) +
                    '</v13:CompanyName> +
                    </v13:Contact> +
                    <v13:Address> +
                     <v13:StreetLines>' +
                     %TRIM(TO_ADR1) +
                    '</v13:StreetLines>  +
                     <v13:City>' +
                     %TRIM(TO_CITY) +
                    '</v13:City> +
                     <v13:StateOrProvinceCode>' +
                     %TRIM(TO_STATE) +
                    '</v13:StateOrProvinceCode>  +
                     <v13:PostalCode>' +
                     %TRIM(TO_ZIP) +
                    '</v13:PostalCode>  +
                     <v13:CountryCode>US</v13:CountryCode> +
                    </v13:Address> +
                   </v13:Recipient> +
                   <v13:PackageCount>1</v13:PackageCount> +
                   <v13:RequestedPackageLineItems> +
                    <v13:SequenceNumber>1</v13:SequenceNumber> +
                    <v13:GroupNumber>1</v13:GroupNumber> +
                    <v13:GroupPackageCount>1</v13:GroupPackageCount> +
                    <v13:Weight> +
                     <v13:Units>LB</v13:Units> +
                     <v13:Value>12.0</v13:Value> +
                    </v13:Weight> +
                   </v13:RequestedPackageLineItems> +
                  </v13:RequestedShipment> +
                 </v13:RateRequest> +
                </soapenv:Body> +
               </soapenv:Envelope>';

       endsr;
    ?  //***********************************************************************
      /end-free
     ?**************************************************************************
     P StartOfElement  B
     D StartOfElement  PI
     D   UserData                      *   value
     D   depth                       10I 0 value
     D   name                      1024A   varying const
     D   path                     24576A   varying const
     D   attrs                         *   dim(32767)
     D                                     const options(*varsize)
      /free

        if path = '/RateResponse/RatedShipment/RatedPackage/TotalCharges'
                  and name = 'MonetaryValue';
        endif;

      /end-free
     P                 E
     ?**************************************************************************
     P EndOfElement    B
     D EndOfElement    PI
     D   UserData                      *   value
     D   depth                       10I 0 value
     D   name                      1024A   varying const
     D   path                     24576A   varying const
     D   value                    65535A   varying const
     D   attrs                         *   dim(32767)
     D                                     const options(*varsize)
      /free

        if path = err_pathu and name = 'ErrorDescription';

           result = %scan('Address':value);

           if result = *zero;
              result = %scan('address':value);
           endif;

           if result > *zero;
              eval parm_error = 'Invalid Shipping Address';
           else;
              eval parm_error = 'Unable to Calculate Ship Chgs';
           endif;

        endif;

        if path = tot_pathu and name = 'MonetaryValue';
           total_charges = value;
        endif;

      /end-free
     P                 E
     ?**************************************************************************
     P ParseXML        B
     D ParseXML        PI
     D   save                          *   value
     D   depth                       10I 0 value
     D   name                      1024A   varying const
     D   path                     24576A   varying const
     D   value                    65535A   varying const
     D   attrs                         *   dim(32767)
     D                                     const options(*varsize)
      /free

        if path = tot_pathf and name = 'Amount';
           total_charges = value;
        endif;

      /end-free
     P                 E
     ?**************************************************************************
**CTDATA Sym
+&*%
-----------------------------------------------------------------------
This is the FTPAPI mailing list.  To unsubscribe, please go to:
http://www.scottklement.com/mailman/listinfo/ftpapi
-----------------------------------------------------------------------