CurL command Rest API call with oauth 2.0 secutity error

Hi

I need to get rates for different security form REST API . the API is oauth 2.0 secured.

i need to use curl command to get json response from api .

token URL - is HTTP
data URL is - HTTPS

when trigger my command from bash script it passing and failing intermittently with following error

with error could not resolve host for curl command (exit code 6). It is stopping me from proceeding .

my command for token :

RTOKEN=$(curl -X POST $RTOKENURL -u $RCLIENTID -d "grant_type=client_credentials" -d "code=client_credentials" | grep token | cut -d, -f1 d\" -f4)

For data with above token

curl -k -o $INDIR/$IFILENAME --request GET --url $RDATAURL$RTOKEN --header 'authorization: Bearer'$RTOKEN.

so the problem is intermittent so some time i get my data in file and sometimes it fails with above error please help...

Please Note :- same URLS are working fine with POSTMAN(chrome) always.