2

The following template returns '' if the Authorization header is not present. How can i get null instead? So return null if key is not present...

{
  "headers" : { 
     "authorization" : "$input.params().header.get('Authorization')" 
  }
}
Rentrop
  • 20,979
  • 10
  • 72
  • 100

1 Answers1

3

You can use #if ($variable) to check if a variable is not null

#if ($variable) 
   ... do stuff here if the variable is not null
#end

In your use case, you can try to put the null check around the authorization header, like this.

{
  "headers" : {
     #if( $input.params().header.get('Authorization').toString() != "" ) 
        "authorization" : "$input.params().header.get('Authorization')" 
     #end
  }
}
Rentrop
  • 20,979
  • 10
  • 72
  • 100
Ka Hou Ieong
  • 5,835
  • 3
  • 20
  • 21