linux:bash-post-to-api
POST to API with cURL
Written to POST a file ref, username and UUID to an API running with Flask:-
(Note:- this URL can be used to test your curl script to see just what you actually sent. https://httpbin.org/anything )
#!/bin/bash # Just random test data! # Simple Auth Token AUTH_TOKEN="123123aasda%^&^%HG" # Generate email ramdomly EMAILS=(user1@example.com user2@example.com user3@example.com) # Get length of list with:- "${#EMAILS[@]}" INDEX=$(( RANDOM % ${#EMAILS[@]} )) EMAIL="${EMAILS[${INDEX}]}" # Generate uuid UUID=$(uuidgen) printf "Using %dth email.\n" ${INDEX} printf "UUID is %s.\n\n" ${UUID} curl -i -X POST \ -H 'Content-Type: application/json' \ -d "{\"auth_token\":\"${AUTH_TOKEN}\", \"user_id\":\"${EMAIL}\", \"file_reference\":\"testFile.odt\", \"uuid\":\"${UUID}\"}" \ http://192.168.21.197:5000/nifiapi
linux/bash-post-to-api.txt · Last modified: by 127.0.0.1