title: HP ALM new defect 500
body: <p>With the following code, i want to create a new defect in hp alm 11.52. </p>
  
  <pre><code>import requests
  import sys
  import json
  
  def login_alm(alm_url, login_list, header):
      # GET request @ ALM URL
      r = requests.get(alm_url + u'authentication-point/authenticate', auth = login_list)
  
      if r.status_code == 200:
          print 'Login successful'
          header['Cookie'] = r.headers['set-cookie']
      else:
          print'Login Failed'
          sys.exit(0)
      return header
  
  def logout_alm(alm_url, login_list, header):
      if header['Cookie'] is not None:
          r = requests.get(alm_url + u'authentication-point/logout', headers=header, auth=login_list)
          if r.status_code == 200:
              print 'Logout successful'
          else:
              print 'Logout not successful'
      else:
          print 'Logging Error: header = None'
          return 1
  
  def create_defect(alm_url, header, alm_domain, alm_project, daten_xml, login_list):
      if header['Cookie'] is not None:
          print header
          r = requests.post(alm_url + u'rest/domains/' + alm_domain + u'/projects/' + alm_project + u'/defects',
                            headers=header,
                            data=daten_xml)
  
  
  def main():
      url = u'https://{.......}'
      login = (u'{...}', u'{...}')
      domain = u'{...}'
      project = u'{...}'
      headers = {"Accept":"application/xml",
                "Content-Type":"application/xml",
                "Cookie": None}
  
      ticket_data_xml = ''' &lt;Entity Type="defect"&gt;
                              &lt;Fields&gt;
                                  &lt;Field Name="{...}"&gt;&lt;Value&gt;{...}&lt;/Value&gt;&lt;/Field&gt;
                                  &lt;Field Name="{...}"&gt;&lt;Value&gt;{...}&lt;/Value&gt;&lt;/Field&gt;
                                  &lt;Field Name="{...}"&gt;&lt;Value&gt;{...}&lt;/Value&gt;&lt;/Field&gt;
                                  &lt;Field Name="{...}"&gt;&lt;Value&gt;{...}&lt;/Value&gt;&lt;/Field&gt;
                                  &lt;Field Name="{...}"&gt;&lt;Value&gt;{...}&lt;/Value&gt;&lt;/Field&gt;
                              &lt;/Fields&gt;
                          &lt;/Entity&gt;'''
  
  
      headers = login_alm(alm_url=url, login_list=login, header=headers)
  
      create_defect(alm_url=url, header=headers, alm_domain=domain, alm_project=project, daten_xml=ticket_data_xml, login_list=login)
  
      logout_alm(alm_url=url, login_list=login, header=headers)
  
  if __name__ == '__main__':
      main()
  </code></pre>
  
  <p>The Login and Logout works fine, but the requests.post in the function create_defect() is the problem. Everytime I execute the code, it throws the following 500 error:</p>
  
  <pre><code>&lt;QCRestException&gt;
  &lt;Id&gt;qccore.entity-not-found&lt;/Id&gt;
  &lt;Title&gt;No entity of type defect with id 703 exists.&lt;/Title&gt;
  &lt;ExceptionProperties/&gt;
  &lt;StackTrace&gt;
  </code></pre>
  
  <p>The XML is correct (every required filed is included), and the Urls too. I also tried Json.</p>
  
  <p>Furthermore i tried the same procedure in the Advance Rest Client for Chrome, but it still throws the same Error. Do someone know if the order of get - post - get request is correct?</p>
  
  <p>QC Log, after executing:</p>
  
  <pre><code>at org.hp.qc.impl.services.ReadServiceImpl.read(ReadServiceImpl.java:68)
  at org.hp.qc.web.restapi.entities.AbstractBaseResource.readEntity(AbstractBaseResource.java:325)
  at org.hp.qc.web.restapi.entities.AbstractBaseResource.performPOSTEntity(AbstractBaseResource.java:169)
  at org.hp.qc.web.restapi.entities.FirstLevelResource.create(FirstLevelResource.java:144)
  at sun.reflect.GeneratedMethodAccessor296.invoke(Unknown Source)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
  at java.lang.reflect.Method.invoke(Method.java:597)
  at org.apache.wink.server.internal.handlers.InvokeMethodHandler.handleRequest(InvokeMethodHandler.java:51)
  at org.apache.wink.server.handlers.AbstractHandler.handleRequest(AbstractHandler.java:33)
  at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:26)
  at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:22)
  at org.apache.wink.server.handlers.AbstractHandlersChain.doChain(AbstractHandlersChain.java:61)
  at org.hp.qc.web.restapi.cache.CacheRequestHandler.handleRequest(CacheRequestHandler.java:46)
  at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:26)
  at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:22)
  at org.apache.wink.server.handlers.AbstractHandlersChain.doChain(AbstractHandlersChain.java:61)
  at org.apache.wink.server.internal.handlers.CreateInvocationParametersHandler.handleRequest(CreateInvocationParametersHandler.java:54)
  at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:26)
  at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:22)
  at org.apache.wink.server.handlers.AbstractHandlersChain.doChain(AbstractHandlersChain.java:61)
  at org.apache.wink.server.internal.handlers.FindResourceMethodHandler.handleResourceMethod(FindResourceMethodHandler.java:151)
  at org.apache.wink.server.internal.handlers.FindResourceMethodHandler.handleRequest(FindResourceMethodHandler.java:65)
  at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:26)
  at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:22)
  at org.apache.wink.server.handlers.AbstractHandlersChain.doChain(AbstractHandlersChain.java:61)
  at org.apache.wink.server.internal.handlers.FindRootResourceHandler.handleRequest(FindRootResourceHandler.java:93)
  at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:26)
  at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:22)
  at org.apache.wink.server.handlers.AbstractHandlersChain.doChain(AbstractHandlersChain.java:61)
  at org.apache.wink.server.internal.handlers.HeadMethodHandler.handleRequest(HeadMethodHandler.java:53)
  at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:26)
  at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:22)
  at org.apache.wink.server.handlers.AbstractHandlersChain.doChain(AbstractHandlersChain.java:61)
  at org.apache.wink.server.internal.handlers.OptionsMethodHandler.handleRequest(OptionsMethodHandler.java:46)
  at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:26)
  at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:22)
  at org.apache.wink.server.handlers.AbstractHandlersChain.doChain(AbstractHandlersChain.java:61)
  at org.apache.wink.server.internal.handlers.SearchResultHandler.handleRequest(SearchResultHandler.java:33)
  at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:26)
  at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:22)
  at org.apache.wink.server.handlers.AbstractHandlersChain.doChain(AbstractHandlersChain.java:61)
  at org.apache.wink.server.handlers.AbstractHandlersChain.run(AbstractHandlersChain.java:48)
  at org.apache.wink.server.internal.RequestProcessor.handleRequestWithoutFaultBarrier(RequestProcessor.java:163)
  at org.apache.wink.server.internal.RequestProcessor.handleRequest(RequestProcessor.java:137)
  at org.apache.wink.server.internal.servlet.RestServlet.service(RestServlet.java:116)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
  at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:547)
  at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1359)
  at org.eclipse.jetty.servlets.UserAgentFilter.doFilter(UserAgentFilter.java:77)
  at org.eclipse.jetty.servlets.GzipFilter.doFilter(GzipFilter.java:181)
  at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1330)
  at org.hp.qc.web.restapi.filters.RESTApiFilter.doFilter(RESTApiFilter.java:128)
  at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1330)
  at org.hp.qc.web.restapi.performance.PerformanceMonitorRESTFilter.doFilter(PerformanceMonitorRESTFilter.java:45)
  at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1330)
  at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:378)
  at com.hp.sw.bto.ast.security.lwsso.authenticator.springSecurity.SpringSecurity2LWSSOIntegrationFilter.doFilter(SpringSecurity2LWSSOIntegrationFilter.java:182)
  at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390)
  at org.hp.qc.web.restapi.sessionmanagement.ImplicitSessionFilter.doFilter(ImplicitSessionFilter.java:76)
  at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390)
  at org.springframework.security.intercept.web.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:109)
  at org.springframework.security.intercept.web.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83)
  at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390)
  at com.hp.sw.bto.ast.security.lwsso.authenticator.springSecurity.LWSSO2SpringSecurityIntegrationFilter.doFilter(LWSSO2SpringSecurityIntegrationFilter.java:299)
  at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390)
  at org.springframework.security.ui.ExceptionTranslationFilter.doFilterHttp(ExceptionTranslationFilter.java:101)
  at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
  at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390)
  at org.springframework.security.context.HttpSessionContextIntegrationFilter.doFilterHttp(HttpSessionContextIntegrationFilter.java:235)
  at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
  at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390)
  at org.springframework.security.util.FilterChainProxy.doFilter(FilterChainProxy.java:175)
  at org.hp.qc.web.restapi.authentication.FilterChainProxyWrapper.doFilter(FilterChainProxyWrapper.java:80)
  at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:237)
  at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167)
  at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1330)
  at com.mercury.optane.core.state.ServerStatusFilter.doFilter(ServerStatusFilter.java:35)
  at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1330)
  at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:478)
  at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:119)
  at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:520)
  at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:227)
  at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:941)
  at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:409)
  at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:186)
  at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:875)
  at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:117)
  at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:250)
  at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:149)
  at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:110)
  at org.eclipse.jetty.rewrite.handler.RewriteHandler.handle(RewriteHandler.java:312)
  at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:110)
  at org.eclipse.jetty.server.Server.handle(Server.java:345)
  at org.eclipse.jetty.server.HttpConnection.handleRequest(HttpConnection.java:441)
  at org.eclipse.jetty.server.HttpConnection$RequestHandler.content(HttpConnection.java:936)
  at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:801)
  at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:224)
  at org.eclipse.jetty.server.BlockingHttpConnection.handle(BlockingHttpConnection.java:50)
  at org.eclipse.jetty.server.bio.SocketConnector$ConnectorEndPoint.run(SocketConnector.java:245)
  at org.eclipse.jetty.server.ssl.SslSocketConnector$SslConnectorEndPoint.run(SslSocketConnector.java:663)
  at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:598)
  at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:533)
  at java.lang.Thread.run(Thread.java:662)
  </code></pre>