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 Kristan 17 Jul
  2. 2 Eset nod32 antivirus 10 crack 2017 11 Jul
    <a href="">Eset nod32 antivirus 9 activation key 2018</a>
  3. 3 idm crack 10 Jul
  4. 4 a10 08 Jul
    It is my first time I visit here. The way you create a website very thorough and good. This is very very impressive. I found so many entertaining stuff in your blog, especially its discussion. I will continually be coming on a regular basis you just read your posts.
    a10, color switch, animal jam
  5. 5 Help With Biology Assignment 01 Jul
    by visiting this site I found cool stuff here keep it up.Help With Biology Assignment
  6. 6 BBA Assignment Help 01 Jul
        Pretty helpful material, much thanks for this article
    BBA Assignment Help
  7. 7 Tom Hardy Bane Vest 22 Jun
    Interesting article! Thank you for sharing them! I hope you will continue to have similar posts to share with everyone.
  8. 8 windows 7 loader activator 22 Jun
    good post
  9. 9 windows 7 loader by daz 22 Jun
    nice post
  10. 10 windows 7 loader activator 22 Jun
  11. 11 mobdro for ios 22 Jun
    Mobdro is a smart movie organiser and based on the internet, the app will automatically determine the quality of the movie
  12. 12 Brand designs 21 Jun
    This is an awesome post..thanks a lot

    brand designs
    website designs
  13. 13 Download Key 15 Jun
    [url=]Download full version[/url]
    This is Very Nice Post Fantastic material and amazing article.I most want to say that you are doing a great job.Thanks for this nice article.[url=]Download full version[/url]
  14. 14 Sophie 15 Jun
    This is an exceptional post I seen on account of offer it. It is really what I anticipated that would see search for in future you will proceed with consequent to sharing such a dazzling smart. Top Gun Brown Jacket

  15. 15 assignment providers help 12 Jun
    ADHD is a tough situation to be in for families and patients. Of course, parents are hoping their children will grow up to be healthy, but things happen along the way. That’s why science is there to explain and seek solutions. I hope more young kids aspire to be scientists or be involved with the field of science. They can end up as scientists, botanists, biologists, doctors of medicine, and other noble professions. I hope they make the right choice.
    assignment providers help
  16. 16 Case Study Help 08 Jun
    An incredible article you write, very very interesting and informative. I hope you will keep writing articles as good as this, so I gained extensive insight. Thanks a lot! 

    Case Study Help
  17. 17 YUYU 07 Jun
    Much interesting article and I am so delighted to be here and to gather this awesome post. Thanks a lot sir. fake yeezy boost 350 for sale
  18. 18 opopo 07 Jun
    Much interesting article and I am so delighted to be here and to gather this awesome post. Thanks a lot sir. <a href="">fake yeezy boost 350 for sale</a>
  19. 19 Cheap Lebron James Sneakers 06 Jun
    <a href="">Cheap Lebron James Sneakers</a> with hyperposite midsole, these shoes provides strong support for fast movement.
  20. 20 Buy Cheap Essay 30 May
    Notice something different around here? That’s right -- we’ve given our website a bit of a facelift! We’re pleased to unveil our new look, with a sleeker design and easier-to-find features. Our new site more effectively highlights what’s most important to us and to our community. Plus, it’s mobile-friendly (hello, 21st century!), so you can browse FAoS opportunities and resources on the go.
  21. 21 swiggy android app 27 May
    swiggy android app
    This article was written by a real thinking writer.
  22. 22 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.
  23. 23 David Clark 26 May
    Thanks for this wonderful info
    Checkout this awesome article : How to Jailbreak Roku
  24. 24 david clark 26 May
    Thanks for the information .
    Do check out this link : How to Jailbreak Roku
  25. 25 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>
  26. 26 official 01 May
    <a href=""></a>

  27. 27 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
  28. 28 John Mathew 24 Apr
    Such a great click
  29. 29 ppsspp gold apk 16 Apr
    ppsspp gold apk available here  
  30. 30 marathi dj songs 16 Apr
  31. 31 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>

  32. 32 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>
  33. 33 05 Apr : we are going to provide you the information regarding MP Board 10th Result 2017

  34. 34 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.
  35. 35 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.
  36. 36 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.
  37. 37 swiggy hyderabad offers 23 Feb
    Thanks for the post
  38. 38 best gaming mouse under 50 04 Feb
    <a href="">best gaming mouse</a>

  39. 39 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?
  40. 40 jimmy 22 Jan visit now if you want to download best apk apps
  41. 41 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.
  42. 42 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.
  43. 43 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.
  44. 44 llya 15 Dec

    <a href="">bgfgfhsg</a>[url=]wendyouyt[/url]
  45. 45 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.
  46. 46 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

  47. 47 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

  48. 48 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.
  49. 49 dumpy 24 May