Use the Packaging API to upload eBooks automatically to EditionGuard, as well as update existing eBooks and activate/deactivate them. It is particularly useful if you need to automate eBook packaging processes.

For instance when you need to add thousands of titles, it would be quite cumbersome to add them one by one through the web interfaces. Instead, you could call our API programmatically to upload eBooks in batches.

Another case maybe that you have business logic on your website that requires automatic operations performed on your eBooks only after some conditions are met. Again, you can call the API whenever it is needed within the flow of your application logic.

We recommend that you examine the sample form codes below to get a better understanding.

NOTE: the 'title' post variable must be a unique value as of May 19, 2015.

PHP

  <!-- 
  In this sample form, your EditionGuard account information is assumed to be:
  E-Mail Address: abc@yourdomain.com  
  Shared Secret: Secret
  Please replace these values with your own credentials to use the API on your account.
  -->
  <?php
  $secret = "Secret"; // Place your unique distributor shared secret, keep this safe or the api can be used in your stead by others!
  $nonce = rand(1000000, 999999999); // Random nonce value
  $email = "abc@yourdomain.com"; // Your e-mail address
  $hash = hash_hmac("sha1", $nonce.$email, base64_decode($secret)); // Generates your dynamic digital signature
  $resource_id = ""; // Include the resource id if you want to update an eBook that was uploaded before.
  ?>
  <form method="post" enctype="multipart/form-data" action="http://www.editionguard.com/api/package">
      <input type="hidden" name="email" value="<?php echo $email ?>" />
      <input type="hidden" name="nonce" value="<?php echo $nonce ?>" />
      <input type="hidden" name="hash" value="<?php echo $hash ?>" />
      Title: <input type="text" name="title" />

      Author: <input type="text" name="author" />

      Publisher: <input type="text" name="publisher" />

      File: <input type="file" name="file" />

      Resource Id (optional): <input type="text" name="resource_id" value="<?php echo $resource_id ?>" />

      <input type="submit" />
  </form>

ASP.NET C#

 <%@ Page Language="C#" %>
<%@ Import Namespace="System.Security.Cryptography"  %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

    /*
    In this sample page, your EditionGuard account information is assumed to be the below values. Please change them with your own credentials.
    E-Mail address: abc@yourdomain.com  
    Shared Secret: Secret
    Please replace these values with your own credentials to use the API on your account.
    */
    public string secret, nonce, email, hash, resource_id;
   
    protected void Page_Load(object sender, EventArgs e)
    {
        secret = "Secret"; // Place your unique distributor shared secret, keep this safe or the api can be used in your stead by others!
        nonce = RandomNumber(1000000, 999999999); // Random nonce value
        email = "abc@yourdomain.com"; // Your e-mail address
        hash = HashingHmacSha1(nonce + email, secret); // Generates your dynamic digital signature
         resource_id = ""; // Include the resource id if you want to update an eBook that was uploaded before.
    }

    private string HashingHmacSha1(string value, string key)
    {
        byte[] sharedSecretBytes = Convert.FromBase64String(key);
        ASCIIEncoding encoding = new ASCIIEncoding();
        HMACSHA1 hmacsha1 = new HMACSHA1(sharedSecretBytes);
        byte[] messageBytes = encoding.GetBytes(value);
        byte[] hashmessage = hmacsha1.ComputeHash(messageBytes);
        return ByteToString(hashmessage);
    }

    private string ByteToString(byte[] buff)
    {
        string sbinary = "";
        for (int i = 0; i < buff.Length; i++)
        {
            sbinary += buff[i].ToString("X2");
        }
        return (sbinary.ToLower());
    }
   
    private string RandomNumber(int min, int max)
    {
        Random random = new Random();
        return Convert.ToString(random.Next(min, max));
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
<form method="post" enctype="multipart/form-data" action="http://www.editionguard.com/api/package">
    <input type="hidden" name="nonce" value="<% =nonce %>" />
    <input type="hidden" name="email" value="<% =email %>" />
    <input type="hidden" name="hash" value="<% =hash %>" />
    Title: <input type="text" name="title" />

    Author: <input type="text" name="author" />

    Publisher: <input type="text" name="publisher" />

    File: <input type="file" name="file" />

    Resource Id (optional): <input type="text" name="resource_id" />

    <input type="submit" />
</form>
</body>
</html>

You use any other programming language or command line tool (such as curl) that can do a POST request similar to these forms in order to use this API.

After posting your form data, you will receive an XML response that denotes either a success or error. In the case of success, the returned XML will be similar to the one below.

  <resourceItemInfo xmlns="http://ns.adobe.com/adept">
  <resource>urn:uuid:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx</resource>
  <resourceItem>0</resourceItem>
  <metadata>
    <dc:title xmlns:dc="http://purl.org/dc/elements/1.1/">Book Title</dc:title>
    <dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Book Creator</dc:creator>
    <dc:format xmlns:dc="http://purl.org/dc/elements/1.1/">application/pdf</dc:format>
    <dc:publisher xmlns:dc="http://purl.org/dc/elements/1.1/">Book Publisher</dc:publisher>
  </metadata>
  <src>http://acs4.editionguard.com/media/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.pdf</src>
  <downloadType>simple</downloadType>
  <licenseToken>
    <resource>urn:uuid:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx</resource>
    <permissions>
      <display/>
    </permissions>
  </licenseToken>
</resourceItemInfo>

Once you get this success XML, you'll need to store the inner value of the resourceItemInfo/resource node. This is the unique identifier of your eBook in encrypted form on EditionGuard, and you will be using it for fulfillment purposes.

In the case of an error with packaging, you'll get an XML response similar to the one below.

<error xmlns="http://ns.adobe.com/adept" data="E_PACK_UNKNOWN_FILE_TYPE http://acs4.editionguard.com/packaging/Package"/>

If you get this error XML, you can look at the data attribute to see what the problem might be. If you're unable to make sense of the error and can't troubleshoot the issue on your own, please visit our Help Desk for further help.

Another feature of the packaging API is status management for your eBooks. You can activate or deactivate existing eBooks in your account anytime with this API. You use the same authentication logic as the previous forms, you only have to include an extra parameter called "status" in your form.

<form method="post" enctype="multipart/form-data" action="http://www.editionguard.com/api/set_status">
    <input type="hidden" name="email" value="your EditionGuard account email" />
    <input type="hidden" name="nonce" value="nonce" />
    <input type="hidden" name="hash" value="hash" />
    Resource Id: <input type="text" name="resource_id" />

    Status: <select name="status"><option value="active">Active</option><option value="inactive">Inactive</option></select>

    <input type="submit" />
</form>

Finally, you can also delete eBooks you uploaded by doing a call to the delete service of the API.

<form method="post" enctype="multipart/form-data" action="http://www.editionguard.com/api/delete">
    <input type="hidden" name="email" value="your EditionGuard account email" />
    <input type="hidden" name="nonce" value="nonce" />
    <input type="hidden" name="hash" value="hash" />
    Resource Id: <input type="text" name="resource_id" />

    <input type="submit" />
</form>

Did this answer your question?