{"id":713,"date":"2020-12-03T10:53:23","date_gmt":"2020-12-03T16:53:23","guid":{"rendered":"https:\/\/ma.rcbla.se\/blog\/?p=713"},"modified":"2023-01-10T12:54:03","modified_gmt":"2023-01-10T18:54:03","slug":"process-csv-file-and-curl-request-with-its-contents","status":"publish","type":"post","link":"https:\/\/ma.rcbla.se\/blog\/2020\/12\/process-csv-file-and-curl-request-with-its-contents\/","title":{"rendered":"Process CSV file and curl request with its contents"},"content":{"rendered":"<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n#!\/bin\/bash\r\n# Purpose: Read Comma Separated CSV File and cURL using contents\r\n\r\nINPUT=$1\r\nOLDIFS=$IFS\r\nIFS=','\r\n&#x5B; ! -f $INPUT ] &amp;&amp; { echo &quot;Please provide a CSV file&quot;; exit 99; }\r\nwhile read user_email first_name last_name Level start_issue start_date\r\ndo\r\n    # curl request with contents from CSV and write output to file\r\n    curl -m 10 -X POST --data API_Key=KEY_GOES_HERE --data Email=$user_email --data Program_Data=PROGRAM_DATA_GOES_HERE --data FirstName=$first_name --data LastName=$last_name https:\/\/API_ENDPOINT.TLD &gt;&gt; curl_output.json\r\n\t\r\ndone &lt; $INPUT\r\nIFS=$OLDIFS\r\n<\/pre>\n<p>Run this as, if saved as curl-csv.sh:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n$ .\/curl-csv.sh curl-csv.csv\r\n<\/pre>\n<p>If you get the &#8220;\/bin\/bash^M: bad interpreter: No such file or directory&#8221; error message you probably created the .sh file in Windows and are running in a Linux shell. Run the following command to rectify.<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n$ sed -i -e 's\/\\r$\/\/' curl-csv.sh\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>#!\/bin\/bash # Purpose: Read Comma Separated CSV File and cURL using contents INPUT=$1 OLDIFS=$IFS IFS=&#8217;,&#8217; &#x5B; ! -f $INPUT ] &amp;&amp; { echo &quot;Please provide a CSV file&quot;; exit 99; } while read user_email first_name last_name Level start_issue start_date do # curl request with contents from CSV and write output to file curl -m 10 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11,65],"tags":[],"class_list":["post-713","post","type-post","status-publish","format-standard","hentry","category-coding","category-sysadmin"],"_links":{"self":[{"href":"https:\/\/ma.rcbla.se\/blog\/wp-json\/wp\/v2\/posts\/713","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ma.rcbla.se\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ma.rcbla.se\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ma.rcbla.se\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/ma.rcbla.se\/blog\/wp-json\/wp\/v2\/comments?post=713"}],"version-history":[{"count":6,"href":"https:\/\/ma.rcbla.se\/blog\/wp-json\/wp\/v2\/posts\/713\/revisions"}],"predecessor-version":[{"id":993,"href":"https:\/\/ma.rcbla.se\/blog\/wp-json\/wp\/v2\/posts\/713\/revisions\/993"}],"wp:attachment":[{"href":"https:\/\/ma.rcbla.se\/blog\/wp-json\/wp\/v2\/media?parent=713"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ma.rcbla.se\/blog\/wp-json\/wp\/v2\/categories?post=713"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ma.rcbla.se\/blog\/wp-json\/wp\/v2\/tags?post=713"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}