GRESB / api-docs

http://gresb.github.io/api-docs/
3 stars 0 forks source link

Creating GRESB response: Doesn't save response values #18

Closed EmilTemirov closed 9 years ago

EmilTemirov commented 9 years ago

I try to create GRESB response by sending this request:

"request": {
          "method": "POST",
          "url": "https://api-sandbox.gresb.com/api/responses?access_token=MY_ACCESS_TOKEN",
          "httpVersion": "HTTP/1.1",
          "postData": {
            "mimeType": "application/x-www-form-urlencoded",
            "text": "country=GB&name=responseTest4&property_type=2&manager=emilManager&legal_status=1",
            "params": [
              {
                "name": "country",
                "value": "GB"
              },
              {
                "name": "name",
                "value": "responseTest4"
              },
              {
                "name": "property_type",
                "value": "2"
              },
              {
                "name": "manager",
                "value": "emilManager"
              },
              {
                "name": "legal_status",
                "value": "1"
              }
            ]
          }
        }
}

But I get response with name value only:

{
    "country": null,
    "created_at": "2015-03-17T12:05:10Z",
    "id": 2668,
    "legal_status": null,
    "manager": null,
    "name": "responseTest4",
    "property_type": null,
    "region": null,
    "submitted_at": null,
    "survey_date": "2015",
    "updated_at": "2015-03-17T12:05:10Z"
}

What is my mistake?

amichal commented 9 years ago

You post any JSON data in the same format as we show for the response (i see the documentation needs to be improved on this).

The HTTP post would look something like this (some fields you see above are documented as read-only):

POST /api/responses HTTP/1.1
Host: api-sandbox.gresb.com
Accept: */*
Content-Type: application/json

{
    "survey_date": 2015,
    "name": "responseTest4",
    "manager": null,
    "legal_status": null,
    "property_type": null,
    "country": null
}

Which you could test with the curl client like so (whitespace doesn't matter in JSON):

curl -H 'Authorization: Bearer YOUR_TOKEN_HERE' -H "Content-Type: application/json" -d '{"survey_date": 2015, "name": "responseTest4", "m anager": null, "legal_status": null, "property_type": null, "country": null }' https://api-sandbox.gresb.com/api/responses

Request params can also be URL query params (which is much easier to do in many clients):

curl -H 'Authorization: Bearer ....' https://api-sandbox.gresb.com/api/responses?name=responseTest4&manager=foo

Finally they can be in the request body as application/x-www-form-urlencoded or multipart/form-data data. This is how HTML forms send data.

POST /api/responses HTTP/1.1
Host: api-sandbox.gresb.com
Accept: */*
Content-Type: application/x-www-form-urlencoded

name=responseTest4&manager=foo
EmilTemirov commented 9 years ago

I'm sorry if I made you confuse, but I posted request presented in HTTP Archive format or HAR. I tried to send request the same as you provided before via curl and got a problem that manager, property_type, country, legal_status values are not saved.

>> curl -H 'Authorization: Bearer MY_ACCESS_TOKEN' -H "Content-Type: application/json" -d '{"survey_date": 2015, "name": "responseCurl", "manager": "Emil", "legal_status": 1, "property_type": 2, "country": "GB" }' https://api-sandbox.gresb.com/api/responses

{
  "country": null,
  "created_at": "2015-03-18T16:44:25Z",
  "id": 2676,
  "legal_status": null,
  "manager": null,
  "name": "responseCurl",
  "property_type": null,
  "region": null,
  "submitted_at": null,
  "survey_date": "2015",
  "updated_at": "2015-03-18T16:44:25Z"
}
amichal commented 9 years ago

I see now the issue. region, country, property_type, legal_status and survey_date were incorrectly documented as being optionally updatable. They are in-fact read-only and only set after a response has been submitted and scored. Documentation has been updated to reflect this correctly now: http://gresb.github.io/api-docs/#fields I hope it doesnt cause you too much trouble.

amichal commented 9 years ago

Also checkout the documentation version history which now says something useful: http://localhost:4567/#versioning

amichal commented 9 years ago

Make that http://gresb.github.io/api-docs/#versioning in my last comment :)