Convertion of decoded string response from SOAP API to Integer

Zain Rasheed 0 Reputation points
2024-06-17T23:46:09.68+00:00

I am trying to get count of rows through SOAP API. The response is binary 64-bit encoded which is then decoded and replaced with spaces to get only the row count. Problems:

  1. Unable to convert decoded binary string row count into integer. Used int(variable) function but didn't get any result. It gives the error:
    "The function 'int' was invoked with a parameter that is not valid. The value cannot be converted to the target type"
Azure Data Factory
Azure Data Factory
An Azure service for ingesting, preparing, and transforming data at scale.
10,127 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Amira Bedhiafi 19,626 Reputation points
    2024-06-18T07:49:35.8433333+00:00

    Let's assume the decoded string is stored in a variable decoded_string :

    
    import base64
    
    # Sample Base64 encoded string (this should be your actual SOAP response)
    
    encoded_string = "U29tZSBlbmNvZGVkIGJpbmFyeSBzdHJpbmc="
    
    # Step 1: Decode the Base64 string
    
    decoded_bytes = base64.b64decode(encoded_string)
    
    decoded_string = decoded_bytes.decode('utf-8')
    
    # Step 2: Remove unwanted characters (assuming we need only digits)
    
    cleaned_string = ''.join(filter(str.isdigit, decoded_string))
    
    # Step 3: Convert the cleaned string to an integer
    
    try:
    
        row_count = int(cleaned_string)
    
        print("Row count:", row_count)
    
    except ValueError:
    
        print("Error: The cleaned string cannot be converted to an integer.")
    
    

    In ADF, the process is similar but might involve using Data Flow or expressions directly in the pipeline. It would be best if you used the base64ToString() function, the Base64 will decode the response and then clean the string using replace() and trim() functions to remove unwanted characters and convert it to integer using int() .

    
    {
    
      "name": "DecodedRowCount",
    
      "value": "@int(replace(trim(base64ToString(activity('YourActivityName').output.response)), ' ', ''))"
    
    }
    
    
    0 comments No comments