# How to automate a request which doesn't give response on the first attempt. It throws Error: getaddrinfo ENOTFOUND {{domainname}}

**URL:** <https://community.postman.com/t/how-to-automate-a-request-which-doesnt-give-response-on-the-first-attempt-it-throws-error-getaddrinfo-enotfound-domainname/33139>\
**Category:** Help Hub\
**Created:** [March 3, 2022, 3:30pm UTC](https://community.postman.com/t/how-to-automate-a-request-which-doesnt-give-response-on-the-first-attempt-it-throws-error-getaddrinfo-enotfound-domainname/33139 "2022-03-03T15:30:44Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![abhi1788](https://avatars.discourse-cdn.com/v4/letter/a/eb9ed0/32.png) [@abhi1788](https://community.postman.com/u/abhi1788)\
**Post date:** [March 3, 2022, 3:30pm UTC](https://community.postman.com/t/how-to-automate-a-request-which-doesnt-give-response-on-the-first-attempt-it-throws-error-getaddrinfo-enotfound-domainname/33139/1 "2022-03-03T15:30:44Z")

</div>

I have a JSON POST request that does not return JSON response on the first attempt.  
**Error: getaddrinfo ENOTFOUND {{domainname}}**

When the same request is posted multiple times (3 to 4 times), then it returns proper response.  
I have checked the code provided in the community, but could not find a solution for this.

 ![Screen Shot 2022-03-03 at 16.28.42](https://us1.discourse-cdn.com/getpostman/original/3X/4/c/4caf4e2b8f1f590796415bf4feeb8cc872d1ecd0.png)

How to automate this scenario?

---

<div class="post-metadata">

**Author:** ![ianthepostmanaut](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/ianthepostmanaut/32/11109_2.png) [@ianthepostmanaut](https://community.postman.com/u/ianthepostmanaut)\
**Post date:** [March 3, 2022, 7:12pm UTC](https://community.postman.com/t/how-to-automate-a-request-which-doesnt-give-response-on-the-first-attempt-it-throws-error-getaddrinfo-enotfound-domainname/33139/2 "2022-03-03T19:12:42Z")

</div>

Hi @abhi1788 , welcome to the community, and thanks for your question.

I will presume that you are using `{{domainname}}` in the request URL. The ENOTFOUND error indicates that the system couldn’t do a DNS lookup, which sounds like Postman is sending that string as-is, and not finding your variable to replace the literal string with your intended server string.

Are you building this variable dynamically? Or is it an environment or collection variable? Can you give us a little more information?

Cheers,  
Ian

---

<div class="post-metadata">

**Author:** ![abhi1788](https://avatars.discourse-cdn.com/v4/letter/a/eb9ed0/32.png) [@abhi1788](https://community.postman.com/u/abhi1788)\
**Post date:** [March 4, 2022, 8:37am UTC](https://community.postman.com/t/how-to-automate-a-request-which-doesnt-give-response-on-the-first-attempt-it-throws-error-getaddrinfo-enotfound-domainname/33139/3 "2022-03-04T08:37:29Z")

</div>

Thanks @ianthepostmanaut to your response. {{domainname}} is an environment variable. It is quite strange that DNS is not resolving to string. But, this does not happen everytime. Out of 10 times, the request is processed correctly for 4 times.

Therefore, I want to keep it posting until I see the response.

---

<div class="post-metadata">

**Author:** ![ianthepostmanaut](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/ianthepostmanaut/32/11109_2.png) [@ianthepostmanaut](https://community.postman.com/u/ianthepostmanaut)\
**Post date:** [March 4, 2022, 6:43pm UTC](https://community.postman.com/t/how-to-automate-a-request-which-doesnt-give-response-on-the-first-attempt-it-throws-error-getaddrinfo-enotfound-domainname/33139/4 "2022-03-04T18:43:08Z")

</div>

Yes, this does seem strange. Can you give us a screenshot of the console showing how it’s not using the `{{domainname}}` variable, and using that literal string instead? Maybe a screenshot of how you’re using the variable in the request URL as well?

---

<div class="post-metadata">

**Author:** ![kevinc-postman](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/kevinc-postman/32/12774_2.png) [@kevinc-postman](https://community.postman.com/u/kevinc-postman)\
**Post date:** [March 4, 2022, 6:47pm UTC](https://community.postman.com/t/how-to-automate-a-request-which-doesnt-give-response-on-the-first-attempt-it-throws-error-getaddrinfo-enotfound-domainname/33139/5 "2022-03-04T18:47:20Z")

</div>

That’s certainly an interesting problem to have. 🤔

It would be ideal to get to the root of the problem and not have to do anything with retries like Ian is trying to help with.

But another possible solution to implement a version of retrying a request could be to use `postman.setNextRequest(request.name)` behind some kind of check with a counter to loop only a certain number of times until you get a response and `postman.setNextRequest(null)` after the 10th request for example.

Here’s a sample I was able to find that demonstrates this for you 😄

> [@Retry a failing request](https://community.postman.com/t/retry-a-failing-request/5934):
>
> Hi, in our test environment, unfortunately quite some requests are failing from time to time, due to timeouts, environment not being available, you-name-it, so I want to give that requests a retry, especially when running the collections in Jenkins via newman. So I came up with a bit of code, that repeats waits for a certain amount of time, before it does a retry of the request. The number of retries can also be set. var expectedHttpStatus = 200; var maxNumberOfTries = 3; var sleepBetweenTrie…

---

<div class="post-metadata">

**Author:** ![lunar-module-opera13](https://avatars.discourse-cdn.com/v4/letter/l/c89c15/32.png) [@lunar-module-opera13](https://community.postman.com/u/lunar-module-opera13)\
**Post date:** [December 4, 2023, 10:03pm UTC](https://community.postman.com/t/how-to-automate-a-request-which-doesnt-give-response-on-the-first-attempt-it-throws-error-getaddrinfo-enotfound-domainname/33139/6 "2023-12-04T22:03:39Z")

</div>

I had the similar problem: after I installed a local Postman app, some of my requests stopped working, but they still worked in a web. Then I noticed that some of the slashes “/” have been removed in my URLs during the sync - they were simply missing in the local app:  
local app: https:/{{cpihostname}}http/parallel\_multicast  
web app: https://{{cpihostname}}/http/parallel\_multicast  
After adding the back, it was all good.  
Hope this helps someone…

---

<div class="post-metadata">

**Author:** ![michalac](https://avatars.discourse-cdn.com/v4/letter/m/58956e/32.png) [@michalac](https://community.postman.com/u/michalac)\
**Post date:** [December 29, 2023, 8:19pm UTC](https://community.postman.com/t/how-to-automate-a-request-which-doesnt-give-response-on-the-first-attempt-it-throws-error-getaddrinfo-enotfound-domainname/33139/7 "2023-12-29T20:19:13Z")

</div>

Hi, did you solve the problem? It does not seem to have the solution here. I have the same problem. Some of the requests I need to run again for it to be successful.  
On of the possibilities, which is not working for all my requests is to have the following function in the pre-request of the collection:

let sendRequestWithRetry = () =\> {

```
    // Send the request
    pm.sendRequest(pm.request, function (err, response) {
        //console.log("... sending request ... ")            
        if (err) {
             // console.log("sendRequestWithRetry")
            const maxRetries = Number(pm.collectionVariables.get("timeoutRetryMax"));
            let retryCount = Number(pm.collectionVariables.get("timeoutRetryCount"));
            console.log(`maxRetries = ${maxRetries}, retryCount = ${retryCount}`)
            if ((err.code === 'ETIMEDOUT' || err.code === "ESOCKETTIMEDOUT" || err.code === "ECONNREFUSED" || err.code === "ENOTFOUND") && retryCount < maxRetries) {
                // Retry the request with a delay
                console.log(`Retrying request (Attempt ${retryCount})...`);
                retryCount++;
                pm.collectionVariables.set("timeoutRetryCount", retryCount)
                setTimeout(sendRequestWithRetry, 2000);
            } else {
                // Handle other errors if needed
                // console.log('******(retryCount >= maxRetries) go on withthe next request********')
                console.log('******(retryCount >= maxRetries) Stop next tests executions********')
                console.error(err);
                postman.setNextRequest(null)
                
            }
        } else {
            // Request completed successfully
            console.log(`Response received in ${response.responseTime} ms`);
            console.log(`Request completed successfully (Attempt ${pm.collectionVariables.get("timeoutRetryCount")})...`);
        }
    });
}

```

---

<div class="post-metadata">

**Author:** ![joint-operations-o11](https://avatars.discourse-cdn.com/v4/letter/j/96bed5/32.png) [@joint-operations-o11](https://community.postman.com/u/joint-operations-o11)\
**Post date:** [January 24, 2024, 4:27pm UTC](https://community.postman.com/t/how-to-automate-a-request-which-doesnt-give-response-on-the-first-attempt-it-throws-error-getaddrinfo-enotfound-domainname/33139/8 "2024-01-24T16:27:50Z")

</div>

I could solve this problem, i installed Postman Desktop Agent and i used it(before Postman cloud) and the problem was fixed.
