Replies: 1 comment 1 reply
-
Welcome to PactumJS Discussions & Thanks a lot for using this library.pactum.spec()
SolutionYou might need to update your function async function searchAPIRequestToEnv(envShortened: string, token: any) {
await pactum.spec()
.post(getSearchEndpoint(envShortened))
.withHeaders({
'authorization': `Bearer ${token}`,
'content-type': 'application/json'
})
.withJson('test-data/search.json')
.expectStatus(200)
} |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi, i wonder if you can help me.
I'm trying to make api request with token which i previously get from another endpoint, but second call always shows error described in the heading.
I use cucumber to run tests and here is my code:
First request:
async function getUserToken(envShortened: string): Promise<void> { const response = await spec.post(linksForAuthorizationTokenByEnvironment[envShortened]) .withHeaders({ 'Content-Type': 'application/x-www-form-urlencoded', 'Authorization':
${credentialsForEnvironment[envShortened]}`,})
.withBody('grant_type=client_credentials&scope=')
.expectStatus(200).toss();
}`
That request returns the token and then i'm trying to pass it to the next request:
async function searchAPIRequestToEnv(envShortened: string, token: any) { spec.post(getSearchEndpoint(envShortened)) .withHeaders({ 'authorization': `Bearer ${token}`, 'content-type': 'application/json' }) .withJson('test-data/search.json') .expectStatus(200) }
And i'm always getting:
[0-0] Error in "0: I have entered certain search criteria for "TEST""
Error: Duplicate request initiated. Existing request - POST - and link to my token access request
What am i doing wrong? :)
Beta Was this translation helpful? Give feedback.
All reactions