The path variable "var" needs to be of type integer, but we found "{{var}}"

Hello Again
In my Environment I set a variable var = 1 and use that one in the URL

Now my put operation yields an issue:
1 Issue found while validating against PUT /api/workspace/{workspaceId}

When I change the URL to /api/workspace/:workspaceId and use a path variable, the test is successfull

Is there a way to use the environment vars in those tests?
Even when using the URL with :workspaceId and setting the path variable workspaceId to the environment variable {{workspaceId} the test fails

I somehow don’t want to use local variables for tests, especialy when chaining them

Looks like this is the same as The path variable needs to be of type number, but we found "{{id}}"

Hey @plcmaechler

Are you able to show an example of what you’re seeing in the app and the test code that you’re using to get/set the variables please?

Well there is no “test code” involved

Let’s share the information firts:

This is the definition in the API:
image

And here is the request from my collection:

And when i test the API, postman reports the error:
image

When I use a path variable, the API test is ok
image

and to summ it all up, the variables are defined in an environment


hope that helps

My bad - When people talk about variables, my mind instantly goes to getting or setting them via a script with pm.environment.get() / pm.environment.set() :smiley:

So it’s failing to validate the request against your schema when you use an environment variable as a path parameter value?

Screenshot 2020-05-18 at 10.36.19

yes

the API endpoint is defined as /api/workspace/{workspaceId}: and requires a parameter workspaceId in path

the request is {{baseUrl}}/api/workspace/{{workspaceId}} and this fails (looks to me I have to use an path variable when testing the API)

therefore my next attemp was to set the path variable to {{workspaceId}} from environment which also does not work

Only when using the path variable and put a “static” value in the, the API validation is working

is there a way to directly use the environment variable, or set the path variable to the environment variable in a pre-reqeust script?

thx for your help so far

Okay. Not totally sure what you are trying to do and why it is or isn’t working, but from the images, it looks like you should “stick” with the path vars, but combine it with the {{workingId}} you add by putting that as the value for the path var.

This one is showing using the dynamic vars for a uuid:

And here is is with your “1” in it:

One thing to note, if you want to have your example use the value you pass on one of the postman mock server instances, you need to change the url value of your example to use a variable, like this:
{{url}}/workspaces/{{workspaceid}}
that way it can be used as a substitution in the response with "{{workspaceid}} on the mock server like this:

{
“workspaceid”:"{{workspaceid}}"
}

Hello Mason

For requests from within a Collection, this approach (using a path variable and setting it to the environment var) is working fine and all the calls and tests are successfull

The problem-part is when i test or validate the API.
On the postman website I go into my API and from there to Test
image

Then I see the test-suite that I created (the collection). If I validate the API schema against it, I get the error mentioned.

It looks like when I test the API, the environment is “ignored” or no environment is used.