Set Up JQuery to Interact with the Smart Publish API

by User Not Found | Feb 06, 2012

What did we ever do before JQuery came about?  Back in the day, when we wanted to use AJAX to interact with services from the browser using javascript, we had to detect which browser was being used and use the appropriate objects to call the services. We then had to write browser specific code to update the UI since there were subtle differences in how to perform DOM manipulations in code.  Thanks to JQuery, all of those nuances have been abstracted and we can let the library take care of those subtleties. Here are some tips in getting JQuery to work for you when you want to call our Smart Publish API (SPA) services.  

At this point you should be signed up for our services and have set up an application through our Partner Workspace. Each application will have it's own APIKey which you will need to interact with our services.  The APIkey is passed in the header of each call to the SPA Services. Without this header, the service will return a "403 Forbidden" http code. 

JQuery makes it easy to set up default values for all ajax interactions by using the $.ajaxSetup function and we'll take advantage of that to make sure the APIKey is added to all calls.  In this example, we'll create a javascript function that  sets the request header value for Authorization and then in the $(document).ready function, we'll set the default ajax values. Don't forget to replace YOURAPIKEYHERE with the APIKey that you get from the Application Management Partner Workspace page (you'll need to be logged in to access that page). 


function AddAuthHeaders(xhr, settings) {

    xhr.setRequestHeader('Authorization', 'apikey=YOURAPIKEYHERE');
     //perform any other header updates you need here

$(document).ready(function () {
    //set default values for all of the service calls
        contentType: "application/json",
        dataType: "json",
        beforeSend: AddAuthHeaders


Alright, we've gotten that authorization header out of the way, now we need to tell JQuery that it's ok to make cross origin scripting requests since the services are not hosted at the same URL as the web site.  Some browsers throw errors and some don't (Internet Explorer will complain with a "No Transport" error if you don't do this), so we can generally handle this by adding the following in the $(document).ready function: = true;


One last bit of housekeeping to take care of and that's to make sure the protocol of your AJAX requests are the same as the containing web page.  Usually what I do is keep a global javascript variable that contains the root of the RESTful requests including whether they should be called through http or https. I'll usually define the value in the $(document).ready by getting the window.location.protocol value and appending it to a constant for the service root URI. The SPA API requires all calls coming in to be through https, so at the point you're making the SPA calls, your page should be at an https URL.  Putting it all together, the $(document).ready function looks like this:


//defined up here so that they have global scope
var apiKey = "YOURAPIKEYHERE";
var serviceRootURI = ""; //test URI
function AddAuthHeaders(xhr, settings) {
    xhr.setRequestHeader('Authorization', 'apikey=' + apiKey);
    //do any other header adds here
$(document).ready(function () {
    //set default values for all of the service calls
        contentType: "application/json",
        dataType: "json",
        beforeSend: AddAuthHeaders
    }); = true;
    serviceRootURI = window.location.protocol + "//" + serviceRootURI;
    //setup is complete, do other stuff now :)

With this code in the JQuery $(document).ready function and the AddAuthHeaders helper function, we're ready to start making calls to the Smart Publish API. The next blog entry will look at the use of our JQuery library for interacting with the individual services. Until then, feel free to leave us a comment to let me know what you think!


  1. 1 swiggy android app 27 May
    swiggy android app
    This article was written by a real thinking writer.
  2. 2 cheap authentic jordans 26 May
    Mens Air Jordan 12 has genuine leather upper for durable comfort.Mens The Air-Sole units offers excellent cushioning for Air Jordan 12.
  3. 3 David Clark 26 May
    Thanks for this wonderful info
    Checkout this awesome article : How to Jailbreak Roku
  4. 4 david clark 26 May
    Thanks for the information .
    Do check out this link : How to Jailbreak Roku
  5. 5 aptoide for pc 18 May
    best alternative for the Google Play store available on the market is the Aptoide for pc
    <a href="">aptoide for pc</a>
  6. 6 official 01 May
    <a href=""></a>

  7. 7 stevesmith 27 Apr
    I guide the students that how they can pass the exams and how can they get the certification for the latest knowledge this certification exam students click at c_hanaimp_11 syllabus its certification its better for your bright future and will helpful to attain the IT certification
  8. 8 John Mathew 24 Apr
    Such a great click
  9. 9 ppsspp gold apk 16 Apr
    ppsspp gold apk available here  
  10. 10 marathi dj songs 16 Apr
  11. 11 tutu app pokemon go 06 Apr
    Tutu app Pokemon go is a Chinese origin application which is a free application for android and ios users. This application was developed by Chinese developers to make the games better as compared to their available versions. 
    <a href=""/>tutu app Pokemon go</a>

  12. 12 Tutu app Pokemon go 06 Apr
    Tutu app Pokemon go is a Chinese origin application which is a free application for android and ios users. This application was developed by Chinese developers to make the games better as compared to their available versions. 
    <a href=""/>tutu app pokemon go</a>
  13. 13 05 Apr : we are going to provide you the information regarding MP Board 10th Result 2017

  14. 14 Robert 29 Mar
    Developers are allowing us to get at their data much more Money Converter transparently now, never again is everything safety secured. Sites are pleased to have you get their information and actually.
  15. 15 Jack kevin 22 Mar
    Engineers are permitting us to get at information substantially more Custom Assignment Help straightforwardly now, never again is everything safety guarded. Sites are pleased to have get to their information and, truth be told, energize it.
  16. 16 Joseph Dahlgren 20 Mar
    Hi! I really sympathize with your situation. I'm going through the same thing right now and have looked into the manga industry and found opportunities for manga artists to publish their own original titles are quite limited. Yen Press is the only prominent publisher working on OEL titles right now and they are largely concentrating on adapting properties with already built in audiences. James Patterson and other YA books like the Parasol Protectorate series. My suggestion is to definitely launch it as a webcomic, build a following cheap custom essay online and self-publish the work yourself. Yes, indeed, it is a lot of hard work but trust me when I say this hard work pays off. You will come to understand the publishing process intimately, will have more control over the way your book is presented and do marketing on your own terms using Facebook, Twitter. Understanding what goes into a successful launch of a book better equips you to approach a publisher down the road. As a beginner, you don't have enough clout to negotiate terms with them unless 1 You are up to your ears in talent or 2 you already have a strong following through other means via Deviantart etc.
  17. 17 swiggy hyderabad offers 23 Feb
    Thanks for the post
  18. 18 best gaming mouse under 50 04 Feb
    <a href="">best gaming mouse</a>

  19. 19 Bishop consultancy 03 Feb
    I have known about JQuery yet don't comprehend what it does. Like what does it really JQuery convey to a site? For instance, i need a live webcam talk on my assignment help UK site. In the event that i utilize JQuery by what means will it help me?
  20. 20 jimmy 22 Jan visit now if you want to download best apk apps
  21. 21 James Cameron 19 Jan
    The agenda utilize JavaScript, we wanted to know which plan was being Buy Assignment utilize the appropriate substance to call the administration. We then required composing agenda exacting system to overhaul.
  22. 22 download Kik messenger for laptop 10 Jan
    Kik for PC on Windows 10/8.1/8/7. download Kik messenger for laptop & MAC using Bluestacks & Android.
  23. 23 How To Write A Research Paper 06 Jan
    JSON-based APIs are a hot property on the Web at this moment. I can't recall the last time I went onto a blog or portfolio without seeing the proprietor's tweets or Facebook companions How To Write A Research Paper gazing back at me. This intuitiveness makes the Web an energizing spot. As far as possible is by all accounts individuals' creative energy. As exhibited by everything from pulled tweets to a mindful trade rates API, information is at present ruler, and sites are swapping it uninhibitedly.
  24. 24 llya 15 Dec

    <a href="">bgfgfhsg</a>[url=]wendyouyt[/url]
  25. 25 SBI UPI App 09 Dec
    Learn How to download SBI UPI App. You can easily transfer money without using the bank account details of the payee through the SBI Pay App.
  26. 26 New Year 2017 Images 08 Dec
    That’s why people are looking for the New Year Wishes, quotes and messagesThat’s why people are looking for the New Year Wishes, quotes and messages

  27. 27 OnePlus 5 Specs 06 Dec
    Here's everything we know about the OnePlus 4. Get Release Date, Price, Features, Rumors and Specifications of OnePlus 4.
    OnePlus 5 Specs

  28. 28 agjsgf 16 Nov
    Coaching makes the pre-adult careful. In custom dissertation writing services countries sex preparing has amazing congruity. Sex preparing is extremely helpful to supervise secondary school pregnancy. Sex guideline moreover offers information to sexually sent ailments.
  29. 29 dumpy 24 May