chapar-rest / chapar

Chapar is a simple and easy to use api testing tools aims to help developers to test their api endpoints. it support http and grpc protocols.
https://chapar.rest
BSD 3-Clause "New" or "Revised" License
434 stars 19 forks source link

Post Request not set(or create) selected target key in envs #64

Closed Monirzadeh closed 1 month ago

Monirzadeh commented 1 month ago

i try to use Post Request and get token with this

Set Environment Variable
Targey Key: "TokenKey"
Status Code: "200"
From: "From Response"
Path/Key: "message.token"

i see token in preview section but when i want use {{TokenKey}} in header of of other request it is not working. did i miss something? i can't find documentation how to use Post Request feature.

Originally posted by @Monirzadeh in https://github.com/chapar-rest/chapar/discussions/58

mirzakhany commented 1 month ago

Hi @Monirzadeh I have tried to reproduce this issue with no success. could you please share your request yaml file? on linux its in ~/.config/chapar and should be something like this:

apiVersion: v1
kind: Request
metadata:
  id: 56da73ac-92ff-4dc7-b95a-596dc411155d
  name: Login
  type: http
spec:
  http:
    method: POST
    url: '{{baseURL}}/login'
    lastUsedEnvironment:
      id: ""
      name: ""
    request:
      headers:
      - id: ddabdf74-a330-496b-87e7-c5653738b506
        key: Content-Type
        value: application/json
        enable: true
      pathParams: []
      queryParams: []
      body:
        type: json
        data: |
          {
            "email": "{{email}}",
            "password": "{{password}}"
          }
      auth:
        type: none
      preRequest:
        type: none
        script: ""
      postRequest:
        type: setEnv
        set:
          target: authenticationToken
          statusCode: 200
          from: responseBody
          fromKey: $.authenticationToken
    responses: []
Monirzadeh commented 1 month ago
apiVersion: v1
kind: Request
metadata:
  id: 5ff95cdf-6f02-41b8-9b85-46a0dfcd9e50
  name: Login
  type: http
spec:
  http:
    method: POST
    url: http://myurl/api/v1/auth/login
    lastUsedEnvironment:
      id: ""
      name: ""
    request:
      headers:
      - id: ""
        key: Content-Type
        value: application/json
        enable: true
      pathParams: []
      queryParams: []
      body:
        type: json
        data: |-
          {
            "password": "whatever",
            "remember_me": true,
            "username": "username"
          }
      auth:
        type: None
      preRequest:
        type: None
        script: ""
      postRequest:
        type: setEnv
        script: ""
        set:
          target: TokenKey
          statusCode: 200
          from: responseBody
          fromKey: message.token
    responses: []

it is the yaml version of request under collection directory

mirzakhany commented 1 month ago

first different I can notice is fromKey. please change it to fromKey: $.message.token. I assume your response is look like flowing, right?

{
    "message": {
        "token": "xyz"
    }
}
Monirzadeh commented 1 month ago

first different I can notice is fromKey. please change it to fromKey: $.message.token.

I change that but problem still exist.

I assume your response is look like flowing, right?

{
    "message": {
        "token": "xyz"
    }
}

Yes

Monirzadeh commented 1 month ago

Hi Why close this issue. Does it solve?

mirzakhany commented 1 month ago

Hi @Monirzadeh I really like to help but I did more tests on this with a fresh setup and to this point the latest build is always working so I can’t confirm this issue.

If any one else sees this issue please let me know to open it again.

I would appreciate If you could send some screenshots, that might help me to understand what is wrong 🙏