Requests not having correct IP even after passing staticIP=true

I’ve been trying to make a simple post request using request module everytime a ticket is created and even after passing the staticIP=true option, I’m getting requests with IPs different than the ones listed in the documentation. I’ve used the “serverless_request_app” as template(Link).

var request = require("request");
exports = {
  events: [{ event: "onTicketCreate", callback: "onTicketCreateHandler" }],

  onTicketCreateHandler: function (args) {
    const url = "---------hidden-----------";
    try {
      request.post(
        url,
        {
          headers: {
            "content-type": "application/json",
            apikey:
              "abcdefgh",
          },
          maxAttempts: 5,
          body: JSON.stringify({
            id: args.data.ticket.id,
          }),
          staticIP: true,
        },
        (err, res, body) => {
          if (err) {
            console.log(err);
          }
          if (res) {
          }
          if (body) {
            console.log(body);
          }
        }
      );
      request.post(
        "https://api-checker-hit.herokuapp.com/saveReq",
        {
          headers: {
            "content-type": "application/json",
            apikey: "abcdefgh",
          },
          maxAttempts: 5,
          body: JSON.stringify({
            id: args.data.ticket.id,
          }),
          staticIP: true,
        },
        (err, res, body) => {
          if (err) {
            console.log(err);
          }
          if (res) {
          }
          if (body) {
            console.log(body);
          }
        }
      );
    } catch (error) {
      console.log(error);
    }
  },
};

This is my code. Some of the headers of the heroku request are:

{
	host: 'api-checker-hit.herokuapp.com',
	connection: 'close',
	'content-type': 'application/json',
	apikey: 'abcdefgh',
	'x-request-id': '14226a3f-7518-46af-b8c3-90db635fad09',
	'x-forwarded-for': '13.232.211.56',
	'x-forwarded-proto': 'https',
	'x-forwarded-port': '443',
	via: '1.1 vegur',
	'connect-time': '1',
	'x-request-start': '1620370628119',
	'total-route-time': '0',
	'content-length': '14'
}
{
	host: 'api-checker-hit.herokuapp.com',
	connection: 'close',
	'content-type': 'application/json',
	apikey: 'abcdefgh',
	'x-request-id': '523059ac-6bf5-439d-b71a-101fc63e967d',
	'x-forwarded-for': '13.232.238.159',
	'x-forwarded-proto': 'https',
	'x-forwarded-port': '443',
	via: '1.1 vegur',
	'connect-time': '1',
	'x-request-start': '1620370625882',
	'total-route-time': '0',
	'content-length': '14'
}

Am I missing anything?

1 Like

Hi Neil,
Welcome to the developer community :tada:

staticIP option will only work with $request method and not with any third party libraries like request. I would suggest you use $request instead of request and let us know if it works.

2 Likes

2 posts were split to a new topic: Increase app rate limit