function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
GuruBVGuruBV 

URI for RESTful API

Hi,

 

Can someone let me know what is the URI of the RESTful API for creating a User object on Sales Force?

Thanks in advance.

 

Regards,

Guru

SuperfellSuperfell

send a POST to /services/data/v21.0/sobjects/user

GuruBVGuruBV

My initial POST was to  /services/data/v20.0/sobjects/User/

I started getting an IOException with the following stack trace :-

 

StringRequestEntity.writeRequest(OutputStream) line: 150   
    PostMethod(EntityEnclosingMethod).writeRequestBody(HttpState, HttpConnection) line: 495   
    PostMethod(HttpMethodBase).writeRequest(HttpState, HttpConnection) line: 1973   
    PostMethod(HttpMethodBase).execute(HttpState, HttpConnection) line: 993   
    HttpMethodDirector.executeWithRetry(HttpMethod) line: 397   
    HttpMethodDirector.executeMethod(HttpMethod) line: 170   
    HttpClient.executeMethod(HostConfiguration, HttpMethod, HttpState) line: 396   
    HttpClient.executeMethod(HttpMethod) line: 324   
    DemoREST.createUser(String, String, String, PrintWriter) line: 172   
    DemoREST.doGet(HttpServletRequest, HttpServletResponse) line: 325   
    DemoREST(HttpServlet).service(HttpServletRequest, HttpServletResponse) line: 617   
    DemoREST(HttpServlet).service(ServletRequest, ServletResponse) line: 717   
    ApplicationFilterChain.internalDoFilter(ServletRequest, ServletResponse) line: 290   
    ApplicationFilterChain.doFilter(ServletRequest, ServletResponse) line: 206   
    StandardWrapperValve.invoke(Request, Response) line: 233   
    StandardContextValve.invoke(Request, Response) line: 191   
    StandardHostValve.invoke(Request, Response) line: 127   
    ErrorReportValve.invoke(Request, Response) line: 102   
    StandardEngineValve.invoke(Request, Response) line: 109   
    CoyoteAdapter.service(Request, Response) line: 291   
    Http11Processor.process(Socket) line: 859   
    Http11Protocol$Http11ConnectionHandler.process(Socket) line: 602   
    JIoEndpoint$Worker.run() line: 489   
    Thread.run() line: 680

 

Thanks to Simon, I have now gone a step ahead after changing the URI to /services/data/v21.0/sobjects/user.

However now I get a HTTP status 400. I need to admit that I am not setting all the "Required" fields of a User object. But my question here is, doesn't Sales Force / RESTful API's send back an appropriate error message pin pointing the exact problem?

 

Regards,

Guru

SuperfellSuperfell

Yes they do, look at the http body you got back with that 400 response.

GuruBVGuruBV

Simon, pardon my ignorance on Sales Force / RESTful API's, but I didn't get what you meant by http body?

To provide you the context, I am trying to alter the Getting Started with the Force.com REST API sample to create a User instead of an Account. Hence I use the same HttpClient library as suggested. If you meant the variable "responseBody" (of type byte[]) of PostMethod object, then it is null in my case.

Paul BerglundPaul Berglund
You have to catch the WebException - see this article: http://msdn.microsoft.com/en-us/library/system.net.webexception.status%28v=vs.110%29.aspx