API Save Content with curl Throws 500 Error

58 views
Skip to first unread message

Alex

unread,
May 6, 2018, 8:25:47 PM5/6/18
to dotCMS User Group
Hi,

I finally upgraded to 4.3.  I am migrating all legacy forms to content types. 

I created a test content Type.  It only has two text fields, when I type the command:

curl -v -u 'mye...@example.com:test12345' -XPUT http://197.xxx.xx.xx:XXXX/api/content/save/1 -H  "Content-Type:application/json" -d '{
contentType:"MyContentType",
languageId:1,
First Name:"test content",
Last name:"test last name"
}'


I get this error (on the catalina.out it only appears as a 500 error, it does not give any further information) and the content is not created.


*   Trying MY IP ADDRESS ...

* TCP_NODELAY set

* Connected to xxx.xxx. xx.xx(xxx.xxx. xx.xx) port XXXX (#0)

* Server auth using Basic with user 'mye...@example.com'

> PUT /api/content/save/1 HTTP/1.1

> Host: 197.xxx.xx.xx:XXXX

> Authorization: Basic YXBpQGNvc3RhcmljYS5jb206dGVzdDEyMzQ1

> User-Agent: curl/7.54.0

> Accept: */*

> Content-Type:application/json

> Content-Length: 104

> 

* upload completely sent off: 104 out of 104 bytes

< HTTP/1.1 500 Internal Server Error

< Server: Apache-Coyote/1.1

< Set-Cookie: JSESSIONID=4XXXXX; Path=/; HttpOnly

< Access-Control-Allow-Origin: *

< Access-Control-Allow-Methods: GET, HEAD, POST, PUT, DELETE, OPTIONS

< Access-Control-Allow-Headers: Authorization, Accept, Content-Type, Cookies

< Content-Type: text/html;charset=ISO-8859-1

< Content-Length: 774

< Date: Mon, 07 May 2018 00:13:45 GMT

< Connection: close

< 


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html>

<head>

<title>dotCMS: 500 error</title>


<style type="text/css">

body {

font-family: helvetica, san-serif;

padding: 20px;

margin-top: 0px;

}


#main {

width: 400px;

}


#footer {

text-align: center;

}


h1 {

font-size: 20px;

}


#logo {

float: left;

}


#text {

float: left;

}

</style>




</head>

<body>

<div id="main">

<div id="text">


<h1>dotCMS: 500 error</h1>


<p>The Page or file you were looking for caused an <a href="javascript:showError()">error</a>. <br/>Please make sure that you have typed the correct URL.</p>


</div>

</div>

</body>

* Closing connection 0



=====


Thanks for any help!


Alex

Alex

unread,
May 6, 2018, 8:45:20 PM5/6/18
to dotCMS User Group
Note:  I also set the 

REST_API_CONTENT_ALLOW_FRONT_END_SAVING=true


Set the CMS Anonymous permissions to the content type.

Alex

Alex

unread,
May 8, 2018, 11:30:31 AM5/8/18
to dotCMS User Group
Hi,

I tried it on the demo site and I get a 500 error too and the content is not added to the contentType.  I do not see anything on the Is there a way to view the dotmarketing properties in the demo?


curl -u ad...@dotcms.com:admin -XPUT https://demo.dotcms.com/api/content/save/1 -H "Content-Type:application/json" -d "{contentType:webPageContent,languageId:1,title:test_alex,contentHost:demo.dotcms.com,body:test_alex}"


When I look at the demo site logs I see these errors.  It seems like the content needs an ID or maybe I am looking at this the wrong way?  I am using one basic example on the  documentation, https://dotcms.com/docs/latest/save-content-using-the-rest-api:


08/05/18 11:24:24:208 EDT] WARN error.custom_002derror_002dpage_jsp: Internal Server Error on /html/error/custom-error-page.jsp
[08/05/18 11:24:34:645 EDT] WARN rest.ContentResource: COOKIES are not in the REQUEST
[08/05/18 11:24:34:646 EDT] WARN rest.ContentResource: Content Type with id:'' not found
com.dotmarketing.business.DotStateException: Content Type with id:'' not found
at com.dotmarketing.cache.FieldsCache.getFieldsByStructureInode(FieldsCache.java:32) ~[dotcms_4.3.3_999999.jar:?]
at com.dotcms.rest.ContentResource.saveContent(ContentResource.java:810) [dotcms_4.3.3_999999.jar:?]
at com.dotcms.rest.ContentResource.singlePUTandPOST(ContentResource.java:800) [dotcms_4.3.3_999999.jar:?]
at com.dotcms.rest.ContentResource.singlePUT(ContentResource.java:745) [dotcms_4.3.3_999999.jar:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_151]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_151]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_151]
at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_151]
at com.dotcms.repackage.org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory$1.invoke(ResourceMethodInvocationHandlerFactory.java:81) [dot.jersey-server-2.22.1_1.jar:?]
at com.dotcms.repackage.org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher$1.run(AbstractJavaResourceMethodDispatcher.java:144) [dot.jersey-server-2.22.1_1.jar:?]
at com.dotcms.repackage.org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:161) [dot.jersey-server-2.22.1_1.jar:?]
at com.dotcms.repackage.org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$ResponseOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:160) [dot.jersey-server-2.22.1_1.jar:?]
at com.dotcms.repackage.org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:99) [dot.jersey-server-2.22.1_1.jar:?]
at com.dotcms.repackage.org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:389) [dot.jersey-server-2.22.1_1.jar:?]
at com.dotcms.repackage.org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:347) [dot.jersey-server-2.22.1_1.jar:?]
at com.dotcms.repackage.org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:102) [dot.jersey-server-2.22.1_1.jar:?]
at com.dotcms.repackage.org.glassfish.jersey.server.ServerRuntime$2.run(ServerRuntime.java:326) [dot.jersey-server-2.22.1_1.jar:?]
at com.dotcms.repackage.org.glassfish.jersey.internal.Errors$1.call(Errors.java:271) [dot.jersey-common-2.22.1_1.jar:?]
at com.dotcms.repackage.org.glassfish.jersey.internal.Errors$1.call(Errors.java:267) [dot.jersey-common-2.22.1_1.jar:?]
at com.dotcms.repackage.org.glassfish.jersey.internal.Errors.process(Errors.java:315) [dot.jersey-common-2.22.1_1.jar:?]
at com.dotcms.repackage.org.glassfish.jersey.internal.Errors.process(Errors.java:297) [dot.jersey-common-2.22.1_1.jar:?]
at com.dotcms.repackage.org.glassfish.jersey.internal.Errors.process(Errors.java:267) [dot.jersey-common-2.22.1_1.jar:?]
at com.dotcms.repackage.org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:317) [dot.jersey-common-2.22.1_1.jar:?]
at com.dotcms.repackage.org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:305) [dot.jersey-server-2.22.1_1.jar:?]
at com.dotcms.repackage.org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:1154) [dot.jersey-server-2.22.1_1.jar:?]
at com.dotcms.repackage.org.glassfish.jersey.servlet.WebComponent.serviceImpl(WebComponent.java:471) [dot.jersey-container-servlet-core-2.22.1_1.jar:?]
at com.dotcms.repackage.org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:425) [dot.jersey-container-servlet-core-2.22.1_1.jar:?]
at com.dotcms.repackage.org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:383) [dot.jersey-container-servlet-core-2.22.1_1.jar:?]
at com.dotcms.repackage.org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:336) [dot.jersey-container-servlet-core-2.22.1_1.jar:?]
at com.dotcms.repackage.org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:223) [dot.jersey-container-servlet-core-2.22.1_1.jar:?]
at com.dotcms.rest.servlet.ReloadableServletContainer.service(ReloadableServletContainer.java:105) [dotcms_4.3.3_999999.jar:?]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291) [catalina.jar:8.0.18]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) [catalina.jar:8.0.18]
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) [tomcat-websocket.jar:8.0.18]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) [catalina.jar:8.0.18]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) [catalina.jar:8.0.18]
at com.dotmarketing.filters.CMSFilter.doFilter(CMSFilter.java:203) [dotcms_4.3.3_999999.jar:?]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) [catalina.jar:8.0.18]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) [catalina.jar:8.0.18]
at com.dotcms.filters.interceptor.AbstractWebInterceptorSupportFilter.doFilter(AbstractWebInterceptorSupportFilter.java:73) [dotcms_4.3.3_999999.jar:?]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) [catalina.jar:8.0.18]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) [catalina.jar:8.0.18]
at com.dotcms.filters.interceptor.AbstractWebInterceptorSupportFilter.doFilter(AbstractWebInterceptorSupportFilter.java:73) [dotcms_4.3.3_999999.jar:?]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) [catalina.jar:8.0.18]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) [catalina.jar:8.0.18]
at com.dotmarketing.cms.urlmap.filters.URLMapFilter.doFilter(URLMapFilter.java:325) [dotcms_4.3.3_999999.jar:?]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) [catalina.jar:8.0.18]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) [catalina.jar:8.0.18]
at com.dotmarketing.filters.VanityURLFilter.doFilter(VanityURLFilter.java:110) [dotcms_4.3.3_999999.jar:?]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) [catalina.jar:8.0.18]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) [catalina.jar:8.0.18]
at com.dotcms.repackage.org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:404) [dot.urlrewritefilter-4.0.3_2.jar:4.0.3]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) [catalina.jar:8.0.18]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) [catalina.jar:8.0.18]
at com.dotmarketing.filters.TimeMachineFilter.doFilter(TimeMachineFilter.java:65) [dotcms_4.3.3_999999.jar:?]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) [catalina.jar:8.0.18]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) [catalina.jar:8.0.18]
at com.dotmarketing.filters.ThreadNameFilter.doFilter(ThreadNameFilter.java:90) [dotcms_4.3.3_999999.jar:?]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) [catalina.jar:8.0.18]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) [catalina.jar:8.0.18]
at com.dotmarketing.filters.CookiesFilter.doFilter(CookiesFilter.java:38) [dotcms_4.3.3_999999.jar:?]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) [catalina.jar:8.0.18]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) [catalina.jar:8.0.18]
at com.dotmarketing.filters.CharsetEncodingFilter.doFilter(CharsetEncodingFilter.java:108) [dotcms_4.3.3_999999.jar:?]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) [catalina.jar:8.0.18]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) [catalina.jar:8.0.18]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219) [catalina.jar:8.0.18]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106) [catalina.jar:8.0.18]
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501) [catalina.jar:8.0.18]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142) [catalina.jar:8.0.18]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) [catalina.jar:8.0.18]
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610) [catalina.jar:8.0.18]
at org.apache.catalina.valves.RemoteIpValve.invoke(RemoteIpValve.java:673) [catalina.jar:8.0.18]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88) [catalina.jar:8.0.18]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:516) [catalina.jar:8.0.18]
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1086) [tomcat-coyote.jar:8.0.18]
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:659) [tomcat-coyote.jar:8.0.18]
at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:223) [tomcat-coyote.jar:8.0.18]
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1558) [tomcat-coyote.jar:8.0.18]
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1515) [tomcat-coyote.jar:8.0.18]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:1.8.0_151]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:1.8.0_151]
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-util.jar:8.0.18]
at java.lang.Thread.run(Thread.java:748) [?:1.8.0_151]
Caused by: com.dotcms.contenttype.exception.NotFoundInDbException: Content Type with id:'' not found
at com.dotcms.contenttype.business.ContentTypeFactoryImpl.dbById(ContentTypeFactoryImpl.java:230) ~[dotcms_4.3.3_999999.jar:?]
at com.dotcms.contenttype.business.ContentTypeFactoryImpl.find(ContentTypeFactoryImpl.java:57) ~[dotcms_4.3.3_999999.jar:?]
at com.dotcms.contenttype.business.ContentTypeAPIImpl.find_aroundBody2(ContentTypeAPIImpl.java:121) ~[dotcms_4.3.3_999999.jar:?]
at com.dotcms.contenttype.business.ContentTypeAPIImpl$AjcClosure3.run(ContentTypeAPIImpl.java:1) ~[dotcms_4.3.3_999999.jar:?]
at org.aspectj.runtime.reflect.JoinPointImpl.proceed(JoinPointImpl.java:149) ~[aspectjrt-1.8.10.jar:?]
at com.dotcms.aspects.aspectj.AspectJDelegateMethodInvocation.proceed(AspectJDelegateMethodInvocation.java:43) ~[dotcms_4.3.3_999999.jar:?]
at com.dotcms.aspects.interceptors.CloseDBIfOpenedMethodInterceptor.invoke(CloseDBIfOpenedMethodInterceptor.java:29) ~[dotcms_4.3.3_999999.jar:?]
at com.dotcms.aspects.aspectj.CloseDBIfOpenedAspect.invoke(CloseDBIfOpenedAspect.java:41) ~[dotcms_4.3.3_999999.jar:?]
at com.dotcms.contenttype.business.ContentTypeAPIImpl.find(ContentTypeAPIImpl.java:119) ~[dotcms_4.3.3_999999.jar:?]
at com.dotmarketing.cache.FieldsCache.getFieldsByStructureInode(FieldsCache.java:30) ~[dotcms_4.3.3_999999.jar:?]
... 83 more

</html>

John Michael Thomas

unread,
May 8, 2018, 1:59:54 PM5/8/18
to dotCMS User Group
Unfortunately I don't have time to try this out right now, but my guess is that you need some quotes around the string values you're supplying (e.g. `contentType:"webPageContent"` instead of `contentType:webPageContent`).  Of course to do that, you'll need to format your curl command using single quotes around the -d argument so you can use double quotes around the string terms - that's how the examples in the doc are formatted, so that's what I'd try first.

Alex

unread,
May 8, 2018, 4:25:23 PM5/8/18
to dotCMS User Group
Dear John:

Thanks for the tips.  I have already tried them with or without quotes and double quote.  Here is an example taken from the documentation (I just modified the port and the domain name of the demo site and the https protocol), it spews the same error:

curl -v -u ad...@dotcms.com:admin -XPUT https://demo.dotcms.com/api/content/publish/1 -H "Content-Type:application/json" -d '{

>     contentType:"webPageContent",

>     languageId:1,

>     title:"test content",

>     contentHost:"demo.dotcms.com",

>     body:"test body"

> }'

*   Trying 54.165.137.45...

* TCP_NODELAY set

* Connected to demo.dotcms.com (54.165.137.45) port 443 (#0)

* ALPN, offering h2

* ALPN, offering http/1.1

* Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH

* successfully set certificate verify locations:

*   CAfile: /etc/ssl/cert.pem

  CApath: none

* TLSv1.2 (OUT), TLS handshake, Client hello (1):

* TLSv1.2 (IN), TLS handshake, Server hello (2):

* TLSv1.2 (IN), TLS handshake, Certificate (11):

* TLSv1.2 (IN), TLS handshake, Server key exchange (12):

* TLSv1.2 (IN), TLS handshake, Server finished (14):

* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):

* TLSv1.2 (OUT), TLS change cipher, Client hello (1):

* TLSv1.2 (OUT), TLS handshake, Finished (20):

* TLSv1.2 (IN), TLS change cipher, Client hello (1):

* TLSv1.2 (IN), TLS handshake, Finished (20):

* SSL connection using TLSv1.2 / ECDHE-RSA-AES256-GCM-SHA384

* ALPN, server accepted to use http/1.1

* Server certificate:

*  subject: CN=demo.dotcms.com

*  start date: Mar 14 03:15:45 2018 GMT

*  expire date: Jun 12 03:15:45 2018 GMT

*  subjectAltName: host "demo.dotcms.com" matched cert's "demo.dotcms.com"

*  issuer: C=US; O=Let's Encrypt; CN=Let's Encrypt Authority X3

*  SSL certificate verify ok.

* Server auth using Basic with user 'ad...@dotcms.com'

> PUT /api/content/publish/1 HTTP/1.1

> Host: demo.dotcms.com

> Authorization: Basic YWRtaW5AZG90Y21zLmNvbTphZG1pbg==

> User-Agent: curl/7.54.0

> Accept: */*

> Content-Type:application/json

> Content-Length: 137

> 

* upload completely sent off: 137 out of 137 bytes

< HTTP/1.1 500 Internal Server Error

< Date: Tue, 08 May 2018 20:21:26 GMT

< Content-Type: text/html;charset=ISO-8859-1

< Content-Length: 774

< Connection: keep-alive

< Server: Apache-Coyote/1.1

< Set-Cookie: JSESSIONID=A8E0701766D97AA7074CDFE97532412A; Path=/; Secure; HttpOnly

< Access-Control-Allow-Origin: *

< Access-Control-Allow-Methods: GET, HEAD, POST, PUT, DELETE, OPTIONS

< Access-Control-Allow-Headers: Authorization, Accept, Content-Type, Cookies

< 














* Connection #0 to host demo.dotcms.com left intact

Daniel Silva

unread,
May 9, 2018, 11:17:34 AM5/9/18
to dotCMS User Group
Hey Alex, 

Unfortunately the 5.0 version of that doc got pushed live and that's the reason the JSON example does not work for 4.x. Please replace the key `contentType` with `stName` in your JSON and it should work. We are restoring the proper version of the doc in a moment. 

Thank you!

Daniel

Alex

unread,
May 9, 2018, 3:33:19 PM5/9/18
to dotCMS User Group
Daniel,

Thank you so much! That was the problem!

Does it mean that when we upgrade to 5.0 we will have to update the code with the correct structure variable name?

Alex

John Michael Thomas

unread,
May 9, 2018, 4:50:18 PM5/9/18
to dotCMS User Group
The old 'stName' notation will still work in 5.0, but will be officially deprecated.  So you won't have to change the code right away, but it will be recommended that you change it to the new `contentType` notation at some point, since it could potentially be removed at some point in the future.

Alex

unread,
May 9, 2018, 7:04:58 PM5/9/18
to dotCMS User Group
John,

I noticed that if I use the labels of the content type the contentlet is not created.  However, if I use the variable names, the contentlet is successfully created.

Anyways, Thank you for your help!

Alex
Reply all
Reply to author
Forward
0 new messages