top of page
Writer's picturecongcanbelthydixil

SharePoint 2013 REST API with Fiddler and SPD: An In-depth Review



Its interesting I can perform the same api call using java but not succeed with SPD. I need to get this working with SPD, this needs to work using OOTB. So I'm still stuck as to why one server works and the other one does not. But I'm still investigating.....




More on SharePoint 2013 REST API with Fiddler and SPD



SharePoint 2013 has a completely new workflow engine. With that engine we got some new actions and options that help us in creating our bussiness process using workflows. One of them is Call HTTP serviceaction that enables us to leverage an external web service from our workflow.On the other hand Sharepoint 2013 comes with a new REST interface that enables us to access and use its resources.When we combine these two new features we get powerful new ways for using our SharePoint workflows.In this post I will show you how you can use this new action to POST new data to your SharePoint site.I have created a SharePoint list named WorkflowItems to use for example. We will create items in this list from a workflow using SharePoint REST services. To keep it simple I will leave it with only one column (Title).Now we can open our SharePoint Designer and create a new site workflow and call it WorkflowItemWizard.In our new workflow first we will create couple of dictionaries. Dictionary is a new variable type in SharePoint workflows that is used for defining collections of key/pair values and is very important for the Call HTTP service action.To create a dictionary add Build Dictionary action to you workflow. Using that action specify two new keys Accept and Content-Type and set the values for both of them to application/json; odata=verbose like in the image below


Set the output to a dictionary with a more meaningful name, call it "header". This dictionary will be used as a header for our request.Next create another dictionary that you will call metadata and in it add a key called type with value SP.Data.WorkflowItemsListItem. And finally you will need one more dictionary that will contain your request data. Call it parameters, add key __metadata and set its value to the previously created dictionary metadata


Now you can deploy your workflow and run it. Once it is over you should have a new item created in your list.From this example you can continue building your solutions, you can add more fields, or use other available REST services for updating list items or deleting them. One of the biggest advantages using this method to create or update list items is it is not limited to the site in which you workflow runs. Using REST services you can now access and create items in lists on other sites.If you want to know more about SharePoint 2013 REST you should check this out :Programming using the SharePoint 2013 REST serviceAlso check this excellent post on getting data into your workflow from SharePoint


Thanks for your helpful post, Lee. I tried to set up a POST request using Fiddler but ended with 403 FORBIDDEN error. -handling-http-403-forbidden-when-querying-the-search-rest-service-using-the-postquery-method/


The only debugging option that is available in every type of SharePoint deployment is writing log messages to the workflow history list. By using this method, you can use either the Log to History List action in SharePoint Designer 2013 or the WriteToHistory activity in Visual Studio 2012 to write a string message as a new item to the list, specified in the workflow association, which is the container for all history logging messages. These can be simple strings or constructed by concatenating the contents of variables within the workflow.


Another debugging option is to take advantage of breakpoints. Breakpoints are available only for workflows created using Visual Studio 2012, since SharePoint Designer 2013 has no capability to set breakpoints or to attach a debugger to the running process. These are available in both SharePoint on-premises and hosted deployments such as Office 365. In this scenario, you would set a breakpoint on an activity within the workflow and then start the workflow in debug mode.


This debugging option is not available for workflows created using SharePoint Designer 2013, because there is no action that maps to the WriteLine activity. Unfortunately, this debugging option is available only to SharePoint on-premises installations, since the port used by the Test Service Host utility is typically not publically accessible outside an on-premises network. This is also true for Office 365. The ports SharePoint uses to connect to Workflow Manager are the same ones used by the Test Service Host, and those are only accessible within the trusted network. However, this does not mean that you need to change their workflows to remove any WriteLine activities before deployment to Office 365. These activities can be left in the workflow as they are not seen unless the Test Service Host is connected to Workflow Manager.


  • Notice that the second result is the one we used by default: sts, for a Team Site.Scroll to the bottom to find custom templates that have been saved for the site collection:

  • Find the Name of the template you want to use, and right-click on it to select Copy

  • Use this value in your SPD 2013 callParams dictionary for the WebTemplate item, when using the Call HTTP Web Service action to create a site.Be sure to remove the Name= portion highlighted in the image.

  • Now when your App Step runs, it will use this custom template when creating new sites.

