How to use Custom Code in AEP Web SDK to send data to Individual profile dataset | Community
Skip to main content
Level 2
December 11, 2023
Solved

How to use Custom Code in AEP Web SDK to send data to Individual profile dataset

  • December 11, 2023
  • 2 replies
  • 3930 views

Hi Team,

It has been mentioned in a few posts that the Web SDK can't be used to ingest data from the data layer to individual profiles directly, but custom code can be used. Can anyone please help with the syntax or a sample JS or JSON code to achieve this?

Old, related community posts

https://experienceleaguecommunities.adobe.com/t5/adobe-experience-platform/data-flow-from-aep-web-sdk-to-real-time-cdp-profile/m-p/443861#M571

https://experienceleaguecommunities.adobe.com/t5/adobe-experience-platform/sending-profile-data-via-web-sdk/m-p/602788#M2603

It would be really helpful if you could provide some pointers on this.

Regards,
Deepan

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by abhinavbalooni

Hey @e-deepanraj 

 

You can use custom code but one thing you would need to understand is that in that case you would just be making use of the custom code functionality within Adobe data collection tags (launch) and not explicitly using web sdk.

 

You will be making use of a HTTP API Streaming endpoint which would need to be setup under sources within AEP.

 

Then, in your custom code, you would be using that streaming endpoint and sending a POST request to it with a payload.

 

Please note, I would suggest you ask your backend team to handle this rather than you doing it through launch as this can be got hold of and played with easily from Adobe Launch.

 

Sharing a sample JS that should work for you when you fit relevant values for your setup.

 

function lambdaHandler(event, context) { const url = "<Your Streaming Endpoint URL>"; // JSON payload const payloadData = { header: { schemaRef: { id: "<Schema ID>", contentType: "application/vnd.adobe.xed-full+json;version=1.0" }, imsOrgId: "<YOUR ORG ID>", datasetId: "<YOUR DATASET ID>", source: { name: "Streaming dataflow - 10/15/2023, 2:30 PM" } }, body: { xdmMeta: { schemaRef: { id: "<Your Schema ID>", contentType: "application/vnd.adobe.xed-full+json;version=1.0" } }, xdmEntity: { _id: "/uri-reference", _repo: { createDate: "2023-12-11T12:00:00-06:00", modifyDate: "2023-12-11T12:00:00-06:00" }, _spnam: { identification: { core: { email: '<your email>' } } }, person: { name: { firstName: 'test league' } } } } }; // Convert the payload to JSON const payloadJson = JSON.stringify(payloadData); // Headers const headers = new Headers(); headers.append('Content-Type', 'application/json'); headers.append('sandbox-name', '<Sandbox Name>'); headers.append('Authorization', 'Bearer YOUR_AUTHORIZATION_TOKEN'); // Replace with your actual Authorization token // Request options const options = { method: 'POST', headers: headers, body: payloadJson }; // Make the POST request fetch(url, options) .then(response => { if (response.status === 200) { return response.text(); } else { throw new Error("Failed to call the API"); } }) .then(data => { console.log(data); }) .catch(error => { console.error(error); }); } // Example usage: const event = { }; lambdaHandler(event, null);

 I removed a few bits which were not relevant and you might need to tweak it a bit but this should give you a start. 

2 replies

abhinavbalooni
Community Advisor
abhinavbalooniCommunity AdvisorAccepted solution
Community Advisor
December 11, 2023

Hey @e-deepanraj 

 

You can use custom code but one thing you would need to understand is that in that case you would just be making use of the custom code functionality within Adobe data collection tags (launch) and not explicitly using web sdk.

 

You will be making use of a HTTP API Streaming endpoint which would need to be setup under sources within AEP.

 

Then, in your custom code, you would be using that streaming endpoint and sending a POST request to it with a payload.

 

Please note, I would suggest you ask your backend team to handle this rather than you doing it through launch as this can be got hold of and played with easily from Adobe Launch.

 

Sharing a sample JS that should work for you when you fit relevant values for your setup.

 

function lambdaHandler(event, context) { const url = "<Your Streaming Endpoint URL>"; // JSON payload const payloadData = { header: { schemaRef: { id: "<Schema ID>", contentType: "application/vnd.adobe.xed-full+json;version=1.0" }, imsOrgId: "<YOUR ORG ID>", datasetId: "<YOUR DATASET ID>", source: { name: "Streaming dataflow - 10/15/2023, 2:30 PM" } }, body: { xdmMeta: { schemaRef: { id: "<Your Schema ID>", contentType: "application/vnd.adobe.xed-full+json;version=1.0" } }, xdmEntity: { _id: "/uri-reference", _repo: { createDate: "2023-12-11T12:00:00-06:00", modifyDate: "2023-12-11T12:00:00-06:00" }, _spnam: { identification: { core: { email: '<your email>' } } }, person: { name: { firstName: 'test league' } } } } }; // Convert the payload to JSON const payloadJson = JSON.stringify(payloadData); // Headers const headers = new Headers(); headers.append('Content-Type', 'application/json'); headers.append('sandbox-name', '<Sandbox Name>'); headers.append('Authorization', 'Bearer YOUR_AUTHORIZATION_TOKEN'); // Replace with your actual Authorization token // Request options const options = { method: 'POST', headers: headers, body: payloadJson }; // Make the POST request fetch(url, options) .then(response => { if (response.status === 200) { return response.text(); } else { throw new Error("Failed to call the API"); } }) .then(data => { console.log(data); }) .catch(error => { console.error(error); }); } // Example usage: const event = { }; lambdaHandler(event, null);

 I removed a few bits which were not relevant and you might need to tweak it a bit but this should give you a start. 

Level 2
December 11, 2023

Thanks @abhinavbalooni Let me check with this JS,

I was just curious about the Datastream AEP service. It has a profile dataset as an optional selection, so is there any use in having that to send the profile data, or is it a feature that is not fully functional yet?

 

abhinavbalooni
Community Advisor
Community Advisor
December 11, 2023

@e-deepanraj That's a fair query and I had the same question when I started working on data streams but till now I haven't seen any use for it or even documentation showing how it works. Might well be a solution in works for now.

 

Cheers.

Rudi-Shumpert
Adobe Employee
Adobe Employee
December 13, 2023

So it's not with the webSDK directly but within datastreams.  https://experienceleague.adobe.com/docs/experience-platform/datastreams/configure.html?lang=en

 

""Profile Dataset Select the Platform dataset that customer attribute data will be sent to. This schema must use the XDM Individual Profile class."" 

 

Disregard my comment above.  This can NOT be used to send profile data.  Working to get the UI & Docs updated to reflect that.  Sorry for any confusion. 

abhinavbalooni
Community Advisor
Community Advisor
December 13, 2023

@rudi-shumpert Thanks for this Rudi.

 

Do you have any documentation where we can see this mapping of the profile dataset being used through a datastream? Would be really helpful as I haven't been able to make use of this particular mapping till date. Might be an oversight at my end.

 

Cheers,

Abhinav

Rudi-Shumpert
Adobe Employee
Adobe Employee
December 13, 2023

Disregard my comment above.  This can NOT be used to send profile data.  Working to get the UI & Docs updated to reflect that.  Sorry for any confusion.