Announcement

Collapse
No announcement yet.

Passing JSON Data and Basic Authorization getting error

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Passing JSON Data and Basic Authorization getting error

    Hi,

    i have below code but not working and giving error. see error below the code

    Code:
    <MvASSIGN NAME = "l.url" VALUE = "http://api.sandbox.ewaypayments.com/Transaction">
    <MvASSIGN NAME = "l.header" VALUE = "Content-Type: application/json">
    <MvCAPTURE VARIABLE = "l.json">
    {"Customer":{"TokenCustomerID":null,"Reference":"A12345","Title":"Mr.","FirstName":"John","LastName":"Doe","CompanyName":"WEB ACTIVE","JobDescription":"Developer","Street1":"15 Smith St","Street2":null,"City":"Phillip","State":"ACT","PostalCode":"2602","Country":"au","Email":"","Phone":"1800 10 10 65","Mobile":"1800 10 10 65","Comments":"Some comments here","Fax":"02 9852 2244","Url":"http:\/\/www.yoursite.com","CardDetails":{"Name":"TestUser","Number":"4444333322221111","ExpiryMonth":"05","ExpiryYear":"15","StartMonth":"","StartYear":"","IssueNumber":"22","CVN":"123"}},"ShippingAddress":{"FirstName":"John","LastName":"Doe","Street1":"9\/10 St Andrew","Street2":" Square","City":"Edinburgh","State":"","Country":"gb","PostalCode":"EH2 2AF","Email":"[email protected]","Phone":"0131 208 0321","ShippingMethod":"LowCost"},"Items":[{"SKU":"SKU1","Description":"Description1","Quantity":null,"UnitCost":null,"Tax":null,"Total":null},{"SKU":"SKU2","Description":"Description2","Quantity":null,"UnitCost":null,"Tax":null,"Total":null}],"Options":null,"Payment":{"TotalAmount":"100","InvoiceNumber":"Inv 21540","InvoiceDescription":"Individual Invoice Description","InvoiceReference":"513456","CurrencyCode":"USD"},"Method":"ProcessPayment","TransactionType":"Purchase","CustomerIP":"127.0.0.1","DeviceID":"eWAY-php-1.2","PartnerID":null}
    </MvCAPTURE>
    <MvASSIGN NAME = "l.userPassEncoded" VALUE = "{crypto_base64_decode('api:apipassword')}">
    <MvCALL METHOD          = "POST"
            ACTION          = "{l.url}"
            HEADERS         = "{'Authorization: Basic ' $ l.userPassEncoded $ asciichar( 13 ) $ asciichar( 10 ) $ l.header $ asciichar( 13 ) $ asciichar( 10 )}"
            FIELDS          = "l.json">
        <MvEVAL EXPR = "{ s.callreturnheader1}"><br/>
    	<MvEVAL EXPR = "{ s.callreturnheader2}"><br/>
    	<MvEVAL EXPR = "{ s.callreturnheader3}"><br/>
    	<MvEVAL EXPR = "{ s.callreturnheader4}"><br/>
    	<MvEVAL EXPR = "{ s.callreturnheader5}"><br/>
    	<MvEVAL EXPR = "{ s.callreturnheader6}"><br/>
    	<MvEVAL EXPR = "{ s.callreturnheader7}"><br/>
    	<MvEVAL EXPR = "{ s.callreturnheader8}"><br/>
    	<MvEVAL EXPR = "{ s.callreturnheader9}"><br/>
    </MvCALL>
    Getting Error:

    HTTP/1.1 400 Bad Request
    Cache-control: no-cache="set-cookie"
    Content-Type: text/html; charset=us-ascii
    Date: Sat, 16 May 2015 23:06:28 GMT
    Server: Microsoft-HTTPAPI/2.0
    Set-Cookie: AWSELB=8361C96B088FEBBC7D3ABDFE8BA0FF6501B9705E7D0 2FB0E46BA8D67B7A800B44A7D2ED0D94C6B4D750DDAD028ED5 C0787DEB1569FF96BD73CDCF09B6E3F354EB31B6537F6;PATH =/;MAX-AGE=86400
    Content-Length: 339
    Connection: Close


    Can someone help into this.

    #2
    Re: Passing JSON Data and Basic Authorization getting error

    I wonder if the VM is generating a second Content-type header, in addition to the one you wrote? I had a similar problem recently. It took MONTHS to debug because the remote server was giving us a misleading error message. You might try METHOD="RAW" and see if that works better.
    Kent Multer
    Magic Metal Productions
    http://TheMagicM.com
    * Web developer/designer
    * E-commerce and Miva
    * Author, The Official Miva Web Scripting Book -- available on-line:
    http://www.amazon.com/exec/obidos/IS...icmetalproducA

    Comment


      #3
      Re: Passing JSON Data and Basic Authorization getting error

      I've done this with a REST service, and it looked different than yours.

      With MvCALL, Method = 'RAW', Content-Type = 'application-json' (instead of using the header), Headers = l.header (see below).

      <MvASSIGN NAME="l.header" VALUE="{ 'Authorization: Basic ' $ crypto_base64_encode( l.api $ ':' $ l.apipassword ) $ asciichar( 13 ) $ asciichar( 10 ) }">

      I think if you use the CONTENT-TYPE parameter in MvCALL as well as using METHOD of RAW, it may work.
      Gordon Currie
      Phosphor Media - "Your Success is our Business"

      Improve Your Customer Service | Get MORE Customers | Edit Any Document Easily | Free Modules | Follow Us on Facebook
      phosphormedia.com

      Comment

      Working...
      X