Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to override post-response script content for the postman? #850

Open
1 task done
hardiklakhalani opened this issue May 11, 2024 · 1 comment
Open
1 task done
Labels
question Further information is requested

Comments

@hardiklakhalani
Copy link

hardiklakhalani commented May 11, 2024

Scribe version

4.35.0

Your question

How to override post-response script content for the postman?

Here is the script I want to add in my login request:

pm.collectionVariables.set("token", pm.response.json().data.token);

image

Following is the variables I've already overridden successfully:

But not sure how to add the post-response script to the login request.

'postman' => [
        'enabled' => true,
        'overrides' => [
            // 'info.version' => '2.0.0',
            'info.name' => 'Example API',
            'info.description' => 'API documentation for the Example API.',
            'variables' => [
                [
                    "key"=> "baseUrl",
                    "value"=>"http://xyz_site.test",
                    "type"=>"string"
                ],
                [

                    "key"=>"token",
                    "value"=> null,
                    "type"=>"string"
                ],
                [
                    "key"=>"password",
                    "value"=>"12345678",
                    "type"=>"string"
                ],
                [
                    "key"=>"email_user",
                    "value"=>"[email protected]",
                    "type"=>"string"
                ]
            ],
            "auth" => [
                "type" => "bearer",
                "bearer" => [
                    "key" => "token",
                    "value" => "{{token}}",
                    "type" => "string"
                ]
            ]
        ],
    ],

Following is the post-response script example snippet from the postman collection export:

{
	"item": [
		{
			"name": "Authentication",
			"item": [
				{
					"name": "Login User",
					"event": [
						{
							"listen": "test",
							"script": {
								"exec": [
									"pm.collectionVariables.set(\"token\", pm.response.json().data.token);"
								],
								"type": "text/javascript",
								"packages": {}
							}
						},
						{
							"listen": "prerequest",
							"script": {
								"exec": [
									""
								],
								"type": "text/javascript",
								"packages": {}
							}
						}
					],
					"request": {
						"auth": {
							"type": "noauth"
						},
						"method": "POST",
						"header": [
							{
								"key": "Content-Type",
								"value": "application/json"
							},
							{
								"key": "Accept",
								"value": "application/json"
							}
						],
						"body": {
							"mode": "raw",
							"raw": "{\"email\":\"{{email_admin}}\",\"password\":\"12345678\"}"
						},
						"url": {
							"raw": "{{baseUrl}}/api/login",
							"host": [
								"{{baseUrl}}"
							],
							"path": [
								"api",
								"login"
							]
						}
					},
					"response": []
				}
			]
		},
	]
}

Docs

@hardiklakhalani hardiklakhalani added question Further information is requested triage labels May 11, 2024
@shalvah
Copy link
Contributor

shalvah commented May 27, 2024

I have no idea. Where is the script meant to be specified in the Postman collection file format? Doesn't the overrides section work?

@shalvah shalvah removed the triage label May 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants