Uploaded image for project: 'Crowd Data Center'
  1. Crowd Data Center
  2. CWD-2298

Provide JSON Request and Response examples for the Server REST APIs

    • Our product teams collect and evaluate feedback from a number of different sources. To learn more about how we use customer feedback in the planning process, check out our new feature policy.

      Currently, our REST Docs provide examples in XML only.

      To avoid confusion when developers try to use JSON, we need to provide the equivalent JSON examples as well.

            [CWD-2298] Provide JSON Request and Response examples for the Server REST APIs

            joe added a comment -

            can you provide some examples for /search?

            The /search resource cannot be used with JSON, unfortunately. Consider Crowd Query Language for a concise way to express queries.

            joe added a comment - can you provide some examples for /search? The /search resource cannot be used with JSON, unfortunately. Consider Crowd Query Language for a concise way to express queries.

            can you provide some examples for /search?

            Jeremy Derr added a comment - can you provide some examples for /search?

            This is excellent. Thank you for the reply and updated docs.

            Jason Keglovitz added a comment - This is excellent. Thank you for the reply and updated docs.

            joe added a comment -

            I've added some examples to the documentation as JSON Requests and Responses.

            joe added a comment - I've added some examples to the documentation as JSON Requests and Responses .

            joe added a comment -

            In this case, for session the creation payload would look like:

            {
               "username" : "name",
               "password" : "pass",
               "validation-factors" : {
                  "validationFactors" : [
                     {
                        "name" : "remote_address",
                        "value" : "192.168.1.1"
                     }
                  ]
               }
            }
            

            and for validation:

            {
               "validationFactors" : [
                  {
                     "name" : "remote_address",
                     "value" : "192.168.1.1"
                  }
               ]
            }
            

            As a general rule, JSON doesn't require the outer wrapper element that XML uses, but the way to encode validationFactors isn't easy to guess.

            joe added a comment - In this case, for session the creation payload would look like: { "username" : "name" , "password" : "pass" , "validation-factors" : { "validationFactors" : [ { "name" : "remote_address" , "value" : "192.168.1.1" } ] } } and for validation: { "validationFactors" : [ { "name" : "remote_address" , "value" : "192.168.1.1" } ] } As a general rule, JSON doesn't require the outer wrapper element that XML uses, but the way to encode validationFactors isn't easy to guess.

            I've had a similar issue trying to POST JSON to crowd/rest/usermanagement/latest/session to create/validate a session. POSTing the documented XML works fine, but when I attempt to POST the JSON conversion of that XML, I get a similar 500 error denoting that Unrecognized field authentication-context is not marked as ignorable.

            I am using Content-Type: application/json

            I have tried through trial and error to deduce the correct JSON format for various calls, but it would be very helpful if you could provide documentation or at least the general logic/scheme for how I do my own conversion from the XML structure to the JSON structure.

            Jason Keglovitz added a comment - I've had a similar issue trying to POST JSON to crowd/rest/usermanagement/latest/session to create/validate a session. POSTing the documented XML works fine, but when I attempt to POST the JSON conversion of that XML, I get a similar 500 error denoting that Unrecognized field authentication-context is not marked as ignorable. I am using Content-Type: application/json I have tried through trial and error to deduce the correct JSON format for various calls, but it would be very helpful if you could provide documentation or at least the general logic/scheme for how I do my own conversion from the XML structure to the JSON structure.

            That seems to have worked.. is there a doc explaining the differences?

            Thanks!
            Ralph

            Ralph Schindler added a comment - That seems to have worked.. is there a doc explaining the differences? Thanks! Ralph

            joe added a comment -

            The structure's a little different for JSON. Try this:

            sample.json
            {"value":"xxxxxx"}
            
            curl -i -u APPLICATION:PASSWORD --data-binary @sample.json http://localhost:4990/crowd/rest/usermanagement/1/authentication?username=ralph --header 'Content-Type: application/json' --header 'Accept: application/json'
            

            joe added a comment - The structure's a little different for JSON. Try this: sample.json { "value" : "xxxxxx" } curl -i -u APPLICATION:PASSWORD --data-binary @sample.json http: //localhost:4990/crowd/ rest /usermanagement/1/authentication?username=ralph --header 'Content-Type: application/json' --header 'Accept: application/json'

            I am having trouble with the JSON api, perhaps b/c I am unfamiliar with the structure that is intended to be used (perhaps a docs problem) - right now I am trying to use a similar structure to that of the XML request.

            In any case, I have an http client that has produced this:

            POST /crowd/rest/usermanagement/1/authentication?username=ralph HTTP/1.1 
            Host: framework.zend.com 
            Connection: close 
            Accept-encoding: gzip, deflate 
            User-Agent: Zend\Http\Client 
            Authorization: Basic emZ0ZWFtLXJlc3Q6emZ0ZWFtLXJlc3Q= 
            Content-Length: 33 
            Content-Type: application/json 
            Accept: application/json 
            Cookie: JSESSIONID=87CFEDD033840F40594549C4AA157A3F 
            
            {"password":{"value":"xxxxxx"}}
            

            But the response is:

            HTTP/1.1 500 Internal Server Error 
            Date: Tue, 29 Nov 2011 17:44:39 GMT 
            Server: Apache-Coyote/1.1 
            X-Embedded-Crowd-Version: Crowd/2.2.2 
            X-Crowd-User-Management-Version: 1 
            Cache-Control: no-cache, no-store, no-transform 
            Content-Type: application/json 
            Via: 1.1 framework.zend.com 
            Connection: close 
            Transfer-Encoding: chunked 
            
            f1 
            {"status-code":500,"message":"Unrecognized field \"password\" (Class com.atlassian.crowd.plugin.rest.entity.PasswordEntity), not marked as ignorable\n at [Source: org.apache.catalina.connector.CoyoteInputStream@4971e85; line: 1, column: 2]"} 
            0 
            

            Any ideas?

            -ralph

            Ralph Schindler added a comment - I am having trouble with the JSON api, perhaps b/c I am unfamiliar with the structure that is intended to be used (perhaps a docs problem) - right now I am trying to use a similar structure to that of the XML request. In any case, I have an http client that has produced this: POST /crowd/ rest /usermanagement/1/authentication?username=ralph HTTP/1.1 Host: framework.zend.com Connection: close Accept-encoding: gzip, deflate User-Agent: Zend\Http\Client Authorization: Basic emZ0ZWFtLXJlc3Q6emZ0ZWFtLXJlc3Q= Content-Length: 33 Content-Type: application/json Accept: application/json Cookie: JSESSIONID=87CFEDD033840F40594549C4AA157A3F { "password" :{ "value" : "xxxxxx" }} But the response is: HTTP/1.1 500 Internal Server Error Date: Tue, 29 Nov 2011 17:44:39 GMT Server: Apache-Coyote/1.1 X-Embedded-Crowd-Version: Crowd/2.2.2 X-Crowd-User-Management-Version: 1 Cache-Control: no-cache, no-store, no-transform Content-Type: application/json Via: 1.1 framework.zend.com Connection: close Transfer-Encoding: chunked f1 { "status-code" :500, "message" : "Unrecognized field \" password\ " ( Class com.atlassian.crowd.plugin. rest .entity.PasswordEntity), not marked as ignorable\n at [Source: org.apache.catalina.connector.CoyoteInputStream@4971e85; line: 1, column: 2]" } 0 Any ideas? -ralph

              jwalton joe
              rbattaglin Renan Battaglin
              Votes:
              1 Vote for this issue
              Watchers:
              4 Start watching this issue

                Created:
                Updated:
                Resolved:

                  Estimated:
                  Original Estimate - 4h
                  4h
                  Remaining:
                  Remaining Estimate - 4h
                  4h
                  Logged:
                  Time Spent - Not Specified
                  Not Specified