Error while passing parameters in Rest Api Azure Data Factory

Shivoy Thakral 0 Reputation points
2024-04-18T20:32:16.1433333+00:00

Hi Folks. Hope you Are doing well. I am passing parameters from one data factory to another to trigger a copy activity that would copy data from an intermediate Location to a final Target which can be an SFTP, Mshare or ADLS location. I am trying to pass a host name in the body of the Rest Api which looks somewhat like "\\abcdefgh\uxyz$". This value is in a json and I extract this from the SQL configs and process it to send in the call itself. However - ADF is throwing an error for this case saying "Invalid Literal" of Invalid escape sequence - and fails to send this parameter causing the REST API activity to fail. I have tried a lot of things however I am unable to pass this value in that API call. The whole pipeline is working effectively - please can anyone help me with this error ?. Do I make changes in the header of the API call or is there an ADF unction to properly encode this value so that the API call can work and pass the parameters - this would enable the other ADF to connect to the source location and copy the data. Any help would be appreciated - running on a strict timeline.

Azure Data Factory
Azure Data Factory
An Azure service for ingesting, preparing, and transforming data at scale.
9,583 questions
{count} votes

1 answer

Sort by: Most helpful
  1. phemanth 5,830 Reputation points Microsoft Vendor
    2024-04-22T07:00:45.0033333+00:00

    @Shivoy Thakral

    The sequence "\ugdp$" is not a valid escape sequence in JSON. It seems there might be a typo or a character encoding issue.

    Solutions:

    1. Verify the Actual Hostname:
      • Double-check the source of the hostname value (connection_json from "Get Non-Zip Configurations").
      • Ensure there are no typos or extra characters in the actual hostname. It should be something like "\atlnetast004\uxyz$" (assuming "uxyz" is the correct value).
    2. Handle Encoding Issues (if applicable):
      • If the source data containing the hostname has a different encoding than UTF-8, you might need to convert it before using it in the JSON body.
      • Azure Data Factory offers functions like convertToString with appropriate encoding options to handle this.
    3. Remove Unnecessary Escape Sequence (if applicable):
      • If "\u" is not intended as an escape sequence, simply remove it from the hostname value before constructing the JSON.

    Here are two possible approaches depending on the cause:

    Scenario 1: Typo or Extra Characters

    • If the issue is a typo or extra characters, correct the value in the source data (connection_json).
    • This ensures the correct hostname is used in the JSON body without any invalid escape sequences.

    Scenario 2: Encoding Issue

    • If there's an encoding issue, use convertToString in ADF to convert the source data to UTF-8 before accessing the hostname:
    'host': '@{convertToString(activity('Get Non-Zip Configurations').output['firstRow']['connection_json'], 'UTF-8')['host_name']}'
    

    Remember to test your changes thoroughly after implementing one of these solutions.

    By addressing the root cause of the invalid escape sequence, you should be able to successfully pass the correct hostname with backslashes in your ADF REST API call.