Integration amazon

SAM321
Tera Contributor

Hi there!.... How to integrate servicenow with amazon , so that i can get amazon product details in servicenwo... Iam new to integration..Can anyone help on how the flow go.

7 REPLIES 7

Punit S
Giga Guru

Hi Abhijith , Happy to help . 

 

To integrate ServiceNow with Amazon, you can use Amazon's Product Advertising API (PA-API) to retrieve product details and then use ServiceNow's IntegrationHub to create a flow to consume the data.

Here are the high-level steps you need to follow:

  1. Create an Amazon developer account and register for PA-API credentials.
  2. Generate an access key and secret key for your ServiceNow instance.
  3. Create a ServiceNow REST message to call the Amazon PA-API.
  4. Create a ServiceNow script include to handle the response from the PA-API.
  5. Create a ServiceNow workflow that triggers the REST message and uses the script include to process the response.
  6. Create a ServiceNow catalog item that allows users to search for Amazon products and displays the details in ServiceNow.

Here's a detailed explanation of each step:

  1. Create an Amazon developer account and register for PA-API credentials.

    • Go to the Amazon Associates website (https://affiliate-program.amazon.com/)
    • Click on "Join Now for Free" and follow the registration process.
    • Once you're registered, go to the "Product Advertising API" page and click "Join."
    • Follow the instructions to create an application and generate your credentials.
  2. Generate an access key and secret key for your ServiceNow instance.

    • Log in to your ServiceNow instance as an administrator.
    • Go to "System OAuth > Application Registry."
    • Create a new application and generate an access key and secret key.
  3. Create a ServiceNow REST message to call the Amazon PA-API.

    • Go to "System Web Services > Outbound > REST Messages."
    • Create a new REST message and fill in the following fields:
    • In the "HTTP Headers" section, add the following headers:
      • Content-Type: application/json
    • In the "HTTP Request Body" section, add the following JSON:
       

 

{
    "PartnerType": "Associates",
    "PartnerTag": "<your partner tag>",
    "Keywords": "${searchTerm}",
    "Marketplace": "www.amazon.com",
    "Resources": [
        "Images.Primary.Small",
        "ItemInfo.Title",
        "Offers.Listings.Price",
        "Offers.Listings.Availability.Message",
        "Offers.Listings.Condition",
        "DetailPageURL"
    ],
    "ItemCount": 1
}

Replace 'your partner tag' with your Amazon Associates Partner Tag.

 

  • Create a ServiceNow script include to handle the response from the PA-API.

    • Go to "System Definition > Script Includes."
    • Create a new script include and fill in the following fields:
      • Name: AmazonProductResponseHandler
      • Accessible from: All application scopes
    • In the script body, add the following code:
       

 

var AmazonProductResponseHandler = Class.create();
AmazonProductResponseHandler.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    processResponse: function(response) {
        var responseBody = JSON.parse(response.getBody());
        var product = responseBody.Items[0];
        var title = product.ItemInfo.Title.DisplayValue;
       

 

Please mark my answer correct/helpful in case it adds value and moves you a step closer to your desired ServiceNow solution goal. 

Thanks,
Punit

 

SAM321
Tera Contributor

@Punit S Hi sir ...as i didnt get proper api.. It is paused. But inspite of it another task.

So i got third party api, which has no authentication . The purpose is when i create new user data in sys_user table . Then the third party also should get new user created. In rest message post http method i created this.

Screenshot (114)_LI.jpg

and the after insert business rule used is.

 

Screenshot (115).png

But anyhow its not creating data in third party tool..can you help to achieve this

Punit S
Giga Guru

I would recommend you to get more familiarity with REST APIs . It's a best practice to have authentication and it does protect your data from being accessed or exposed. 

To accomplish what you described , you can use ServiceNow's Outbound REST Message functionality to send data to the third party API whenever a new user is created in the sys_user table. Here are the high-level steps you can follow:

  1. Define the REST endpoint and payload format of the third-party API. You'll need to know the URL of the endpoint, the HTTP method to use (e.g. POST), and the expected payload format (e.g. JSON).

  2. Create a new Outbound REST Message in ServiceNow. This involves defining the URL of the third-party API endpoint, the HTTP method to use, and any headers or payload data that need to be sent.

  3. Create a Business Rule in ServiceNow that triggers whenever a new user record is inserted into the sys_user table. The Business Rule should call the Outbound REST Message created in step 2 and pass it the user data to be sent to the third-party API.

  4. Test the integration to ensure that new user data is being sent to the third-party API correctly.

Here are some additional details to keep in mind:

  • When creating the Outbound REST Message, be sure to define any required headers (such as Content-Type or Authorization) and include the payload format and data as needed.

  • In the Business Rule, you can access the user data using the GlideRecord API. For example, you could use var gr = new GlideRecord('sys_user'); gr.query(); while (gr.next()) { /* send user data to API */ } to loop through all user records and send each one to the third-party API.

  • Be sure to handle any errors or exceptions that may occur when sending data to the third-party API. You can use try/catch blocks or ServiceNow's built-in logging and error handling functionality to handle these cases.

  • It's a good practice to use asynchronous processing when calling external APIs from ServiceNow, especially if the API may take a long time to respond. You can use ServiceNow's async APIs (such as GlideAsyncCallback or GlideScriptable) to handle this.

 

Please ensure to mark my answer correct/helpful in case it adds value and moves you a step closer to your desired ServiceNow solution goal. 

Thanks,
Punit

SAM321
Tera Contributor

@Punit S Hi, In log its showing this!

Screenshot (121).png