javascriptibm-mobilefirstworklight-adapters

How to filter and get "DisplayName: Ariful" from http adapter response text data


This is my output from adapter

":{
   "data": "{\"CustomerId\":\"1\",\"DisplayName\":\"Ariful\"}",
   "isSuccessful": true
}"

and my HTTP adapter code:

function getUniqueName(UniqueName){
    var input = { 
            method : 'post', 
            path : 'ZIMApi/api/zi/UniqueNameGet/',
            returnedContentType : 'plain',
            headers: {
                      'Content-Type' : 'application/json'
                     }, 
                     body : { 
                        'contentType' : 'application/json',
                        'content' : JSON.stringify({ 
                              'UniqueName' : UniqueName
                                    }
                                )
                        } 
                    };
     var response=WL.Server.invokeHttp(input);
     if (response.statusCode==200 && response.isSuccessful==true){

            var val =response.text

                return {

                    data:val
                }
        }
        else{

            return null
        }
}

Solution

  • Can you change returned Content Type from returnedContentType : 'plain'to returnedContentType : 'json',

    Then

     var response=WL.Server.invokeHttp(input);
    
     if (response.statusCode==200 && response.isSuccessful==true){
    
                    var val =response.DisplayName;
    
                        return {
    
                            data:val
                        }
                }
                else{
    
                    return null
                }