Visa Developer Community

Highlighted
Helper

400: Bad Request : The request could not be completed due to malformed syntax

Hi Friends,

 

I am trying to "update an existing customer profile" , as per the API https://developer.visa.com/capabilities/vctc/reference#vctc__customer_rules_alerts__v1__customer_ale...

 

I have given all the required tags as per API Doc. However geting the error "The request could not be completed due to malformed syntax". I have also used HTTP PATCH (org.apache.http.client.methods.HttpPatchSmiley Wink , as i found "PATCH" verb being used in the API. 

 

Can you help to understand the error?

 

 

2018-08-01 08:16:39 INFO  VisaAPIClient:202 - URI: https://sandbox.api.visa.com/vctc/customerrules/v1/consumertransactioncontrols/customer/CIF003
2018-08-01 08:16:39 INFO  VisaAPIClient:203 - Register A Card
2018-08-01 08:16:39 INFO  VisaAPIClient:207 - RequestBody: {
  "defaultAlertsPreferences" : [ {
    "contactType" : "SMS",
    "contactValue" : "123456789",
    "isVerified" : true,
    "status" : "Active"
  } ],
  "countryCode" : "USA",
  "isProfileActive" : false,
  "firstName" : "Testfirst",
  "lastName" : "Testlast",
  "preferredLanguage" : "en-us"
}
2018-08-01 08:16:40 INFO  VisaAPIClient:175 - Response status : HTTP/1.1 400 Bad Request

2018-08-01 08:16:40 INFO  VisaAPIClient:177 - Response Headers:

2018-08-01 08:16:40 INFO  VisaAPIClient:180 - Server:Apache
2018-08-01 08:16:40 INFO  VisaAPIClient:180 - X-SERVED-BY:l55c014
2018-08-01 08:16:40 INFO  VisaAPIClient:180 - X-CORRELATION-ID:1533082602_591_94_l55c014_VDP_ARM
2018-08-01 08:16:40 INFO  VisaAPIClient:180 - X-Backside-Transport:FAIL FAIL,FAIL FAIL
2018-08-01 08:16:40 INFO  VisaAPIClient:180 - Cache-Control:no-cache, no-store, must-revalidate
2018-08-01 08:16:40 INFO  VisaAPIClient:180 - Expires:-1
2018-08-01 08:16:40 INFO  VisaAPIClient:180 - X-OPNET-Transaction-Trace:a2_c857bd6c-29c8-4a3e-a90f-dad1b8cf00c2
2018-08-01 08:16:40 INFO  VisaAPIClient:180 - Strict-Transport-Security:max-age=31536000; includeSubDomains ,max-age=2592000;includeSubdomains
2018-08-01 08:16:40 INFO  VisaAPIClient:180 - Pragma:no-cache
2018-08-01 08:16:40 INFO  VisaAPIClient:180 - X-Global-Transaction-ID:2937905695
2018-08-01 08:16:40 INFO  VisaAPIClient:180 - X-APP-STATUS:400
2018-08-01 08:16:40 INFO  VisaAPIClient:180 - X-Frame-OptionsSmiley FrustratedAMEORIGIN
2018-08-01 08:16:40 INFO  VisaAPIClient:180 - X-XSS-Protection:1; mode=block
2018-08-01 08:16:40 INFO  VisaAPIClient:180 - X-Content-Type-Options:nosniff
2018-08-01 08:16:40 INFO  VisaAPIClient:180 - Content-Type:application/json;charset=UTF-8
2018-08-01 08:16:40 INFO  VisaAPIClient:180 - Content-Language:en-US
2018-08-01 08:16:40 INFO  VisaAPIClient:180 - Content-Length:122
2018-08-01 08:16:40 INFO  VisaAPIClient:180 - X-Cnection:close
2018-08-01 08:16:40 INFO  VisaAPIClient:180 - X-Cnection:close
2018-08-01 08:16:40 INFO  VisaAPIClient:180 - Date:Wed, 01 Aug 2018 00:16:42 GMT
2018-08-01 08:16:40 INFO  VisaAPIClient:180 - Connection:close
2018-08-01 08:16:40 INFO  VisaAPIClient:181 -
 Response Body:
2018-08-01 08:16:40 INFO  VisaAPIClient:188 - ResponseBody: {
  "metainfo" : {
    "Description" : "Bad Request",
    "Code" : 400
  },
  "error" : "The request could not be completed due to malformed syntax"
}
Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 2.879 sec <<< FAILURE!
testRegisterACard(com.visa.vdp.vctc.TestUpdateProfile)  Time elapsed: 1.907 sec  <<< FAILURE!
java.lang.AssertionError: expected [true] but found [false]
        at org.testng.Assert.fail(Assert.java:94)
        at org.testng.Assert.failNotEquals(Assert.java:513)
        at org.testng.Assert.assertTrue(Assert.java:42)
        at org.testng.Assert.assertTrue(Assert.java:52)
        at com.visa.vdp.vctc.TestUpdateProfile.testRegisterACard(TestUpdateProfile.java:52)


Results :

Failed tests:   testRegisterACard(com.visa.vdp.vctc.TestUpdateProfile): expected [true] but found [false]

Tests run: 1, Failures: 1, Errors: 0, Skipped: 0

4 REPLIES 4
Helper

Re: 400: Bad Request : The request could not be completed due to malformed syntax

I tested same request body with SOAPUI, and it succeeded.

 

If someone has a sample java code for http patch, please help to share.

 

Helper

Re: 400: Bad Request : The request could not be completed due to malformed syntax

Thank you, I solved the problem by adding below lines in VisaAPIClient.java

 

        if (request instanceof HttpPost) {
      ((HttpPost) request).setEntity(new StringEntity(body, "UTF-8"));
  } else if (request instanceof HttpPut) {
      ((HttpPut) request).setEntity(new StringEntity(body, "UTF-8"));
  } else if (request instanceof HttpPatch) {
      ((HttpPatch) request).setEntity(new StringEntity(body, "UTF-8"));
  }

Community Scholar

Re: 400: Bad Request : The request could not be completed due to malformed syntax

Hello forum friend, @Ranjith,

 

Thanks for sharing your solution with us! I enjoyed reading through your forum post today.

 

 

 

Thanks,
Diana

Regular Visitor

Re: 400: Bad Request : The request could not be completed due to malformed syntax

A 400 means that the request was malformed. In other words, the data stream sent by the client to the server didn't follow the rules.

In the case of a REST API with a JSON payload, 400's are typically, and correctly I would say, used to indicate that the JSON is invalid in some way according to the API specification for the service.

By that logic, both the scenarios you provided should be 400's.

Imagine instead this were XML rather than JSON. In both cases, the XML would never pass schema validation--either because of an undefined element or an improper element value. That would be a bad request. Same deal here.