Request body with field value set in pre-request Script

I am running simple Azure Graph API query with JSON body

    {
        "subscriptions": [
            "{{subscriptionId}}"
        ],
        "query": "Resources| project tags | summarize buildschema(tags)"
        }
    } 

but I need to change it to

{
    "subscriptions": [
        "{{subscriptionId}}"
    ],
    "query": "{{query}}"
    }
}

with {{query}} set in pre-request Script, tried both below

var query = JSON.stringify("Resources| project tags | summarize buildschema(tags)")
var query = "Resources| project tags | summarize buildschema(tags)"

Unfortunately getting Badrequest error

Hi @irekromaniuk, welcome to the Postman community! I’ve moved your post to the “help” category so that others can better find and answer your question.

Have you set {{query}} as a variable, beyond the pre-request script?

1 Like

@hannah.neil is correct, in your prerequest script just add the following:

pm.variables.set('query', 'Resources| project tags | summarize buildschema(tags)');
2 Likes

Appreciate , it works now