title: Shell script call API via curl and process response
body: <p>I need to create a shell script that calls my login API via curl.
  The script should be able to store and process the response from curl api call.</p>
  
  <p><strong>myscript.sh</strong></p>
  
  <pre><code>#!/bin/bash
  
  echo "Extract bearer token from curl calling login api"
  echo
  # Check cURL command if available (required), abort if does not exists
  type curl &gt;/dev/null 2&gt;&amp;1 || { echo &gt;&amp;2 "Required curl but it's not installed. Aborting."; exit 1; }
  echo
  
  PAYLOAD='{"email": "dummy-user@acme.com", "password": "secret"}'
  
  curl -s --request POST -H "Content-Type:application/json"  http://acme.com/api/authentications/login --data "${PAYLOAD}"
  </code></pre>
  
  <p>My problem in the given script is:</p>
  
  <ol>
  <li>it does not get the response of curl calling the API.</li>
  <li>From the response json, get only the token value.</li>
  </ol>
  
  <p><strong>Sample Login API response:</strong></p>
  
  <pre><code>{
    "user": {
      "id": 123,
      "token": "&lt;GENERATED-TOKEN-HERE&gt;",
      "email": "dummy-user@acme.com",
      "refreshToken": "&lt;GENERATED-REFRESH-TOKEN&gt;",
      "uuid": "1239c226-8dd7-4edf-b948-df2f75508888"
    },
    "clientId": "abc12345",
    "clientSecretKey": "thisisasecret"
  }
  </code></pre>
  
  <p>I only need to get the value of <code>token</code> and store it in a variable... I will use token value in other curl api call as bearer token.</p>
  
  <p>What do I need to change in my script to extract the <code>token</code> value from the response of curl api call?</p>
  
  <p>Thanks!</p>