bashcurlbash4

illegal character found in url


I'm trying to extract data from an api with different ids stored in a text file but i keep getting the message "curl(3): illegal character found in url".

the text file contains:

362ae-235sa-3h26g-136gr
652ae-290sa-3h26g-132gr
394ae-275sa-k726g-106gr
362ae-257sa-3le0g-136gr

My script:

for j in $(cat ids.json)    
do
    curl -u "$workspace_username":"$workspace_password" \
         "https://gateway.watsonplatform.net/assistant/api/v1/workspaces/$j/logsversion=2018-07-10" \
     | jq '.' | jq -r '.logs[]' >> test.json
    sleep 3
done

I'm new to this. Can anyone please help me with the script?


Solution

  • I could reproduce your problem with a CR attached to a line in the file ids.json. I just can assume that this is also your problem. I propose to fix your file.

    You can do that automatically by removing all characters which are not part of your ids which are supposed to be in this file:

    sed -i 's/[^0-9a-z-]//g' ids.json