Forum Discussion

ranujn's avatar
ranujn
Contributor
6 years ago

How to get Endpoint from the Request

I wanna to get full Endpoint from the request. I passing endpoints dynamically for each step that I need to record it. I tried below options to get complete url (Constant one + dynamically passed) ...
  • avidCoder's avatar
    avidCoder
    6 years ago

    ranujn 

     

    You gave me this response right?

     

    {
    "data" : {
    "token" : "sidayf8r4jhrdsuf97adif09rujkfhw.8regiu6sy9s7d6fsa87s87439ykhkhfjdsbfsdf"
    }
    }

    And I provided the code based on that. If you are getting the error. In that case, "data" attribute is not there in your response. You can pass the reponse to JsonSlurper. please ad few more lines of code:-

     

     

     

    import groovy.json.JsonSlurper
    
    def slurper = new groovy.json.JsonSlurper()
    def response = context.expand('${API_Name#Response}') def slurp = slurper.parseText(response)
    def token = slurp.data.token //Considering "data" and "token" as JSON attributes.