pinpoint.updateEndpoint Giving error "NotFoundException: Resource not found"

-1

I am trying to create a dynamic segment in amazon pinpoint and then add endpoints. In Postman i am able to create/update the pinpoint endpoint with AWS signature but when I tried to implement the same in the NodeJS project i am getting "Resource Not Found" exception. Where i am missing something? Any solution, please!

here is my code:

const AWS = require('aws-sdk');
accessKeyId = process.env.ACCESS_KEY_ID,
secretKey = process.env.SECRET_KEY

AWS.config.update({
    region: 'ap-southeast-2',
    accessKey: accessKeyId,
    secretAccessKey: secretKey,
});

const pinpoint = new AWS.Pinpoint({
    accessKey: accessKeyId,
    secretAccessKey: secretKey,
    region: 'ap-southeast-2',
    signatureVersion: 'v4',
});
const endpointAddress = obj.phone;
console.log(">>>Endpoint Address: ", endpointAddress)  //I am getting this value

const endpointID = obj_id.toString();
console.log(">>>EndpointID: ", endpointID)  //I am getting this value as well

const params = {
    ApplicationId: 'a35e50bc1ec54c18a53294c6e610da5d' /* required */,
    EndpointId: endpointID /* required */,
    EndpointRequest: {
        /* required */
        Address: endpointAddress,
        ChannelType: 'VOICE',
        EndpointStatus: 'ACTIVE',
        OptOut: 'NONE',
        Location: {
            Country: obj.country,
        },
        Demographic: {
            Make: 'Apple',
            Platform: 'iOS',
        },
        EffectiveDate: '2022-08-11',
        Attributes: {
            Interests: ['Technology', 'Music', 'Travel'],
            CampaignIdentifier: ['OB'],
        },
        Metrics: {
            technology_interest_level: 9,
            music_interest_level: 6,
            travel_interest_level: 4,
        },
        User: {
            UserAttributes: {
                firstName: [obj.firstname],
                lastName: [obj.lastname],
                country: [obj.country]
            },
            UserId: "user-20" //obj_id.toString()
        },
    },
};

pinpoint.updateEndpoint(params).promise().catch((er) => {
    console.log(er);
});
return endpointID;

      //res.status(200).end();
    });
asked 2 years ago1246 views
2 Answers
2

Thank you for sharing the sample code snippet. Please allow me to share my observations :-

  1. NotFoundException could occur in case if the resource being referenced could not be found. Therefore, Could you please verify whether the parameters such as Pinpoint Application ID (This identifier is displayed as the Project ID on the Amazon Pinpoint console), Region, Object etc. that are being passed are passed as expected ?

  2. Next, I tried using the following snippet in a Lambda function keeping your your code as a reference and I was able to successfully create/update an endpoint associated with the user ID: user-20. I simply added the try-catch block and await in front of the promise. The following is the sample Lambda function code I used at my end :-

const AWS = require('aws-sdk');
accessKeyId = process.env.ACCESS_KEY_ID,
secretKey = process.env.SECRET_KEY

AWS.config.update({
    region: 'ap-southeast-2',
    accessKey: accessKeyId,
    secretAccessKey: secretKey,
});
const pinpoint = new AWS.Pinpoint({
    accessKey: accessKeyId,
    secretAccessKey: secretKey,
    region: 'ap-southeast-2',
    signatureVersion: 'v4',
});

exports.handler = async (event) => {
const endpointAddress = '+91123456778'; // TODO: PLEASE ENTER ENDPOINT'S PHONE NUMBER
console.log(">>>Endpoint Address: ", endpointAddress)  

const endpointID = '1234';
console.log(">>>EndpointID: ", endpointID)  // TODO: PLEASE ENTER THE ENDPOINT ID 

const params = {
    ApplicationId: 'abcdefghijkl' // PLEASE ENTER YOUR APPLICATION ID,
    EndpointId: endpointID ,
    EndpointRequest: {
        /* required */
        Address: endpointAddress,
        ChannelType: 'VOICE',
        EndpointStatus: 'ACTIVE',
        OptOut: 'NONE',
        Location: {
            Country: "IN" 
        },
        Demographic: {
            Make: 'Apple',
            Platform: 'iOS'
        },
        EffectiveDate: '2022-08-11',
        Attributes: {
            Interests: ['Technology', 'Music', 'Travel'],
            CampaignIdentifier: ['OB']
        },
        Metrics: {
            technology_interest_level: 9,
            music_interest_level: 6,
            travel_interest_level: 4
        },
         User: {
            UserAttributes: {
                firstName: ["Dev"],
                lastName: ["A"],
                country: ["India"]
            },
            UserId: "user-20"
        }
        }
    }

try {
   const res= await pinpoint.updateEndpoint(params).promise();
   console.log(res);
}catch(err){
    console.log(err);
}
return endpointID;
};

Lastly, I verified that the updateEndpoint is working by using the CLI get-endpoint and get-user-endpoints operations and I could notice the endpoint details as a successful response.

Having said that, in case you face further challenges, please feel free to open a support case with AWS using the following link.

AWS
SUPPORT ENGINEER
Dev_A
answered 2 years ago
0
Accepted Answer

I am able to reslove the issue by some modifications i used:

AWS.config.update({
    secretAccessKey: process.env.AWS_SECRET_ACCESS,
    accessKeyId: process.env.AWS_ACCESS_KEY,
    region: 'ap-southeast-2',
  });

const pinpoint = new AWS.Pinpoint();
pinpoint.updateEndpoint(params, function (err, data) {
      if (err) {
        console.log('An error occurred.\n');
        console.log(err, err.stack);
      } else {
        console.log(
          'Endpoint added Successfully with endpoint ID ' + endpointID
        );
      }
    });

No need to add credentials in pinpoint object while creation.

answered 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions