2

I am trying to create a base request in getToken.http that I can import and run in my main.http file. The base request needs three variables, two of which are loaded from the http-client.env.json file, the credentials for the request, and the third one is a string used in the response handler.

The baseUrl is loaded from the ...env.json and the environment is set to 'local'.

getToken.http:

### Post request with a profile variable
POST {{baseUrl}}/getToken
Authorization: Basic {{username}} {{password}}

> {%
    client.test("Get Auth Token for " + name, function () {
        client.assert(response.body.name === "MY_TOKEN", "MY_TOKEN expected but not found.")
        client.global.set(name + "-TOKEN", response.body.value)
    })

%}

main.http:

import getToken.http

###
run #Post request with 3 variables(@username={{profile1-username}}, @password={{profile1-password}}, @name='test_string')

It does not properly load the variables from the ...env.json. When I check the Authorization of the request it looks like this:

Authorization: Basic {{profile1-username}} {{profile1-password}}

As for the response handler, it says: ReferenceError: name is not defined

Unfortunately, there is no example here: import-http-requests-from-other-http-files

1 Answer 1

1

About your second issue with the ReferenceError: If I understand the IntelliJ HTTP Client correctly, using an imported request and providing/overriding variables using that (@var = value) syntax these variabled are created as "in-place variables", and according to this bug report in Jetbrains' Youtrack it's not (yet) possible to access those in the response handler JavaScript...

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.