0

Currently trying to use the Web Services within Sharepoint Designer to create a list item in a list on a different site collection using the POST method.

The workflow itself runs til completion but no items are created.

I'm only trying to test it with the Title field alone.

enter image description here Here's the breakdown of my code:

ProjecSiteURL = http://www.mysite.sharepoint.com/sites/Apps/Project/
ProjectListName = Projects
CallDesiredAction = SP.Data.ProjectsListItem
CallURL =
 [%Variable:ProjectSiteURL%]/_api/web/lists/getbytitle('[%Variable:ProjectListName%]')/items

I have three dictionaries:

header:

Accept: application/json;odata=verbose
Content-Type: application/json;odata=verbose

metadata:

type: Variable: CallDesiredAction

parameters:

__metadata: Variable: metadata
Title: Created by REST

I then log the parameters, which is shown as the following on the workflow history log:

{"__metadata":{"type":"SP.Data.ProjectsListItem"},"Title":"Created by REST"}

Finally the REST call itself uses the POST method and uses the following settings:

enter image description here

The workflow executes but creates nothing, only other thing I can note is that the log I've created for the responseCode after the REST Call returns as "BadRequest"

Any help is greatly appreciated. Starting to bang my head against a wall!

  • 1
    You HTTP Web Service Properites doesn't show you using your headers for the RequestHeaders. Probably not the entire problem, but a start. Are you using app step permissions and given the workflow permissions cross-site collection? Here is also how I debug...After my rest call I have the end of a stage... if responseCode is OK then I proceed to the next stage, If it isn't OK I have a stage called REST error that emails me the CallURL, parameters, Responsde Content Response Headers (you'll need a variable) and the response code. That gives a lot mor einfo that you can get from logging. – Rothrock Nov 9 '17 at 17:42
  • Make sure your workflow from the source site (where your workflow is published) is able to perform actions on the target site. You can check this docs.microsoft.com/en-us/sharepoint/dev/general-development/… – harshal gite Nov 10 '17 at 17:03
  • It has the correct elevated permissions and the headers are assigned to the correct variable, I've just not taken the correct screenshot up top. I'll try the additional email stage in an IF statement and post the results when i'm done. – cod3r_jim Nov 13 '17 at 10:32
  • This doesn't help with your issue, but you can omit the __metadata property in the body if you use application/json;odata=nometadata or application/json;odata=minimalmetadata. @Rothrock's suggestions are spot on, and should help you isolate the issue. – wjervis Nov 13 '17 at 13:04
0

The endpoint is not correct:

CallURL =
 [%Variable:ProjectSiteURL%]/api/web/lists/getbytitle('[%Variable:ProjectListName%]')/items

Should be

CallURL =
 [%Variable:ProjectSiteURL%]/_api/web/lists/getbytitle('[%Variable:ProjectListName%]')/items

Here is one thread for your reference.

https://mysharepointexperiences.wordpress.com/2017/03/18/using-sharepoint-designer-2013-workflow-updatecreate-item-in-other-site-collection/

  • Again apologies, another typing error on my end when taking the screenshots. It has the appropriate underscore before api so it already says "_api" – cod3r_jim Nov 13 '17 at 10:31
0

Here's a working JQuery script to add an item to a page. This might help you ironing out any bugs.

The only thing I can think of that hasn't been touched upon is the list type property. This has to be the internal name of the list not the actual name (If there's a difference). So if you list "Projects" orginally was named something else that could be the issue.

var listType = "SP.Data.ChecklistDoneListItem"; //This is unique for each list, as far as I can tell it's composed of "SP.Data." + [Internal list name] + "ListItem"
var TargetListGuid  = "7437AE7D-92F4-4AAF-8D2E-7A6AA1F1978A";


/*
<<-- This is where you specify the list fields, remember to use the internal field name -->>
*/
        var item = {
            "__metadata": { "type": listType},
            "Title": "Se tjekliste",
            "Answer": checkmarkAnswers,
            "PhaseId": projectPhase,
            "ProjectTypeId": projectType,
            "ProjectId": projectId
        }

/*
<<-- This is the actual call to create the item in the list -->>
*/      
        $.ajax({
            url: _spPageContextInfo.siteAbsoluteUrl + "/_api/web/lists(guid'" + TargetListGuid + "')/items",
            type: "POST",
            contentType: "application/json;odata=verbose",
            data: JSON.stringify(item),
            headers: {
                "Accept": "application/json;odata=verbose",
                "X-RequestDigest": $("#__REQUESTDIGEST").val()
            },

            //This is where you put any actions when an item has been create. For instance an alert telling the user the data has been submittet
            success: function (data) {
                console.log("Success!");
                console.log(data); // Returns the newly created list item information
            },

            //This is where you put ant actions when creating the item for any reason didn't happen
            error: function (data) {
                console.log("Error!");
                console.log(data);
            }
        });

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.