API HELP NEEDED PLEASE -- posting new observations

133 views
Skip to first unread message

Ian Kleinfeld

unread,
Apr 20, 2017, 10:30:26 AM4/20/17
to iNaturalist
Looking at the API Reference, it seems that to post a new observation using the API, I first need to post that new observation and THEN add it to a project. Is that correct or am I missing something? 

Ref: 

Is there a way to do this all in one step, i.e., 

POST to observations.json and assign to a project ... 

or do I need to POST / observations then POST / project_observations ?

 

Scott Loarie

unread,
Apr 20, 2017, 10:32:18 AM4/20/17
to inatu...@googlegroups.com
You need to separately post the observation and then the project_observation

--
You received this message because you are subscribed to the Google Groups "iNaturalist" group.
To unsubscribe from this group and stop receiving emails from it, send an email to inaturalist+unsubscribe@googlegroups.com.
To post to this group, send email to inatu...@googlegroups.com.
Visit this group at https://groups.google.com/group/inaturalist.
For more options, visit https://groups.google.com/d/optout.



--
--------------------------------------------------
Scott R. Loarie, Ph.D.
Co-director, iNaturalist.org
California Academy of Sciences
55 Music Concourse Dr
San Francisco, CA 94118
--------------------------------------------------

Ian Kleinfeld

unread,
Apr 20, 2017, 10:40:23 AM4/20/17
to iNaturalist
Ok, thanks. Is there any way the documentation can be updated to clarify this in each of those sections? 

Thanks for all your work. It's great!


On Thursday, April 20, 2017 at 10:32:18 AM UTC-4, Scott Loarie wrote:
You need to separately post the observation and then the project_observation
On Thu, Apr 20, 2017 at 7:30 AM, Ian Kleinfeld <mydes...@gmail.com> wrote:
Looking at the API Reference, it seems that to post a new observation using the API, I first need to post that new observation and THEN add it to a project. Is that correct or am I missing something? 

Ref: 

Is there a way to do this all in one step, i.e., 

POST to observations.json and assign to a project ... 

or do I need to POST / observations then POST / project_observations ?

 

--
You received this message because you are subscribed to the Google Groups "iNaturalist" group.
To unsubscribe from this group and stop receiving emails from it, send an email to inaturalist...@googlegroups.com.

To post to this group, send email to inatu...@googlegroups.com.
Visit this group at https://groups.google.com/group/inaturalist.
For more options, visit https://groups.google.com/d/optout.

Ian Kleinfeld

unread,
Apr 20, 2017, 4:11:20 PM4/20/17
to iNaturalist
Hmmmm... so I can POST a new observation, but I can't manage to add it to a project.

This is the POST url I'm using, what am I doing wrong? The response is {"error":"Not found"}

Ian Kleinfeld

unread,
Apr 20, 2017, 4:16:36 PM4/20/17
to iNaturalist
When using POSTMAN to try the POST, here's the response:


{
  "errors": [
    "Observation can't be blank"
  ],
  "object": {
    "id": null,
    "project_id": 10110,
    "observation_id": 5875491,
    "created_at": null,
    "updated_at": null,
    "curator_identification_id": null,
    "tracking_code": null,
    "user_id": null,
    "uuid": "7708ab3e-1adc-4a64-8087-a5f6857e35f2"
  }
}

On Thursday, April 20, 2017 at 10:32:18 AM UTC-4, Scott Loarie wrote:
You need to separately post the observation and then the project_observation
On Thu, Apr 20, 2017 at 7:30 AM, Ian Kleinfeld <mydes...@gmail.com> wrote:
Looking at the API Reference, it seems that to post a new observation using the API, I first need to post that new observation and THEN add it to a project. Is that correct or am I missing something? 

Ref: 

Is there a way to do this all in one step, i.e., 

POST to observations.json and assign to a project ... 

or do I need to POST / observations then POST / project_observations ?

 

--
You received this message because you are subscribed to the Google Groups "iNaturalist" group.
To unsubscribe from this group and stop receiving emails from it, send an email to inaturalist...@googlegroups.com.

