Empty REST API Request Results - From https powershell request

4 views
Skip to first unread message

Henry Versemann

unread,
Nov 6, 2017, 3:22:25 PM11/6/17
to dot...@googlegroups.com

I have a department in our departments structure which when I search for it using its name through the REST API brings back no contentlets, even though I can log into our backend and see the department listed in the departments structure, with some data.

 

For this reason I’m assuming that there is indeed a contentlet for the department named below and I’m just not formatting my https request properly somehow.

 

The name of the department contains a single-quote and looks like this:

 

President’s Office

 

I’ve tried replacing the single-quote with a %27 to try to properly url encode it and that doesn’t seem to work because I’m still not finding any contentlets for it, in my response, though I am still receiving back a 200 status code.

 

I have also tried converting the single-quote to two single-quotes (‘’) back to back, as well as to a back slash single quote (\’) to try to escape the single-quote, but so far nothing seems to work and bring back any data.

 

I’m actually sending my formatted url request using the Invoke-WebRequest commandlet.

 

Any help would be greatly appreciated.

 

HDV

 

 

 

 

 

 

Nathan Keiter

unread,
Nov 6, 2017, 3:40:56 PM11/6/17
to dot...@googlegroups.com

Since it’s a two word term, have you tried encapsulating it in quotes or asterisks?

 

+Department.name=“President’s Office”

 

+Department.name=“*President’s Office*

 

Nathan I. Keiter | Lead Network Applications Programmer | Benefits Advisory Council Member | I.D.E.A Council Member
Gettysburg College | Information Technology | DataSystems
Campus Box 2453 | 300 North Washington Street | Gettysburg, PA 17325
Phone: 717.337.6993

https://www.gettysburg.edu

--
http://dotcms.com - Open Source Java Content Management
---
You received this message because you are subscribed to the Google Groups "dotCMS User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dotcms+un...@googlegroups.com.
To post to this group, send email to dot...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/dotcms/CY4PR0501MB37772028D29B3AABEC88F77FAD500%40CY4PR0501MB3777.namprd05.prod.outlook.com.
For more options, visit https://groups.google.com/d/optout.

Henry Versemann

unread,
Nov 6, 2017, 3:46:24 PM11/6/17
to dot...@googlegroups.com

Nathan,

 

No I have not but I will try that shortly.

Thanks for the response.

 

Henry

Henry Versemann

unread,
Nov 6, 2017, 5:04:35 PM11/6/17
to dot...@googlegroups.com

Nathan,

 

Will I tried both of those alternatives with no success.

 

So then just to see if I could do it I copied the following 3 url variations into a brand new browser window and hit enter and each one brought back the data that I’m trying to get at. Here are the 3 url variations I used:

 

https://dotcmsstaging.stchas.edu:443/api/content/query/+contentType:Departments%20+Departments.Name:*President's%20Office*%20+languageId:1%20+deleted:false%20+live:true

 

 

https://dotcmsstaging.stchas.edu/api/content/query/+contentType:Departments%20+Departments.Name:President's%20Office*%20+languageId:1%20+deleted:false%20+live:true

 

 

https://dotcmsstaging.stchas.edu/api/content/query/+contentType:Departments%20+Departments.Name:President's%20Office%20+languageId:1%20+deleted:false%20+live:true

 

So I’m not sure what the difference is when I build my url in the powershell script, but it’s not working properly.

 

So when I build my final url before submitting it through the Invoke-WebRequest commandlet I’m doing this to concatenate the different url parts together into the final url which will be subnmitted like this:

 

        $dprtmntSrchUrlPt1 = "https://dotcmsstaging.stchas.edu:443/api/content/query/+contentType:Departments%20+Departments.Name:"

        $dprtmntSrchUrlPt3 = "*%20+languageId:1%20+deleted:false%20+live:true"

 

With the dprtmntSrchUrlPt2 variable being my department name string to search with and then concatenating the individual parts together to build the final url looking like this:

 

$dptNameSrchUrl = "{0}{1}{2}" -f $dprtmntSrchUrlPt1, $dprtmntSrchUrlPt2, $dprtmntSrchUrlPt3

 

The –f then formats and concatenates all of the above string variables together to build the final url to be sent to the REST API.

 

The funny thing is when I try to submit the https request through the powershell invoke-webrequest commandlet, as shown above then I keep getting a 401 unauthorized response/status code.

 

Which probably means I don’t have my request exactly right and so the API thinks I’m trying to go to an endpoint that is either protected or doesn’t exist.

 

So I’m not sure what more to check the url for since it looks ok to me, unless the current concatenation process somehow is adding or changing some of the original characters, and thereby pointing the request to an invalid page or endpoint.

 

Any thoughts on what to try next?

 

Henry

Nathan Keiter

unread,
Nov 7, 2017, 8:46:18 AM11/7/17
to dot...@googlegroups.com

Well, unfortunately I have zero experience using PowerShell program scripts.

 

Could you check the access logs on the dotCMS server and see what URL is actually hitting the server? That might give you a clue as to what is malformed by the script.

Henry Versemann

unread,
Nov 7, 2017, 8:50:41 AM11/7/17
to dot...@googlegroups.com

OK. I’ll try to get that information.

Thanks.

Reply all
Reply to author
Forward
0 new messages