DOTCMS REST API

26 views
Skip to first unread message

Henry Versemann

unread,
Oct 12, 2017, 10:44:31 AM10/12/17
to dot...@googlegroups.com

I’m getting a “(401) Unauthorized” exception returned from trying to send an add new content request to the REST API.

 

I’m trying to send to this URI:

 

$url = "https://www.stchas.edu:443/api/content/publish/1"

 

Using these headers:

 

$headers = @{"Authorization"=$authHdrSffx} (for basic authentication)

$headers.Add("Accept","text/plain")

$headers.Add("Content-Type","application/json")

 

And the following body of data (in json format):

 

{

    "stName": "Employees",

       "languageId": 1,

       "prefix": "",

       "firstName": "Dum",

       "middleInitial": "D",

       "lastName": "Dummy",

       "nickname": "Dummy",

       "title": "Adjunct Faculty",

       "type1": "adjunct",

       "phoneNumber": "636-922-9999",

       "email": "ddu...@stchas.edu",

       "fax": "999-999-9999",

       "picture": "",

       "quickEducation": "Bachelors",

       "education": "Bachelors",

       "bio": "nothing",

       "building": "Administration",

       "room": "4123",

       "slug": "",

       "pagetitle": "",

       "headline": ""

}

 

And I am trying to send the request using the POST method via https (port 443).

 

I’m using the PowerShell Invoke-WebRequest commandlet like this to do it:

 

Invoke-WebRequest -URI $url -Body $body -Headers $headers -Method POST

 

I’m not sure what exactly the problem is, since I thought I had everything correct based on the documentation for the Invoke-WebRequest commandlet, including the credentials part of the documentation.

 

Is it possible that the url I’m trying to hit is not correct, since it is listed under the examples for the Original API, instead of the New API?

 

Any help would be greatly appreciated.

 

Thanks.

 

Henry

 

 

Nathan Keiter

unread,
Oct 12, 2017, 10:53:05 AM10/12/17
to dot...@googlegroups.com

I find it helpful to test RESTful APIs using Google’s “Advanced REST Client” program. (It’s free.)

 

https://advancedrestclient.com/

https://chrome.google.com/webstore/detail/advanced-rest-client/hgmloofddffdnphfgcellkdfbfbjeloo?hl=en-US

 

Get it to work there first, then try it with your script.

 

The 401 seems to be a permissions error. Check the access log or dotcms log for clues.

 

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/BLUPR0501MB1700C9334EA49EFE1EC3CA67AD4B0%40BLUPR0501MB1700.namprd05.prod.outlook.com.
For more options, visit https://groups.google.com/d/optout.

Mark Pitely

unread,
Oct 12, 2017, 11:01:12 AM10/12/17
to dot...@googlegroups.com
Set that content type permission to CMS_Anonymous (publish) to test. I don't see you sending any credentials-  dotCMS *should* be locking you out.

Mark Pitely
Marywood University

To unsubscribe from this group and stop receiving emails from it, send an email to dotcms+unsubscribe@googlegroups.com.

--
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+unsubscribe@googlegroups.com.

To post to this group, send email to dot...@googlegroups.com.

Nathan Keiter

unread,
Oct 12, 2017, 11:02:58 AM10/12/17
to dot...@googlegroups.com

He’s using a base 64 encoded authentication string. That happens to be my preferred method as well.

 

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

 

From: dot...@googlegroups.com [mailto:dot...@googlegroups.com] On Behalf Of Mark Pitely
Sent: Thursday, October 12, 2017 11:01 AM
To: dot...@googlegroups.com
Subject: Re: [dotcms] RE: DOTCMS REST API

 

Set that content type permission to CMS_Anonymous (publish) to test. I don't see you sending any credentials-  dotCMS *should* be locking you out.

Mark Pitely

Marywood University

On Thu, Oct 12, 2017 at 10:53 AM, Nathan Keiter <nke...@gettysburg.edu> wrote:

I find it helpful to test RESTful APIs using Google’s “Advanced REST Client” program. (It’s free.)

 

https://advancedrestclient.com/

https://chrome.google.com/webstore/detail/advanced-rest-client/hgmloofddffdnphfgcellkdfbfbjeloo?hl=en-US

 

