cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
lalcabasa
Nintex Newbie

How to use REST API GetItems POST query in Nintex Forms for O365?

Hi All,

 

We are using SharePoint Online with Nintex Forms O365. We are trying to query a SharePoint List from the host web from Nintex Forms O365 but is facing difficulty.

 

We are using REST API POST query because of a calculated field. Currently, we are facing difficulty  using it because Nintex Forms is located in a separate App Web, resulting in an Access Denied (403) error when trying to access the Host Web URL.

 

    var hostweburl = decodeURIComponent(getQueryStringParameter("SPHostUrl"));
    var appweburl = decodeURIComponent(getQueryStringParameter("SPAppWebUrl"));  
    
    var viewXml = "<Query><Where><And><And><Geq><FieldRef Name='EndDate_Adjusted' /><Value Type='DateTime'>" + str_startdate + "</Value></Geq><Leq><FieldRef Name='StartDate_Adjusted' /><Value Type='DateTime'>" + str_enddate + "</Value></Leq></And><Eq><FieldRef Name='Workflow_x0020_Status' /><Value Type='Text'>Blocked</Value></Eq></And></Where></Query>";      
    var queryPayload = {
        'query': {
            '__metadata': { 'type': 'SP.CamlQuery' },
            'ViewXml': viewXml
        }
    };

    var url = appweburl + "/_api/SP.AppContextSite(@target)/web/lists/GetByTitle('Booking Requests')/getitems?@target='" + hostweburl + "'";
    var executor = new SP.RequestExecutor(appweburl);
    executor.executeAsync(
        {
            url: url,
            method: "POST",
            body: JSON.stringify(queryPayload),
            headers: {
                "Accept": "application/json; odata=verbose",
                "content-type": "application/json; odata=verbose",
                "X-RequestDigest": NWF$("#__REQUESTDIGEST").val()
            },
            success: function (data) {
                var jsonobj = JSON.parse(data.body);
                var results = jsonobj.d.results;
                
                for (var i = 0; i < results.length; i++){
                    blocked.push({ID: results[i].ID});   
                }
                
                deferred.resolve(Boolean(valid));
            },
            error: function (data) {
                console.error(data);
                deferred.reject(Boolean(valid));
            }
        }
    );

We cannot use GET request because EndDate_Adjusted and StartDate_Adjusted are calculated fields, which $filter does not support.

 

We cannot get / fill-in the correct RequestDigest because querying /api/_contextinfo would also need a POST query, which results in Access Denied as well.

 

What are the options that we can use / do in order to use REST API POST query?

 

Thank you

Labels: (1)
Tags (3)
Reply
2 Replies
Community Manager Community Manager
Community Manager

Re: How to use REST API GetItems POST query in Nintex Forms for O365?

I see what you are trying to do, but why? What are you trying to get items on a form?

 

You can use list lookup control, a prepopulated dropdown control, or javascript. But again its difficult to help without know what you're really after. 

0 Kudos
Reply
lalcabasa
Nintex Newbie

Re: How to use REST API GetItems POST query in Nintex Forms for O365?

We are doing a custom display and post processing of the items. 

We have solved it by using JSOM instead of REST.

0 Kudos
Reply