How to write shell script on website login

43 views Asked by At

I already written shell script but its exactly not working getting empty response it should first return token and also it should login then registry API

thats my task of shell script has to do

#!/bin/bash
# Begin

TEMP=$(getopt -n "$0" -a -l "base_url:,auth0_url:,register_url:,username:,password:,openapi_spec:,base_path:,label:,test_email:" -- -- "$@")

[ $? -eq 0 ] || exit

eval set -- "$TEMP"

while [ $# -gt 0 ]; do
    case "$1" in
        --base_url) BASE_URL="$2"; shift ;;
        --auth0_url) AUTH0_URL="$2"; shift ;;
        --register_url) REGISTER_URL="$2"; shift ;;
        --username) TEST_USER="$2"; shift ;;
        --password) TEST_PWD="$2"; shift ;;
        --openapi_spec) OPENAPI_SPEC="$2"; shift ;;
        --base_path) BASEPATH_SPEC="$2"; shift ;;
        --label) LABEL="$2"; shift ;;
        --test_email) TEST_EMAIL="$2"; shift ;;
        --) shift ;;
    esac
    shift
done

# Set defaults for configurable options
BASE_URL=${BASE_URL:-"https://dev.cloudnetwork.in"}
AUTH0_URL=${AUTH0_URL:-"https://dev-yxxxxxxx1.us.auth0.com"}
REGISTER_URL=${REGISTER_URL:-"https://dev.cloudnetwork.in/apis/register"}


#f [ "$BASE_URL" = "" ];
#then
#    BASE_URL="https://dev.cloudnetwork.in"
#fi


echo " "
token=$(curl -s -H "Content-Type: application/json" -X POST -d '{"username": "'${TEST_USER}'", "password": "'${TEST_PWD}'"}'  ${AUTH0_URL}/login ${BASE_URL}/login ${REGISTER_URL}/login | jq -r .token)

echo "generated token is:" $token

echo " "

data=$(curl -k -s -H "Accept: application/json" -H "Content-Type: application/json" --location --request POST "https://dev.cloudnetwork.in/api/v1/api/test" --header "Authorization: Bearer $token" -d  '{"base_url":"'"${BASE_URL}"'","auth0_url":"'"${AUTH0_URL}"'","register_url":"'"${REGISTER_URL}"'","openapi_spec":"'"${OPENAPI_SPEC}"'","base_path":"'"${BASEPATH_SPEC}"'","label":"'"${LABEL}"'","test_email":"'"${TEST_EMAIL}"'"}' | jq -r .token)

label_name=$(jq -r '.label')
created_email=$(jq -r '.created_by_email')

echo "Successfully created the API Register."
echo "LabelName: $label_name"
echo "CreatedEmail: $created_email"
echo 'Script Execution is Done.'
echo "Successfully created $NoProjectsToCreate projects in $TEST_HOSTNAME environment!!!"

Here is my output command

./dev-registry.sh --base_url "https://dev.cloudnetwork.in" --auth0_url "https://dev-yxxxxxxxx1.us.auth0.com" --register_url "https://dev.cloudnetwork.in/apis/register" --username "[email protected]" --password "123456" --openapi_spec "https://xxxxxx.yaml" --base_path "https://xxxxxxx/v2" --label "Demo" --test_email "[email protected]"

Here is my website login browser response which below shows all details from here i take and add into shell script inside curl

 {
    BASE_URL: 'https://dev.cloudnetwork.in',
    AUTH0_URL: 'https://dev-yxxxxxxxxx1.us.auth0.com',
    USERNAME: '[email protected]',
    PASSWORD: '123456',
    REGISTER_URL:'https://dev.cloudnetwork.in/apis/register',
  },


1. GENERAL
Request URL:     https://dev.cloudnetwork.in/api/v1/api/test
Request Method:  POST

2. Request Header
authority:       api.dev.cloudnetwork.in
method:          POST
path:            /api/v1/api/test
Authorization:   Bearer
eyJhxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxeaLvIBUOsH6gGQ1xxxxxxxxxxxxxxxx0huyw

3. Payload
openapi_spec:      "https://xxxxx/xxxxx.yaml"
base_path:          "https://xxxxxxx/v2"
test_email:   "[email protected]"
label:              "demo"

{"openapi_spec":"https://xxxxxxxx.yaml","base_path":"https://xxxxxxxx/v2","label":"demossss"}

So, using above details im pulling token, login and registering an API the same i want to do from shell script above is script but its return empty response

i dont know where im wrong

0

There are 0 answers