Expand my Community achievements bar.

My request from server side is coming as undefind for the most value, any idea why?

Avatar

Level 2

Hello there,

I am using NodeSDK on the react code base to send requests to prefetch offers. I am seeing most of the values are coming back undefined from the Adobe server, is there a reason? Am I missing anything in the request?

 

My request is simple: 

 

 

 prefetch: {
      mboxes: [
        {
          index: 0,
          name: 'mbox Name'
        }
      ]
    }

 

 

 

Pravinrams1_0-1727447267161.png

 

2 Replies

Avatar

Community Advisor

Hi @Pravinrams1 

At initial level, check that your Node SDK is properly initialized with the correct credentials. Incorrect or missing configuration for the Adobe services (like credentials, API keys, or tenant information) could result in invalid responses.

2) Make sure your Mbox is active and exists in Adobe Target. 

3) When using the prefetch method, ensure that you're not confusing it with execute in your code. prefetch is for retrieving offers in advance, but if the configuration or targeting is off, it could return undefined.

4) Caching issues - Sometimes cached offers or mismatches in timing (when the prefetch request is made vs when it's used) can cause issues. Please clear your cache.

5)  Use logger optional object -  in order to debug. 

Here is the sample code again 

import AdobeTargetClient from '@adobe/target-nodejs-sdk';

// Initialize client
const client = AdobeTargetClient.create({
  client: '<YOUR_CLIENT_ID>',
  organizationId: '<YOUR_ORG_ID>',
  apiKey: '<YOUR_API_KEY>',
  targetHostname: 'your-target-url',
  logger: console
});

// Prefetch offers
client.getOffers({
  sessionId: '<SESSION_ID>',
  visitorId: '<VISITOR_ID>',
  context: {
    channel: 'web',
    address: {
      url: 'https://your-site.com',
    },
    browser: {
      host: 'your-site.com',
      userAgent: navigator.userAgent,
    },
  },
  prefetch: {
    mboxes: [
      {
        name: 'your-mbox-name',
        index: 0
      }
    ]
  }
}).then((response) => {
  console.log(response);
}).catch((error) => {
  console.error('Error fetching offers:', error);
});

 

Avatar

Level 2

Thank you @Gokul_Agiwal 

It was an issue with windows.targetGlobalsettings and it's now working and getting a response from the server with the content. I can see prefetch only has getoffers not applyoffers like Client Side. How do I then apply the script I received from Adobe to the actual webpage page? 

 

One more question: On the request I see you used navigator.userAgent to get the browser details but it only works on the client side because navigator is not available on the server side right?

 

AT Response (I masked some of the info because not sure if it can be public): 

SSR_Response.png