How much of the form payload is needed for a succesful PUT /v1/projects/{id}
? Somehow, I’m not getting it … error 400 every time.
Example working code (at least it returns 200) that just does an authenticated GET:
import requests
from pyinaturalist import get_access_token
access_token = get_access_token(
username="dronefly",
password="REDACTED",
app_id="REDACTED",
app_secret="REDACTED",
)
response = requests.get(
"https://api.inaturalist.org/v1/projects/545640",
headers={"Content-Type": "application/json", "Accept": "application/json", "Authorization": f"Bearer {access_token}", "User-Agent": "Dronefly/1.0"},
)
print(repr(response))
This is fine and returns:
<Response [200]>
But if I give this as complete a payload as I can as a PUT based on the properties of a test project I created, I get error 400:
payload = {
"project": {
"project_type": "collection",
"user_id": 545640,
"title": "Moderated membership test",
"description": "A project to learn about writing code to add or remove user observation rules without destroying a real project in the process.",
"preferred_banner_color": "#74ac00",
"prefers_hide_title": False,
"prefers_hide_umbrella_map_flags": False,
"prefers_banner_contain": False,
"prefers_rule_quality_grade": "research,needs_id",
"prefers_rule_photos": "",
"prefers_rule_sounds": "",
"prefers_rule_term_id": "",
"prefers_rule_term_value_id": "",
"prefers_rule_observed_on": "",
"prefers_rule_d1": "2022-01-01",
"prefers_rule_d2": "",
"prefers_rule_month": "",
"prefers_rule_native": "",
"prefers_rule_introduced": "",
"prefers_user_trust": False,
"project_observation_rules_attributes": [
{"operand_id":545640,"id":831633,"operand_type":"User","operator":"observed_by_user?","_destroy":False},
],
"admin_attributes": [
{"user_id":1474198,"role":"manager","id":1474198,"_destroy":False},
{"user_id":545640,"role":"manager","id":1474187,"_destroy":False},
],
},
}
response = requests.put(
"https://api.inaturalist.org/v1/projects/545640",
headers={"Content-Type": "application/json", "Accept": "application/json", "Authorization": f"Bearer {access_token}", "User-Agent": "Dronefly/1.0"},
data=payload,
)
print(repr(response))
Then I just get:
<Response [400]>
I had hoped I could just submit the fields I wanted to change, so I started with a simpler payload that only included the project_observation_rules_attributes. However, that failed (same response: error 400), so then I tried the fuller payload specifying everything that would be on the form instead. Still no joy.