farmOS / farmOS.js

A JavaScript library for working with farmOS data structures and interacting with farmOS servers.
MIT License
15 stars 13 forks source link

406 Not Acceptable: Unknown data property field_farm_area_type #31

Closed MohamedFarid2018 closed 3 years ago

MohamedFarid2018 commented 3 years ago

if I remove area_type from the body, I get this error: 406 Not Acceptable: Unknown data property field_farm_geofield.

this error happens when I try area.send()

here is the body I'm sending

{ tid: 20, name: 'Farm 1', description: '', area_type: "greenhouse", geofield: [ { geom: 'POLYGON ((-75.53640916943549,42.54421203378203 -75.53607389330863,42.54421796218091 -75.53607121109961,42.54415472589722 -75.53640648722647,42.54414682135726 -75.53640916943549,42.54421203378203))' } ], vocabulary: { id: '2', resource: 'taxonomy_vocabulary' }, parent: [ { id: 11, resource: 'taxonomy_term' } ] }

Amr-MKamal commented 3 years ago

@jgaehring @mstenta

mstenta commented 3 years ago

Hi @Amr-MKamal

Hmm - and you said you're experiencing the same issue with raw curl commands too, correct (via email)?

You probably already know this, but for reference: https://farmos.org/development/api/#creating-taxonomy-terms

(Areas in farmOS 1.x are "taxonomy terms". This changes in 2.x, where they become full-fledged asset types, so you use the asset API endpoints.)

I might recommend that you try creating a different kind of taxonomy term via curl first... to make sure that works as expected... before trying to create an area term. This might help to isolate the problem.

For example, you could try creating a new "Unit" term, or a new "Crop/variety" term. These term types do not have any additional fields on them like area_type or geofield - so presumably they will not have the same issue that you're encountering with the area geofield field.

If you can test that out, and provide the results along with the exact curl command you're using, that would help us to debug this with you.

Amr-MKamal commented 3 years ago

image This worked , but still the same error for areas

mstenta commented 3 years ago

Hmm. Can you paste the full curl command you are trying?

paul121 commented 3 years ago

@Amr-MKamal you might have the wrong vocabulary ID when you're trying to create areas. Both of your examples are using vocabulary id: 2. I think that would explain why you're getting "Unknown data property field_farm_area_type" - the field doesn't exist on the other vocabulary!

Amr-MKamal commented 3 years ago

@mstenta we don't try curl yet for this @paul121 we just tried with VID:7 ( the vocabulary ID for areas ) and it returns the same error

mstenta commented 3 years ago

@Amr-MKamal I'm curious: if you omit both area_type and geofield, does it create the area term?

Amr-MKamal commented 3 years ago

@mstenta @paul121 after re-checking area vid (VID:3) , it successfully creates areas with area type but when sending a geom ( the geom in the example ) it returns 422 Unprocessable Entity response , after digging more in how areas are presented as json in our farmos it appears that they have more fields like geotype , schemaorg_shape , srid , when sending the geom of an already extent area ( manually created , copied from raw json ) the area is created successfully , but when sending only the geom and omitting other fields it sometimes transforms the polygon into a point , it has become ambiguous to us what's needed exactly to create areas programmatically

mstenta commented 3 years ago

@Amr-MKamal I just tested myself and for some reason your polygon geometry is being rejected as invalid. The same is true if I try to paste it directly into the "Data" field below a map in the farmOS UI (when creating a new area through farmOS directly).

The specific response I get when I try to submit it via the API is: 422 Unprocessable Entity: Field validation errors

For reference, I tested this API POST command and it works as expected (with a valid geometry):

curl --cookie farmOS-cookie.txt -H "X-CSRF-Token: ${TOKEN}" -X POST -H 'Content-Type: application/json' -d '{"name": "Test API Area Creation", "vocabulary": {"id":"1"}, "area_type": "field", "geofield": [{"geom": "POINT(-31.04003861546518 39.592143995003994)"}]}' https://test.farmos.net/taxonomy_term

This (with your geometry) does not:

curl --cookie farmOS-cookie.txt -H "X-CSRF-Token: ${TOKEN}" -X POST -H 'Content-Type: application/json' -d '{"name": "Test API Area Creation", "vocabulary": {"id":"1"}, "area_type": "field", "geofield": [{"geom": "POLYGON ((-75.53640916943549,42.54421203378203 -75.53607389330863,42.54421796218091 -75.53607121109961,42.54415472589722 -75.53640648722647,42.54414682135726 -75.53640916943549,42.54421203378203))"}]}' https://test.farmos.net/taxonomy_term
mstenta commented 3 years ago

Interestingly, when I paste your geometry into http://arthur-e.github.io/Wicket/sandbox-gmaps3.html it does appear to display - but it's a very odd shape (almost a straight line).

The code that parses WKT in farmOS may have different validation criteria than the code in that website, however.

I would recommend testing with a different geometry.

paul121 commented 3 years ago

@Amr-MKamal once you paste your geometry into the Wicket example linked above I noticed that if you edit the geometry just a little bit (drag a corner) then the WKT is updated to a geometry that works.

Actually, it looks like the coordinate list in your POLYGON doesn't start with a correct lat/long pair, it's just a single number, followed by lat/long pairs, and finally ending with a single number. Seems like the first and last numbers need to go together. The following works, but seems to rotate the geometry 180 degrees (upside down)?

POLYGON ((42.54421203378203 -75.53640916943549,42.54421203378203 -75.53607389330863,42.54421796218091 -75.53607121109961,42.54415472589722 -75.53640648722647,42.54414682135726 -75.53640916943549))
Amr-MKamal commented 3 years ago

@mstenta @paul121 Thank you all , the geometry indeed had a typo , I think @MohamedFarid2018 can close the issue now