import script returns html in stead of json when using eve-ng api

Before posting something, READ the changelog, WATCH the videos, howto and provide following:
Your install is: Bare metal, ESXi, what CPU model, RAM, HD, what EVE version you have, output of the uname -a and any other info that might help us faster.

Moderator: mike

Post Reply
noorderpoort
Posts: 2
Joined: Tue Sep 05, 2023 6:34 pm

import script returns html in stead of json when using eve-ng api

Post by noorderpoort » Tue Sep 05, 2023 8:17 pm

CPU: Intel Xeon CPU E5-2620 v3 2.40Ghz
Cores: 12 cores per socket
Eve: Eve-Ng Professional running in Kvm VM on baremetal Proxmox
VT-X: VT-X is enabled

Image: no image involved
Permissions: not applcable as far as I know
File format: html/json
Logs: Contains no info regarding api calls


I'm trying to automate user- and lab management.

Therefore I wrote a script with the following content to import a comma separated userfile:

Code: Select all

#!/bin/bash

while IFS="," read -r username name email password role expiration pod pexpiration
do


        curl -s -b /tmp/cookie -c /tmp/cookie -X POST -d '{"username":"admin","password":"eve"}' http://127.0.0.1/api/auth/login | jq
        curl -s -c /tmp/cookie -b /tmp/cookie -X POST -d '{"path":"/opt/unetlab/labs","name":"Workspace_$username"}' -H 'Content-type: application/json' http://127.0>
        curl -s -c /tmp/cookie -b /tmp/cookie -X POST -d '{"username":"$username","name":"$name","email":"$email","password":"$password","role":"$role","expiration":>

done < <(tail -n +2 sampledata)

The curl commands are respectively meant to login as admin, create a folder for a specific user and finally add the user to the eve-ng database.
All commands are closed with jq. Jq will parse the result as json.

My problem is that executing the curl command does not yield json format but html.

Image:
Image


I tried to execute the commands without piping to jq.
I also tried to check if the system is able to return json text. Running `jq .user user.json` actually returns the username, so json is working.

noorderpoort
Posts: 2
Joined: Tue Sep 05, 2023 6:34 pm

Re: import script returns html in stead of json when using eve-ng api

Post by noorderpoort » Wed Sep 06, 2023 9:52 pm

So the solution was to add a "-k" and https to the curl command:

Old (works for http):

Code: Select all

curl -s -b /tmp/cookie -c /tmp/cookie -X POST -d '{"username":"admin","password":"eve"}' http://127.0.0.1/api/auth/login | jq
New (works for https)

Code: Select all

 curl -s -k -b /tmp/cookie -c /tmp/cookie -X POST -d '{"username":"admin","password":"eve"}' https://127.0.0.1/api/auth/login | jq 
I tested the commands on a http machine but the staging server works with TLS over cloudflared argo tunnel.

Post Reply