0

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?

Alfe
  • 56,346
  • 20
  • 107
  • 159
  • "I'm trying to extract data from an api with different ids stored in a json file" what does that mean? Your question is poorly worded. – Red Cricket Aug 30 '18 at 07:56
  • "362ae-235sa-3h26g-136gr 652ae-290sa-3h26g-132gr 394ae-275sa-k726g-106gr 362ae-257sa-3le0g-136gr" doesn't looks like valid JSON file – Samuel Aug 30 '18 at 07:56
  • I cannot reproduce the problem. When I try it (without the `-u` of course because I don't have your credentials), I get the proper 401 error (Not Authorized), so the URL itself seems to be correct. Maybe you have a strange character somewhere in the `ids.json` file? Maybe a CR or sth similar? I would propose to recreate this file and try the new version. – Alfe Aug 30 '18 at 08:00
  • what is `jq`? Whatever it is, it is probably causing your problem. Everything else looks fine. – Red Cricket Aug 30 '18 at 08:02
  • `jq` is a tool for manipulating json and doesn't curl anything. So that's very unlikely to be the problem. – Alfe Aug 30 '18 at 08:07

1 Answers1

0

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
Alfe
  • 56,346
  • 20
  • 107
  • 159