Get it to work there first, then try it with your script.

 

The 401 seems to be a permissions error. Check the access log or dotcms log for clues.

 

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

 

To unsubscribe from this group and stop receiving emails from it, send an email to dotcms+un...@googlegroups.com.

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

 

--

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.

Henry Versemann

unread,
Oct 12, 2017, 11:24:34 AM10/12/17
to dot...@googlegroups.com

Thanks Nathan. I’ll check it out.

Henry Versemann

unread,
Oct 12, 2017, 11:25:19 AM10/12/17
to dot...@googlegroups.com

Thanks Mark.

I am using Base64.

 

Henry

 

From: dot...@googlegroups.com [mailto:dot...@googlegroups.com] On Behalf Of Mark Pitely


Sent: Thursday, October 12, 2017 10:01 AM
To: dot...@googlegroups.com

To unsubscribe from this group and stop receiving emails from it, send an email to dotcms+un...@googlegroups.com.

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

 

--

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.

Nathan Keiter

unread,
Oct 12, 2017, 11:27:24 AM10/12/17
to dot...@googlegroups.com

In Google Advanced Rest Client, if you right click in headers and choose authentication, it will ask for username/password and automatically base 64 encode the value for you. J

Henry Versemann

unread,
Oct 12, 2017, 11:37:28 AM10/12/17
to dot...@googlegroups.com

Henry Versemann

unread,
Oct 13, 2017, 4:55:09 PM10/13/17
to dot...@googlegroups.com

I’m trying to search our departments structure for a value of “Network Operations” and after some dynamic constructing and editing of the REST API url to inquire against the final url looks like this:

 

https://www.stchas.edu:443/api/content/query/+contentType:Departments%20+_all:network*%20+_all:operations*%20languageId:1%20+deleted:false%20+live:true/orderby/modDate%20desc

 

and I’ve already tried stripping out the space characters (%20), but I still keep getting a 400 Bad Request when I send it.

 

Most of the url was originally copied from our backend “show query” button, so I think it should be close.

 

Thanks for the help.

 

Henry

 

 

 

 

 

Nathan Keiter

unread,
Oct 13, 2017, 5:03:29 PM10/13/17
to dot...@googlegroups.com

 

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

 

From: dot...@googlegroups.com [mailto:dot...@googlegroups.com] On Behalf Of Henry Versemann
Sent: Friday, October 13, 2017 4:55 PM
To: 'dot...@googlegroups.com'
Subject: [dotcms] DOTCMS REST API

 

I’m trying to search our departments structure for a value of “Network Operations” and after some dynamic constructing and editing of the REST API url to inquire against the final url looks like this:

--

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.

Nathan Keiter

unread,
Oct 13, 2017, 5:08:12 PM10/13/17
to dot...@googlegroups.com

Oh, never mind that was an underscore.  The original link works for me.

 

Result:

 

{"contentlets":[{"modDate":"2015-12-09 10:07:07.012","pageTitle":"","description":"","title":"Network Operations","building":"","inode":"99ded5ed-56ec-4899-aab5-fd84d1e4b0bc","academicDepartment":false,"__DOTNAME__":"Network Operations","host":"SYSTEM_HOST","lastReview":"2015-12-09 10:07:06.995","fax":"","stInode":"765899e6-e895-4036-a4b0-546a2ad4d2fa","headline":"","slug":"network-operations","owner":"nhogan","identifier":"c3829700-3f84-4077-9743-a3463a7f5050","image":"","languageId":1,"officeHours":"","URL_MAP_FOR_CONTENT":"\/academics\/departments\/network-operations","room":"","folder":"SYSTEM_FOLDER","sortOrder":0,"modUser":"nhogan","name":"Network Operations","slugMaker":""}]}

 

 

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

 

Henry Versemann

unread,
Oct 13, 2017, 5:48:40 PM10/13/17
to dot...@googlegroups.com

OK.

I figured out that I was still trying to send the query with the POST method and I think its supposed to be using the GET method. So when I made that change then I stopped getting the 400 Bad Request, but my response back from the query didn’t seem to have any contentlets that it brought back, so I’m still puzzled about that.

 

Nathan thanks for the help.

 

Have a good weekend.

 

Henry

Reply all
Reply to author
Forward
0 new messages