GRESB / api-docs

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

Updating GRESB response doesn't work properly #19

Closed EmilTemirov closed 9 years ago

EmilTemirov commented 9 years ago

From documentation:

Creating a new response automatically creates a company or fund object if needed or updates an existing one if the same name and manger are used.

When I try to send request with existing name and manager I get error:

{
    "errors": {
        "name": [
            "taken"
        ]
    }
}

How to reproduce:

1) First, send request to create new GRESB response:

     "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=responseTest9&property_type=2&manager=emilManager&legal_status=1",
            "params": [
              {
                "name": "country",
                "value": "GB"
              },
              {
                "name": "name",
                "value": "responseTest9"
              },
              {
                "name": "property_type",
                "value": "2"
              },
              {
                "name": "manager",
                "value": "emilManager"
              },
              {
                "name": "legal_status",
                "value": "1"
              }
            ]
          }
        }
    }

2) Send request with the same name and manager values:

     "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=responseTest9&property_type=2&manager=emilManager&legal_status=1",
            "params": [
              {
                "name": "country",
                "value": "US"
              },
              {
                "name": "name",
                "value": "responseTest9"
              },
              {
                "name": "property_type",
                "value": "1"
              },
              {
                "name": "manager",
                "value": "emilManager"
              },
              {
                "name": "legal_status",
                "value": "2"
              }
            ]
          }
        }
    }

I tried some of sensible variations: 1) I sent POST request with the response_id as a parameter Response - same error as before. 2) I sent PUT request with/without the response_id Response:

{
    "error": "API End-point not found"
}

What am I doing wrong?

amichal commented 9 years ago

I think the documentation is just confusing here. If a response exists for 2014 called "response123" and you create a response for 2015 called "response123" they will automatically be associated with the same company_fund_id and there is no way to pass company_fund_id directly.

This should not be a concern for an API consumer since the relationship between responses and company funds is curated by the respondent in collaboration with GRESB and can be changed after the fact.

Further, We expect the list of responses returned by /api/responses will be pre-populated with empty responses for 2015 for any respondents who participated in 2014.

Does that make sense?

EmilTemirov commented 9 years ago

So, how can I update any existing response via API? For example, I create new response with a wrong country value

curl -H 'Authorization: Bearer YOUR_TOKEN_HERE' -H "Content-Type: application/json" -d 
'{"survey_date": 2015, "name": "responseTest4", "manager": "Emil", "country": "UA" }' 
https://api-sandbox.gresb.com/api/responses

and then I want to get rid of this mistake, change country to "GB".

amichal commented 9 years ago

Hi @EmilTemirov i see now the update response API call is entirely missing from the documentation!. Sorry about that. I'm adding it in now but it looks like so:

PUT /api/responses/:id

$ curl -X PUT -d name='New Name' -d manager='New Manager' https://api.gresb.com/api/responses/123 \
-H 'Authorization: Bearer ...' \ 

The 123 ID is the the one returned but the create response POST /api/responses call or the one listed in GET /api/responses

amichal commented 9 years ago

It is not company_fund_id which is a foreign key to the 'CompanyFund' model which is not yet exposed in the API. This model simply links responses for the same company or fund over multiple survey years.

amichal commented 9 years ago

Updated documentation now includes the missing 'Update Response' section: http://localhost:4567/#update-response. Let me know if you have further issues