Step 2: Add Data to your Site

In addition to sending API requests with tools like Postman, you can also connect to the Content Delivery API via JavaScript (jQuery) and display attributes for one entity on your webpage.

  1. Set up an API call using jQuery in your JavaScript file to pull one entity.

      $(document).ready(function () {
       apiKey = <YOUR_API_KEY>,
        vParam = <YYYYMMDD>,
         entityID = <ENTITY_ID>,
         $.ajax({
            type: 'GET',
            url : 'https://cdn.yextapis.com/v2/accounts/me/entities/'     
                + entityId + '?api_key=' + apiKey + '&v=' + vParam,
            success: function(data, textStatus, xhr){
            // TODO: your callback function 
     // TIP: parse your response with: JSON.parse(xhr.responseText).response        
         }, error: function(xhr, textStatus, errorThrown) {
                console.log('Unable to load data')
            }
        });
     });
  2. Populate your parameters

    • API Key – (see instructions in the previous step for obtaining your API Key)
    • v parameter (Optional) – you can fill in the date you started your integration in YYYMMDD format if you do not want to receive any breaking changes to the API
    • Entity ID – use the Entity ID from Knowledge Graph for the entity you want to return
  3. Parse the JSON response you receive from the API

    • You can see an example response body in Using the Content Delivery API guide.

      var response = JSON.parse(xhr.responseText).response
      
       // Examples of grabbing individual values 
      var entityName = response.name
      var address = response.address
  4. Display the data on your webpage.

Feedback