'How to use curl's response in other run commands in github actions
Trying to get the response from curl and use it in subsequent commands. Not sure what should be the correct syntax here.
- name: Get Token
run: |
response = $(curl https://********* -header "Accept: application/json" -header "X-Username: ${{ secrets.USER_NAME }}" -header "X-Password: ${{ secrets.PASSWORD }}")
echo "response from curl= $response"
Solution 1:[1]
Try to use like this
- name: Get Token
run: |
response = $(curl https://********* -header "Accept= application/json" -header "X-Username= ${{ secrets.USER_NAME }}" -header "X-Password= ${{ secrets.PASSWORD }}")
echo "response from curl= $response"
Solution 2:[2]
I was able to solve this using below approach
- name: GET all workspace
run: |
curl --location --request GET 'https://api.getpostman.com/workspaces' --header 'X-API-Key: ${{ secrets.API_TOKEN }}' -o workspaces.json
- name: read workspace id
id: workspace
run: echo "::set-output name=id::$(cat workspaces.json | jq -c '.workspaces[] | select(.name == "My Workspace").id')"
- name: print workspace id
run: echo ${{ steps.workspace.outputs.id }}
- name: GET api's in workspace
run: |
curl --location --request GET "https://api.getpostman.com/apis?workspace=${{ steps.workspace.outputs.id }}" --header 'X-API-Key: ${{ secrets.API_TOKEN }}' -o apis.json
- name: Read api id in workspace
id: api
run: echo "::set-output name=id::$(cat apis.json | jq -c '.apis[] | select(.name == "testing-service").id')"
- name: Print api id
run: echo ${{ steps.api.outputs.id }}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 | ChaseD20 |