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
I find it helpful to test RESTful APIs using Google’s “Advanced REST Client” program. (It’s free.)
https://advancedrestclient.com/
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
--
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.
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.
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.
--
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 view this discussion on the web visit https://groups.google.com/d/msgid/dotcms/3877388989f345ca82aa1af68ad83180%40exch13c.ms.gettysburg.edu.
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
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/
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
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.
--
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/3877388989f345ca82aa1af68ad83180%40exch13c.ms.gettysburg.edu.
For more options, visit
https://groups.google.com/d/optout.
--
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/CAFeiKqM_Bk-Q1PjE2CAV4gOdD-PjxZdacX_-45gOYq3Dn7FmAg%40mail.gmail.com.
Thanks Nathan. I’ll check it out.
To view this discussion on the web visit https://groups.google.com/d/msgid/dotcms/3877388989f345ca82aa1af68ad83180%40exch13c.ms.gettysburg.edu.
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.
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.
--
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/3877388989f345ca82aa1af68ad83180%40exch13c.ms.gettysburg.edu.
For more options, visit https://groups.google.com/d/optout.
--
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/CAFeiKqM_Bk-Q1PjE2CAV4gOdD-PjxZdacX_-45gOYq3Dn7FmAg%40mail.gmail.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
To view this discussion on the web visit https://groups.google.com/d/msgid/dotcms/BLUPR0501MB1700EB3E78FF74963E58E0F3AD4B0%40BLUPR0501MB1700.namprd05.prod.outlook.com.
Thanks Nathan.
To view this discussion on the web visit https://groups.google.com/d/msgid/dotcms/b0347f1857e94ccb89e3d9cf1d8134e7%40exch13c.ms.gettysburg.edu.
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:
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 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
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/dotcms/BLUPR0501MB1700739DB8F7D194524979AEAD480%40BLUPR0501MB1700.namprd05.prod.outlook.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
To view this discussion on the web visit https://groups.google.com/d/msgid/dotcms/5a09456017ad49c3bf31f00fe87d3049%40exch13c.ms.gettysburg.edu.
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
To view this discussion on the web visit https://groups.google.com/d/msgid/dotcms/f32c1e2739ba43489e2c222a17f4b10a%40exch13c.ms.gettysburg.edu.