-
Notifications
You must be signed in to change notification settings - Fork 0
Additional Information For Backend Integrations
Requests issued directly from the user's browser contain a number of useful data points, namely User-Agent and X-Forwarded-For. These are necessary for Constructor.io to understand the origin of requests to adequately ensure DDOS prevention.
The Constructor security token also plays an important role to help us identify requests to ensure it is originating from an actual customer and not a malicious user. If the token is not supplied with each request, it is highly likely that the requests to our server will get throttled.
In order to power personalization, an anonymous user identifier and session identifier are stored in the users browser and automatically transmitted with requests in a frontend integration. In a backend integration, these values will need to be read from cookies and transmitted with requests.
In summary, here are the fields that should be sent with all requests originating server side (backend integrations):
- ConstructorioConfig.ConstructorToken (Mandatory)
- A unique string supplied by Constructor to be transmitted with requests originating from the backend. This value should be treated as sensitive information and never exposed client side.
- ConstructorioConfig.ServiceUrl (Mandatory)
- Requests must also be pinned to a single data center. In order to do this, we’ll provide a specific host which you’ll use to interact with Constructor’s API. That is, all calls will be sent to https://[subdomain].cnstrc.com, where [subdomain] is a string that will be provided to you by your integrations engineer. Note, this does not apply to calls to update catalogs.
- UserInfo.forwardedFor (Mandatory)
- Containing the IP of the origin request from the users browser.
- UserInfo.clientId & UserInfo.sessionId (Mandatory)
- The client and session id parameters live in the browser's cookies and are sent along with all requests. You should be able to grab them from the
ConstructorioID_client_id
andConstructorioID_session_id
cookies, respectively
- The client and session id parameters live in the browser's cookies and are sent along with all requests. You should be able to grab them from the
- UserInfo.userId (Mandatory for logged-id users)
- A unique internal identifier for a logged-in user. Used for cross device personalization.
- UserInfo.userAgent
- Containing the User-Agent of the origin request from the users browser
The request service url and Constructor security token are set in the ConstructorioConfig prior to instantiation of the ConstructorIO client. Here's an example of how that looks like:
ConstructorioConfig config = new ConstructorioConfig("apiKey", "apiToken");
config.ConstructorToken = "YOUR SECURITY TOKEN";
config.ServiceUrl = "https://[subdomain].cnstrc.com" // defaults to https://ac.cnstrc.com
ConstructorIO constructorio = new ConstructorIO(config);
Information about the user will be passed with each request using the UserInfo
object. Here is an example request:
UserInfo userInfo = new UserInfo("ConstructorioID_client_id cookie", 1); // These values come from `ConstructorioID_client_id` and `ConstructorioID_session_id` cookies, respectively.
userInfo.SetForwardedFor("30.19.91.1"); // The IP the request originated from
userInfo.SetUserAgent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.84 Safari/537.36");
userInfo.SetUserId("user-id-1"); // This value is a unique internal identifier for a logged in user.
BrowseRequest req = new BrowseRequest("filterName", "filterValue");
req.UserInfo = userInfo;
constructorio.Browse.GetBrowseResults(req);