In SharePoint, there is always (or usually) more than one way to do things.


Therefore the preferred method is to use install Fiddler onto the workflow manager server, and configure it to trace HTTP calls from workflow manager. This method is more reliable and easier to work with, but is relatively tricky to set it all up. Luckily for all of us, Andrew Connell wrote comprehensive and clear instructions for using this approach.


Thank you for this. After finding this blog, I found some other references to using CAML with GetItems and using the CAML as the request body (no more encoding spaces!). Anatoly Mironov described its use here -caml-with-sharepoint-rest-api/ and referenced the MSDN documentation here -us/library/office/dn531433%28v=office.15%29.aspx#bk_ListGetItems.


Remote SharePoint development is getting more important. Especially with SharePoint Apps. To speed up development, find hidden lists/items/documents, discover the structure or specific artifact properties use the SharePoint Client Browser which supports SharePoint 2010, SharePoint 2013 and SharePoint Online (Office 365)


In the above post I will take a Publicly Available REST API probably the Weather API or Twitter API and use the HTTP Web Request along with the Dictionary Variable in SPD 2013 to surface it in a SharePoint Promoted Links App (List)


Some things that you must know about Workflows in SharePoint 2013 is that unlike SharePoint 2010 that was built on the platform of Windows Workflow Foundations 3.0 (WWF3) this version of SharePoint is built on Windows Workflow Foundation 4.0 (WWF4) and .NET Framework 4.5, it also employs a new Installer/Manager called Workflow Manager 1.0. Now you have the ability to design and create complete declarative workflows, REST and Service Bus messaging. You should also be aware that the SharePoint 2013 features and capabilities only comes available to you and your tooling after you download and install the Workflow Manger 1.0 Service and configure it to communicate with your Site Collection. For more on the Workflow Manager 1.0 please see Start: Set up and configure SharePoint 2013 Workflow Manager Finally with Visio Professional 2013 add-in provides you with a Visual Workflow Development experience both inside SPD2013 and outside inside Visio Professional 2013.


