Reputation: 1673
I have a pipeline in ADF that goes to a REST API endpoint which returns a string enclosed in double quotes ("). It looks like this: "xyz123fj=="
What I'm trying to do is store the string value in a variable called AuthKey
. Originally I just stored it "as is" but the pipeline failed with the following error: The variable 'AuthKey' of type 'String' cannot be initialized or updated with value of type 'Object'. The variable 'AuthKey' only supports values of types 'String'.
So naturally I thought I would try converting to a string like this: string(@activity('Get Token').output)
which actually allows the variable to be stored successfully, but the next step fails with the message: Error calling the endpoint 'https://<xxxxxx.com/APIendpoint>'. Response status code: ''. More details:Exception message: 'The format of value 'string(@activity('Get Token').output)' is invalid.'. No response from the endpoint. Possible causes: network connectivity, DNS failure, server certificate validation or timeout.
Which I suspect means that it didn't actually store the original 'xyz123fj=='
string, but rather the unevaluated function itself as a string (so it stored string(@activity('Get Token').output)
which is invalid when sent to the API.
I also tried @string(activity('Get Token').output)
which resulted in a slightly different error message of: More details:Exception message: 'The format of value '{"Response":"\"xyz123fj==\"","ADFWebActivityResponseHeaders":{"Pragma":"no-cache","Strict-Transport-Security":"max-age=31536000","X-Absorb-Correlation-Id":"c937fab2-3e6c-4d92-8b28-5375fb2d5721","X-Content-Type-Options":"nosniff","X-Frame-Options":"SAMEORIGIN","X-LMS-Server":"USE1-PRD-WEB-A3","X-Response-For":"/api/Rest/v1/Authenticate","X-XSS-Protection":"1; mode=block","Connection":"keep-alive","Cache-Control":"no-cache","Date":"Mon, 03 May 2021 15:53:01 GMT","Content-Length":"178","Content-Type":"application/json; charset=utf-8","Expires":"-1"},"effectiveIntegrationRuntime":"DefaultIntegrationRuntime (East US)","executionDuration":0,"durationInQueue":{"integrationRuntimeQueue":0},"billingReference":{"activityType":"ExternalActivity","billableDuration":[{"meterType":"AzureIR","duration":0.016666666666666666,"unit":"Hours"}]}}' is invalid.'. No response from the endpoint.
In the last example, it looks like the step that is using the variable is receiving the full output object from the "Set variable" activity rather than just the simple string as intended. Any insight as to what I'm doing wrong here would be much appreciated.
I also tried only trimming the single quotes (so no string conversion function), but couldn't get that to work either. All I'm trying to do is store this string by itself :(
Upvotes: 1
Views: 4868
Reputation: 6043
You should use @replace(activity('Get Token').output.Response,'"','')
expression, backslash is an escape character in ADF.
Upvotes: 1
Reputation: 986
You should just be able to write @activity('Get Token').output.Response
in the assignement of your variable
It seems like your Response value is enclosed in double-quotes so you may have to do this instead to strip the quotes: @replace(activity('Get Token').output.Response,'\"','')
activity('Get Token').output is type object - this is why the first error occurs (you cannot assign it to a string variable).
In the second case, your expression has to start with @ to be interpreted as such.
In the final case you are sending the entire output from the REST activity (which you can see in the monitor) as the token, which has a format the endpoint doesn't expect.
Upvotes: 1