Reply
Highlighted
Member
Posts: 6
Registered: ‎03-24-2020

cfhttp with JSON error message - invalid child element 'name'

I am using Accept.js. Attempting to POST createTransactionRequest. I keep getting the errror:

 

The element 'merchantAuthentication' in namespace 'AnetApi/xml/v1/schema/AnetApiSchema.xsd' has invalid child element 'name' in namespace 'AnetApi/xml/v1/schema/AnetApiSchema.xsd'. List of possible elements expected: 'mobileDeviceId' in namespace 'AnetApi/xml/v1/schema/AnetApiSchema.xsd'.

 

I've carefully checked my JSON and I believe it's correct. Here's my code:

 

<!--- Create the transaction request --->
<cfset var transRequest = StructNew()>
<cfscript>
    transRequest = {
        "createTransactionRequest": {
            "merchantAuthentication": {
                "name""#AN_MERCHANT_NAME#",
                "transactionKey""#AN_TRANSACTION_KEY#"
            },
            "refId""#refId#",
            "transactionRequest": {
                "transactionType""authCaptureTransaction",
                "amount""#amount#",
                "payment": {
                    "opaqueData": {
                        "dataDescriptor""#dataDescriptor#",
                        "dataValue""#dataValue#"
                    }
                }
            }
        }
    };
</cfscript>
<cfset transRequestJSON = SerializeJSON(transRequest)>
 
<cfhttp url="#AN_URL#" method="post" result="postResult" timeout="30">
    <cfhttpparam type="header" name="Content-Type" value="application/json" />
    <cfhttpparam type="body" value="#transRequestJSON#">
</cfhttp>
<cfset var postResultJSON=DeserializeJSON(postResult.FileContent)>
 
<cfdump var="#postResultJSON#">
 
'mobileDeviceId' Isn't even in createTransactionRequest.
 
What is going wrong?
 

 

Highlighted
Member
Posts: 6
Registered: ‎03-24-2020

Re: cfhttp with JSON error message - invalid child element 'name'

I'm trying this with Postman and gettting the same results.

 

POST to: https://apitest.authorize.net/xml/v1/request.api

Body: "raw", "JSON"

 

{

    "createTransactionRequest": {
          "merchantAuthentication": {
          "transactionKey": "xxxxxxxxxxxxxxxx",
          "name": "xxxxxxxxxxxx"
        },
        "refId": "FE3-839F030E27EEE7A4",
        "transactionRequest": {
            "payment": {
                "opaqueData": {
                    "dataDescriptor": "COMMON.ACCEPT.INAPP.PAYMENT",
                    "dataValue": "eyJ0b2tlbiI6Ijk1ODg5NDEzMDU4NzY5NDE5MDQ2MDIiLCJ2IjoiMS4xIn0="
                }
            },
            "amount": 10,
            "transactionType": "authCaptureTransaction"
        }
    }
}

 

Same result:

{
    "messages": {
        "resultCode""Error",
        "message": [
            {
                "code""E00003",
                "text""The element 'merchantAuthentication' in namespace 'AnetApi/xml/v1/schema/AnetApiSchema.xsd' has invalid child element 'name' in namespace 'AnetApi/xml/v1/schema/AnetApiSchema.xsd'. List of possible elements expected: 'mobileDeviceId' in namespace 'AnetApi/xml/v1/schema/AnetApiSchema.xsd'."
            }
        ]
    }
}

 

Highlighted
Member
Posts: 6
Registered: ‎03-24-2020

Re: cfhttp with JSON error message - invalid child element 'name'

Interesting. I changed the request to use XML (with Postman). And it works.

 

So, it would appear I am doing something wrong with JSON. (?)

Highlighted
Posts: 459
Topics: 0
Kudos: 92
Blog Posts: 0
Ideas: 0
Solutions: 36
Registered: ‎04-28-2017

Re: cfhttp with JSON error message - invalid child element 'name'

With JSON, it will fail with that error message just by having the "name" and "transactionKey" in the wrong order. Try:

{
"createTransactionRequest": {
"merchantAuthentication": {
"name": "API_Login",
"transactionKey": "Transaction_key"

}

 

Powered by NexWebSites.com -
Certified Authorize.net developers
Highlighted
Member
Posts: 6
Registered: ‎03-24-2020

Re: cfhttp with JSON error message - invalid child element 'name'

I had seen comments about JSON order in other threads. I changed the order to match. Same result.