'use strict';var express = require('express');var request = require('request');var http = require('http');var path = require('path');var passport = require('passport');var AzureAdOAuth2Strategy = require('passport-azure-ad-oauth2');var engine = require('ejs-locals');var app = express();var config = // Enter the App ID URI of your application. To find this value in the Windows Azure Management Portal, // click Active Directory, click Integrated Apps, click your app, and click Configure. // The App ID URI is at the bottom of the page in the Single Sign-On section. realm: ' :4000', // Enter the endpoint to which your app sends sign-on and sign-out requests when using WS-Federation protocol. // To find this value in the Windows Azure Management Portal, click Active Directory, click Integrated Apps, // and in the black menu bar at the bottom of the page, click View endpoints. // Then, copy the value of the WS-Federation Sign-On Endpoint. // Note: This field is ignored if you specify an identityMetadata url identityProviderUrl: ' -8647-xxxxxxx/wsfed', // Enter the logout url of your application. The user will be redirected to this endpoint after // the auth token has been revoked by the WSFed endpoint. logoutUrl: 'http:/localhost:4000/', // Enter the URL of the federation metadata document for your app or the cert of the X.509 certificate found // in the X509Certificate tag of the RoleDescriptor with xsi:type="fed:SecurityTokenServiceType" in the federation metadata. // If you enter both fields, the metadata takes precedence identityMetadata: ' -8647-4dc7-xxxxxxxx/federationmetadata/2007-06/federationmetadata.xml';var graphConfig = // Enter the domain for your Active directory subscription, such as contoso.onmicrosoft.com tenant: '8b87af7d-8647-4dc7-xxxxxxxxxxxxxxx', // Enter the Client ID GUID of your app. // In the Windows Azure Management Portal, click Active Directory, click your tenant, // click Integrated Apps, click your app, and click Configure. // The Client ID is on this app configuration page. clientid: '2462ee60-5695-xxxxxxxxxxxxxx', //Enter the value of the key for the app. You can create the key on the Configure page for the app. // The value appears only when you first save the key. Enter the saved value. clientsecret: 'xxxxxxxxxxxxxxxx';// array to hold logged in usersvar users = [];// AAD Graph Client for AAD queriesvar graphClient = null;var aToken;// use ejs-locals for all ejs templates:app.engine('ejs', engine);app.configure(function() app.set('port', process.env.PORT );app.configure('development', function() app.use(express.errorHandler()););var findByEmail = function (email, fn) for (var i = 0, len = users.length; i " + accessToken); aToken = accessToken; console.log("done ---> " + JSON.stringify(done)); var waadProfile = profile ));var sp_files = function(callback) { var headers = 'Authorization': 'Bearer ' + aToken, 'Accept': 'application/json', ; if (RESOURCE.indexOf("graph") != -1) headers[ 'x-ms-dirapi-data-contract-version'] = '0.5'; console.log("CALL___________________ "+REST_CALL); request( url: REST_CALL,// qs: qs, headers: headers , function(err, resp, body) { console.log("Body " + body); console.log("Err " + err);// if (err) return callback(err, null); if (resp && resp.statusCode != 200) return callback(new Error(body), null); else if (!resp) return callback(null, null); // results: // [ __metadata: [Object],// Manager: [Object],// DirectReports: [Object], var d = JSON.parse(body).d, users = d.results;// meta = buildMetadata(d); console.log("users" + users); return callback(users); ) console.log("Sent request---->");http.createServer(app).listen(app.get('port'), function() console.log("Express server listening on port " + app.get('port')););var graphQuery = function(res, user) graphClient.getUsers(function(err, result) if(err) res.end('GraphClient.getUsers error:' + err + '\n'); else console.log("User " + JSON.stringify(result) ); //res.render('index', user: user, data: JSON.stringify(result) ); // get user properties (user.DisplayName, user.Mail, etc.) );;var doWaad = function(res, user) if(graphClient === null) waad.getGraphClientWithClientCredentials2(graphConfig.tenant, graphConfig.clientid, graphConfig.clientsecret, function(err, client) if(err) res.end('waad.getGraphClientWithClientCredentials2 error:' + err + '\n'); else graphClient = client; graphQuery(res, user); ); else graphQuery(res, user); ;app.get('/cb', function(req, res) console.log("cb"););app.get('/fail', function(req, res) console.log("fail"););app.get('/ok', function(req, res) console.log("*************** ok ", req.user); //doWaad(res, req.user););app.get('/', function(req, res) if (aToken) console.log("T: " + aToken); sp_files(function(d) var mail = []; if (d) for (var i=0; i>>> " + d[i]);// if (d[i].Mail)// mail.push(d[i].Mail); if (d[i]) mail.push(JSON.stringify(d[i])); res.render('result', user: d, data: mail, oauth: aToken); ); else res.render('index', user: null); );app.get('/account', ensureAuthenticated, function(req, res) res.render('account', user:req.user ););app.get('/login', passport.authenticate('azure_ad_oauth2', failureRedirect: '/fail' ));app.get('/callback', passport.authenticate('azure_ad_oauth2', failureRedirect: '/', failureFlash: true ), function(req, res) // Successful authentication, redirect home. console.log("================= callback"); res.redirect('/ok'); );app.get('/logout', function(req, res)// clear the passport session cookies req.logout();// We need to redirect the user to the WSFED logout endpoint so the// auth token will be revoked wsfedStrategy.logout(, function(err, url) if(err) res.redirect('/'); else res.redirect(url); ););// Passport session setup.// To support persistent login sessions, Passport needs to be able to// serialize users into and deserialize users out of the session. Typically,// this will be as simple as storing the user ID when serializing, and finding// the user by ID when deserializing.passport.serializeUser(function(user, done) done(null, user.email););passport.deserializeUser(function(id, done) findByEmail(id, function (err, user) done(err, user); );); 2ff7e9595c


0 views0 comments

Recent Posts

See All

Traffic rider mod apk por an1

Traffic Rider Mod APK por AN1: uma revisão Se você é fã de jogos de corrida de moto, já deve ter ouvido falar Piloto de Trânsito, um jogo...

Comentarios


bottom of page