I have a shell script that will call a REST API and gets the JobID from the response. Using the JobId from the first rest API, I am calling another REST API using cURL. But the issue is the file is not getting downloaded.
I am using basic grep, shell, and cURL.
I am open to use any other alternatives, but not too complex.
I am new to shell scripting. Just doing for a use case that we want to achieve.
Here is my shell script (For security reasons I have changed few things)
#!/bin/bash
echo "Extract jobId from curl request"
RESPONSE=`curl -s --request POST "https://example.com/access/2/abc/jobs/DataDomainExports" -H "accept: application/json" -H "Content-Type: application/json" -d "{ \"association\": [ \"ACCEPTED\" ], \"objectId\": \"DataDomain://FirstName\"}" -u "username:password"`
TEMPJOBID=`echo $RESPONSE | grep -o "DataDomainExports_[A-Za-z0-9]*"` #Using this because the above $RESPONSE is in single line and has the same JobID multiple times.
JOBID=`echo $TEMPJOBID | grep -o -m 1 "^DataDomainExports_[A-Za-z0-9]*"`
echo "The Job ID is:"
echo $JOBID
curl -v -X GET "https://example.com/access/2/abc/jobs/DataDomainExports/"${JOBID}"/result" -u "username:password" -H "accept: application/excel" -o output.csv
echo "export completed"
When I run the above shell script it generates the JobID but doesn't save the file. If I download from chrome it gets downloaded without any issue. I also tried running the scripts individually through the terminal and it works fine and file gets downloaded. Seems like something is wrong.