8 Replies Latest reply on Oct 16, 2017 7:58 AM by Tayyab Hussain

    Passing XML code to Get Repose from API using Coldfusion

    Tayyab Hussain Level 1

      I had the following PHP code that posts XML data and retrieves the status as successful post or not This is a valid code and running fine using PHP. This code was sent by the company to test the api, but as the development is done using ColdFusion I wrote a code, given below in ColdFusion, Its sends an OK response but returns an error code as per behavior or the API.

       

      PHP Code:

       

      <?php
      define
      ('blueEx', "http://benefit.blue-ex.com/api/post.php");
      $xml
      = '<?xml version="1.0" encoding="utf-8"?>
      <BenefitDocument>
      <AccessRequest>
      <DocumentType>1</DocumentType>
      <TestTransaction>Y</TestTransaction>*For Testing purpose, after testing leave it blank
      <ShipmentDetail>
        
      <ShipperName></ShipperName>
        
      <ShipperAddress></ShipperAddress>
        
      <ShipperContact></ShipperContact>
        
      <ShipperEmail></ShipperEmail>
        
      <ConsigneeName>Tayyab</ConsigneeName>
        
      <ConsigneeAddress>202-N,DHA,Lahore</ConsigneeAddress>
        
      <ConsigneeContact>03004306499</ConsigneeContact>
        
      <ConsigneeEmail>fusioner@gmail.com</ConsigneeEmail>
        
      <CollectionRequired>Y</CollectionRequired>
        
      <ProductDetail>Some Product</ProductDetail>
        
      <ProductValue>200</ProductValue>
        
      <OriginCity>ISB</OriginCity>
        
      <DestinationCountry>PK</DestinationCountry>
        
      <DestinationCity>LHE</DestinationCity>
        
      <ServiceCode>BG</ServiceCode>
        
      <ParcelType>P</ParcelType>
        
      <Peices>1</Peices>
        
      <Weight>1</Weight>
        
      <Fragile>N</Fragile>
        
      <ShipperReference>9010191</ShipperReference>
        
      <InsuranceRequire>N</InsuranceRequire>
        
      <InsuranceValue></InsuranceValue>
        
      <ShipperComment>xxxx</ShipperComment>
      </ShipmentDetail>
      </AccessRequest>
      </BenefitDocument>';
      $c = curl_init(); 
        curl_setopt($c, CURLOPT_URL, blueEx );
        curl_setopt($c, CURLOPT_RETURNTRANSFER, 1 );
        curl_setopt($c, CURLOPT_USERPWD, "sphere.technologies:sphere.tech");
        curl_setopt($c, CURLOPT_POST, 1 );
        curl_setopt($c, CURLOPT_POSTFIELDS, array('xml'=>$xml) );
        curl_setopt($c, CURLOPT_HTTPHEADER, array('Content-Type=application/soap+xml', 'charset=utf-8'));
        $result = curl_exec ($c);
        $xres = simplexml_load_string($result);
        $st = $xres->status;
        $no = $xres->message;

        echo $st . ' - ' . $no;
      ?>

       

      ColdFusion Code

       

      <cfset objCFHttpProperties = {
        
      Useragent = "#CGI.http_user_agent#",
        
      Username = "sphere.technologies",
        
      Password = "sphere.tech"
        }
      />
      <cfxml variable="xmlString">
        
      <BenefitDocument>
        
      <AccessRequest>
        
      <DocumentType>1</DocumentType>
        
      <TestTransaction>Y</TestTransaction>
        
      <ShipmentDetail>
        
      <ShipperName></ShipperName>
        
      <ShipperAddress></ShipperAddress>
        
      <ShipperContact></ShipperContact>
        
      <ShipperEmail></ShipperEmail>
        
      <ConsigneeName>Tayyab</ConsigneeName>
        
      <ConsigneeAddress>202-N,DHA,Lahore</ConsigneeAddress>
        
      <ConsigneeContact>03004306499</ConsigneeContact>
        
      <ConsigneeEmail>fusioner@gmail.com</ConsigneeEmail>
        
      <CollectionRequired>Y</CollectionRequired>
        
      <ProductDetail>Some Product</ProductDetail>
        
      <ProductValue>200</ProductValue>
        
      <OriginCity>ISB</OriginCity>
        
      <DestinationCountry>PK</DestinationCountry>
        
      <DestinationCity>LHE</DestinationCity>
        
      <ServiceCode>BG</ServiceCode>
        
      <ParcelType>P</ParcelType>
        
      <Peices>1</Peices>
        
      <Weight>1</Weight>
        
      <Fragile>N</Fragile>
        
      <ShipperReference>9010191</ShipperReference>
        
      <InsuranceRequire>N</InsuranceRequire>
        
      <InsuranceValue></InsuranceValue>
        
      <ShipperComment></ShipperComment>
        
      </ShipmentDetail>
        
      </AccessRequest>
      </BenefitDocument>
      </cfxml>
      <cfhttp url="http://benefitx.blue-ex.com/api/post.php" method="post" result="result" attributecollection="#objCFHttpProperties#">
        
      <cfhttpparam type="header" name="Content-Type" value="application/soap+xml"/>
        
      <cfhttpparam type="xml" name="xmlString" value="#xmlString#" />
      </cfhttp>
      <cfdump var="#result#">

       

      But this code returns the error Status

      I've been trying to resolve the issue but cannot come to resolve. Can Someone Help, where I went wrong.

       

      Thanks