I am trying to send a web-push subscription object to my API, which consists of 'endpoint' and 'keys'.
The problem I seem to be having is when this object reaches my API it has the 'Keys' values but the 'endpoint' value is null. Yet when I debug it I can confirm that the endpoint value is defined.
This is the JS code I am using:
async function Subscribe() {
let sw = await navigator.serviceWorker.ready;
let push = await sw.pushManager.subscribe({
userVisibleOnly: true,
applicationServerKey:
'ApplicationServerKeyHere'
});
console.log(JSON.stringify(push)); //Store this in DB
fetch("https://localhost:44325/Subscribe", {
method: "POST",
//credentials: "same-origin", // include, *same-origin, omit
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(push)
});
}
endpoint is populated before the Fetch POST is sent:
And then empty when it arrives at the API:
The incoming JSON has 'endpoint' as field while your DOTNET model class as 'enpoint' as field (mismatch in field names in json-payload and model class that will accept the json payload)