Api,  Postman

Calling an Api inside Postman


Warning: DOMDocument::loadHTML(): Tag template invalid in Entity, line: 12 in /home/samu/public_html/blog/wp-content/plugins/gistpress-master/includes/class-gistpress.php on line 473

Warning: DOMDocument::loadHTML(): Tag svg invalid in Entity, line: 14 in /home/samu/public_html/blog/wp-content/plugins/gistpress-master/includes/class-gistpress.php on line 473

Warning: DOMDocument::loadHTML(): Tag path invalid in Entity, line: 15 in /home/samu/public_html/blog/wp-content/plugins/gistpress-master/includes/class-gistpress.php on line 473

Warning: DOMDocument::loadHTML(): Tag template invalid in Entity, line: 27 in /home/samu/public_html/blog/wp-content/plugins/gistpress-master/includes/class-gistpress.php on line 473

Warning: DOMDocument::loadHTML(): Tag svg invalid in Entity, line: 29 in /home/samu/public_html/blog/wp-content/plugins/gistpress-master/includes/class-gistpress.php on line 473

Warning: DOMDocument::loadHTML(): Tag path invalid in Entity, line: 30 in /home/samu/public_html/blog/wp-content/plugins/gistpress-master/includes/class-gistpress.php on line 473

For a recent test of a system, I had to use a different CNPJ (Brazilian company unique identifier) for each postman call for each registration, so as not to conflict with what had already been registered in the database.

Of course I could have deleted the data on every call, but I wanted to do something different. In the tutorial we did on scrapping, I taught how to get the data from a common API, so I had, in a sqlite, 3000 records, which could be used.

The basic idea would be, when you click send (at 1), it will already bring up the fetched_cnpj variable, at 2, filled in)

To accomplish that, let’s click on pre-request-scripts and paste the following code

const reqObject = {
url: 'https://myendpoint.com/cnpj',
method: 'GET',
header: 'token: MYTOKEN'
};
pm.sendRequest(reqObject, (err, res) => {
const returned_date = res.json()
pm.collectionVariables.set ("fetched_cnpj", returned_date.data.cnpj);
});
view raw gistfile1.txt hosted with ❤ by GitHub

Notice: ob_end_flush(): failed to send buffer of zlib output compression (0) in /home/samu/public_html/blog/wp-includes/functions.php on line 5277