Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save gabrielh-silvestre/cf822c65547585211dc47ac165c7809a to your computer and use it in GitHub Desktop.
Save gabrielh-silvestre/cf822c65547585211dc47ac165c7809a to your computer and use it in GitHub Desktop.

Criação/Configuração de Variável

Exemplo

var json = JSON.parse(responseBody);

if (responseCode.code >= 200 && responseCode.code < 300) {
    // Variável da coleção
    pm.collectionVariables.set("productId", json.data.id);
    // Variável global
    pm.globals.set("productId", json.data.id);
}

Template

var /*variável local*/ = JSON.parse(responseBody);

if (responseCode.code >= 200 && responseCode.code < 300) {
    // Variável da coleção
    pm.collectionVariables.set(/*"variável do postman"*/, /*variável local*/./*estrutura da resposta*/);
    // Variável global
    pm.globals.set(/*"variável do postman"*/, /*variável local*/./*estrutura da resposta*/);
}

Deleção de Variável

Exemplo

if (responseCode.code >= 200 && responseCode.code < 300) {
    // Variável da coleção
    pm.collectionVariables.unset("productId");
    // Variável global
    pm.globals.unset("productId");
}

Template

if (responseCode.code >= 200 && responseCode.code < 300) {
    // Variável da coleção
    pm.collectionVariables.unset(/*"variável do postman"*/);
    // Variável global
    pm.globals.unset(/*"variável do postman"*/);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment