Great question, I agree that can be a bit confusing. If you want to pass multiple post_ids you would pass in multiple form data fields for post_ids[] like this curl example:
Is this still the recommended way to send an array to the API? I’m trying to create a web hook and I’m not able to send the web_hook_event_type_ids array parameter.
I’ve tried it with CURL (as multipart/form-data)
curl -X POST "https://MYSITE.com/admin/api/web_hooks" \
-H "Api-Key: KEY" \
-H "Api-Username: USER" \
-F "payload_url=https://MYOTHERSITE.com" \
-F "content_type=1" \
-F "wildcard_web_hook=false" \
-F "verify_certificate=true" \
-F "active=true" \
-F "web_hook_event_type_ids[]=2"
# I get
{"errors":["param is missing or the value is empty: web_hook"]}%
Looks like this whole endpoint wants the values in a nested web_hook param:
I’m not a huge fan of this nested format, and there are a few endpoints like this that are on my eventual list to fix. You can make an API call to it using form-data like so:
Notice how each parameter has the “array” syntax web_hook[payload_url]. If you are sending your request with json it will look like:
Ah, thank you so much. That’s not what it said in the Discourse API, so I was going crazy.
Also, I’ve noticed that setting web_hook_event_type_ids to at least one item is required even if I end up using wildcard_web_hook=true. That also had me scratching my head for a while.