How do I extract a variable from XML using Postman?

后端 未结 3 511
灰色年华
灰色年华 2021-01-04 02:10

I\'m trying to extract a SessionId from the XML which is returned from a SOAP API.

I\'ve read through the Postman documentation (several times over) but it wasn\'t t

3条回答
  •  鱼传尺愫
    2021-01-04 02:39

    Postman v7.20.1

    I'd like to add my answer since above there are a couple of details that took me a while to solve:

    • how to cope with a multipart SOAP response
    • how to manage a JSON object
    • responseBody definition

    Here's the first lines of my XML response to analyze:

    ------=_Part_694527_1470506002.1584708814081
    Content-Type: application/xop+xml;charset=UTF-8;type="text/xml"
    Content-Transfer-Encoding: 8bit
    Content-ID: 
    
        
        
            
            
                
                    
                        
                            1
                            CHECKIN_UNIVERSAL
    

    After I noticed it was a multipart I've ended up with this Postman Test:

    var response = pm.response.text();
    var responseBody = response.substr(response.indexOf(' {
        if (field.name == 'StatusMessage'){
            console.log("Field = " + field.name);
            pm.expect(field.text().to.include("Successfully checked in"));
            }
        }); 
    });
    

提交回复
热议问题