MushroomObserver / mushroom-observer

A website for sharing observations of mushrooms.
https://mushroomobserver.org
MIT License
78 stars 25 forks source link

Update iNat Observation #2246

Closed JoeCohen closed 1 month ago

JoeCohen commented 3 months ago

Update the iNat observation with a note and/or Observation field that has the MO id and a link. Probably copy what Pulk did in his Mirror app

Tasks

JoeCohen commented 1 month ago

Notes re adding Mushroom Observer Url to iNat: This is ofvs field_id=>5005 https://api.inaturalist.org/v1/docs/#!/Observation_Field_Values/post_observation_field_values:Parameters

Parameter body

  "observation_field_value": {
    "observation_id": 215968871,
    "observation_field_id": 5005,
    "value": "https://mushroomobserver.org/547126"
  }
}

Parameter content type: application/json

{
  "observation_field_value": {
    "observation_id": 215968871,
    "observation_field_id": 5005,
    "value": "https://mushroomobserver.org/547126"
  }
}

Curl

curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{
  "observation_field_value": {
    "observation_id": 215968871,
    "observation_field_id": 5005,
    "value": "https://mushroomobserver.org/547126"
  }
}' 'https://api.inaturalist.org/v1/observation_field_values'

Request URL

https://api.inaturalist.org/v1/observation_field_values
JoeCohen commented 1 month ago

Add to note by modifying (PUT) the :description. It should be the old notes plus the new line. https://api.inaturalist.org/v1/docs/#!/Observations/put_observations_id: Parameters id: 215968871 body:

{
  "observation": {
    "description": "\n\nImported to Mushroom Observer 2024-09-09"
  }
}

Parameter content type: application/json

Curl

curl -X PUT --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{
  "observation": {
    "description": "\n\nImported to Mushroom Observer 2024-09-09"
  }
}' 'https://api.inaturalist.org/v1/observations/215968871'

Request URL https://api.inaturalist.org/v1/observations/215968871

JoeCohen commented 1 month ago

Copilot says:

To add an Observation Field to an iNaturalist observation using the API v1, you can use the POST /observation_field_values endpoint. Here’s how you can do it:

Endpoint: POST /observation_field_values Headers: Ensure you include the necessary authentication headers (OAuth token). Payload: The payload should include the observation ID, observation field ID, and the value you want to add. Here’s an example of how you can structure your request:

curl -X POST "https://api.inaturalist.org/v1/observation_field_values" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"observation_field_value": {
"observation_id": 215968871,
"observation_field_id": 5005,
"value": "https://mushroomobserver.org/547126"
}
}'
JoeCohen commented 1 month ago

CoPIlot says:

Here’s how you can add an Observation Field to an iNaturalist observation using the RestClient gem in a Rails application:


def self.add_observation_field(observation_id, field_id, value, access_token)
payload = {
observation_field_value: {
observation_id: observation_id,
observation_field_id: field_id,
value: value
}
}
headers = {
  Authorization: "Bearer #{access_token}",
  content_type: :json,
  accept: :json
}

response = RestClient.post(INATURALIST_API_URL, payload.to_json, headers)
JSON.parse(response.body)

rescue RestClient::ExceptionWithResponse => e e.response end