Store Article Views Code Samples
Use the code samples below as examples to create an application in your desired language. The following code samples use the /user/store-article-views endpoint which allows you to post article views. Get started and begin to understand the endpoint by following the examples below in the language of your choice.
# Store article views:
curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' --header 'authorization: Bearer TOKEN' -d \
'{
  "items": [
    {
     "article": {
         "id": "T116388",
         "title": "Acute Lymphoblastic Leukemia\/Lymphoma (ALL)",
         "section": {
            "title": ""
         }
      },
      "eventType": "OPEN_ITEM",
      "prevSearchTerm": "",
      "timestamp": "2020-10-19T19:04:03Z"
    }
  ]
}' \
'https://apis.ebsco.com/medsapi-dynamic-health/v1/user/store-article-views'
// Store Article Views:
// Construct the client
OkHttpClient client = new OkHttpClient();
// Create the URL
HttpUrl url = new HttpUrl.Builder()
    .scheme("https")
    .host("apis.ebsco.com")
    .addPathSegment("medsapi-dynamic-health")
    .addPathSegment("v1")
    .addPathSegment("user")
    .addPathSegment("store-article-views")
    .build();
// Build the body   
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, "{
  \"items\": [
    {
     \"article\": {
         \"id\": \"T116388\",
         \"title\": \"Acute Lymphoblastic Leukemia\/Lymphoma (ALL)\",
         \"section\": {
            \"title\": \"\"
         }
      },
      \"eventType\": \"OPEN_ITEM\",
      \"prevSearchTerm\": \"\",
      \"timestamp\": \"2020-10-19T19:04:03Z\"
    }
  ]
}");     
// Build the request
Request request = new Request.Builder()
    .url(url)
    .post(body)
    .addHeader("Accept", "application/json")
    .addHeader("Authorization", "Bearer TOKEN")
    .addHeader("Content-Type", "application/json")
    .build();
// Send the request
Response response = client.newCall(request).execute();
// Store Article Views: 
var host = "https://apis.ebsco.com";
var path = "/medsapi-dynamic-health/v1/user/store-article-views";
// Create the Request
var url = host + path;
var settings = {
  "async": true,
  "crossDomain": true,
  "url": url,
  "method": "POST",
  "processData": false,
  "data": '{
  "items": [
    {
     "article": {
         "id": "T116388",
         "title": "Acute Lymphoblastic Leukemia\/Lymphoma (ALL)",
         "section": {
            "title": ""
         }
      },
      "eventType": "OPEN_ITEM",
      "prevSearchTerm": "",
      "timestamp": "2020-10-19T19:04:03Z"
    }
  ]
}',
  "headers": {
        Accept: "application/json",
        Authorization: "Bearer TOKEN",
        Content-Type: "application/json"
  }  
}
// Send the Request
$.ajax(settings).done(function (response) {
  console.log(response);
});
# Form the URL 
urlstr = File.join('https://', 'apis.ebsco.com', '/medsapi-dynamic-health', '/v1', '/user/store-article-views')
url = URI(urlstr)
 
# Create the HTTP object
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
 
# Create the request
request = Net::HTTP::Put.new(url)
request["Accept"] = "application/json"
request["Authorization"] = "Bearer TOKEN"
request["Content-Type"] = "application/json"
request.body = '{"items":["article":{"id":"T116388", "title": "Acute Lymphoblastic Leukemia\/Lymphoma (ALL)", "section":{"title":""}],"eventType":"OPEN_ITEM","prevSearchTerm":"", "timiestamp":"2020-10-19T19:04:03Z"}'
 
# Send the request
response = http.request(request)
# Store Article Views:
# Form the URL
url = ''.join(['/medsapi-dynamic-health','/v1', '/user', '/store-article-views'])
# Create Connection Instance
conn = http.client.HTTPSConnection("apis.ebsco.com")
# Payload
payload =  '{"items":["article":{"id":"T116388", "title": "Acute Lymphoblastic Leukemia\/Lymphoma (ALL)", "section":{"title":""}],"eventType":"OPEN_ITEM","prevSearchTerm":"", "timiestamp":"2020-10-19T19:04:03Z"}'
 
# Create the Request Headers
headers = {
    "Authorization": "Bearer TOKEN",
    "Accept": "application/json",
    "Cache-Control": "no-cache"
    }
# Send Request  
conn.request("POST", url, payload, headers)
 
            