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.

Unfortunately my problem is still not solved. I’m getting the feelding, that my question/problem is not clear

I have six request in my Collection

  1. /login
  2. /user/create
  3. /user/read/:userId
  4. /user/change/:userId
  5. /user/delete/:userId
  6. /user/read/:userId

when loggin in, the accessToken is saved as an environment variable
when creating an user, the response is the userId, which is also saved as an environment variable
when reading the object, the PathVariable is set to the environment Variable

This setup is working fine. I can send those request and all return with a status code of 200 and the object is added, changed and deleted

In Postman i also have an API which has the above Test Suite linked to it. There when I click on validate the, the schema has issues
image

I’m sure this is something trivial because it feels like a basic test routine which I’m sure lots of you already did .)

May someone be able to sched some light into the darknes and gives me a hint on how to solve?

When I “hardcode” the ID, the validation wors fine, so i certain that it has to do with the {{variable}} syntax