To post to this group, send email to inatu...@googlegroups.com.
Visit this group at https://groups.google.com/group/inaturalist.
For more options, visit https://groups.google.com/d/optout.

Ian Kleinfeld

unread,
Apr 20, 2017, 4:58:12 PM4/20/17
to iNaturalist
Now I'm getting this with POST https://www.inaturalist.org/project_observations.json?project_observation[observation_id]=587610&project_observation[project_id]=10110 and am unclear how to update those properly. 

It would be very helpful to have examples for each entry in the API Reference. :)


{
  "errors": [
    "Didn't pass rules: must have observation field 'Name of photographer' filled out OR must have observation field 'Date of photo' filled out OR must have observation field 'Research name of animal' filled out OR must have observation field 'Animal species' filled out OR must have observation field 'Collection institution' filled out OR must have observation field 'Research name of animal' filled out OR must have observation field 'Animal species' filled out OR must have observation field 'Collection institution' filled out"
  ],
  "object": {
    "id": null,
    "project_id": 10110,
    "observation_id": 587610,
    "created_at": null,
    "updated_at": null,
    "curator_identification_id": null,
    "tracking_code": null,
    "user_id": 423326,
    "uuid": "7e700f17-d5ed-411e-9249-9af81cd0bf64"
  }
}


Should I then update the POST /observation_field_values with      /observation_field_values.json?observation_field_value[observation_id]=587610&observation_field_value[observation_field_id]=????NOIDEA???.... etc?

Sorry, I'm finding this confusing.

Patrick Leary

unread,
Apr 20, 2017, 5:58:24 PM4/20/17
to iNaturalist
Hi Ian,

With POST requests, the parameters should not be included in the URL, rather they should in the body of the POST request. Here's an example of adding an observation to a project, using curl to POST a request to project_observations":

curl -XPOST "http://localhost:3000/project_observations" -H "Content-Type: application/json" -d '{
  "project_observation": {
    "project_id": PROJECT_ID,
    "observation_id": OBSERVATION_ID
  }
}' -H 'Authorization: Bearer YOUR_BEARER_TOKEN'

Patrick Leary

unread,
Apr 20, 2017, 6:05:44 PM4/20/17
to iNaturalist
It is also possible to add an observation to a project in the observation's creation POST call, but I'm not sure I'd recommend it. An observation might fail to be added to a project for a variety of reasons, so for many applications you'd want to first catch any errors on the observation create method, then make a separate call to add the observation to a project and catch and address any validation errors from each project addition. Here's an example curl request for adding while creating:

curl -XPOST "http://localhost:3000/observations.json" -H "Content-Type: application/json" -d '{
  "observation": {
    "description": "your description"
  },
  "project_id": [ PROJECT_ID ]
}' -H 'Authorization: Bearer YOUR_BEARER_TOKEN'

Add in your own real data, including swapping out http://localhost:3000 with https://www.inaturalist.org. Note that project_id in this case is outside the observation object

Ian Kleinfeld

unread,
Apr 21, 2017, 9:58:00 AM4/21/17
to iNaturalist
Thanks Patrick, 

I had been having success with the POSTing of new observations, but I'll try using curl instead.

Ian Kleinfeld

unread,
Jun 5, 2017, 5:20:26 PM6/5/17
to iNaturalist
Hi again Patrick, 

What's the best practice for inaturalist to GET information? Also curl? Or just using the url with GET?

Can you give me a PHP example? 

Thanks!

Patrick Leary

unread,
Jun 7, 2017, 1:40:02 PM6/7/17
to iNaturalist
Our API simply responds to standard HTTP methods (GET, POST, PUT, etc.) over the HTTP and HTTPS protocols. cURL is one of many tools / methods which creates HTTP requests. If you are using PHP, then there are built-in methods, as well as numerous different third-party packages, which will all make HTTP requests. How you choose to make the request is up to you.

I haven't used PHP in a while, but one easy way to make a GET request is with http://php.net/manual/en/function.file-get-contents.php . For example:


If you want to make POST requests from PHP you'll need something different, but I'm sure you can find lots of information on that on the web.
Reply all
Reply to author
Forward
0 new messages