# How do you pass an array to the api

**URL:** https://meta.discourse.org/t/how-do-you-pass-an-array-to-the-api/121598
**Category:** Development
**Tags:** rest-api
**Created:** [28 juni 2019 om 16:57 UTC](https://meta.discourse.org/t/how-do-you-pass-an-array-to-the-api/121598 "2019-06-28T16:57:37Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Nikki\_Locke](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nikki_locke/32/146184_2.png) [@Nikki\_Locke](https://meta.discourse.org/u/Nikki_Locke)
#### Post date: [28 juni 2019 om 16:57 UTC](https://meta.discourse.org/t/how-do-you-pass-an-array-to-the-api/121598/1 "2019-06-28T16:57:37Z")

</div>

On some of the api calls, you are expected to pass an array of values in the post data. How do you do this?

I have figured out by trial an error how to pass an array with one item in it - e.g. for change-owner, you want something like:

```
username: sean-finnegan
post_ids[]: 925

```

(or, in url-encoded)

```
post_ids%5B%5D=925&username=sean-finnegan

```

---

<div class="post-metadata">

### Author: ![blake](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/blake/32/157322_2.png) [@blake](https://meta.discourse.org/u/blake)
#### Post date: [1 juli 2019 om 18:17 UTC](https://meta.discourse.org/t/how-do-you-pass-an-array-to-the-api/121598/2 "2019-07-01T18:17:17Z")

</div>

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:

```plaintext
curl -i -sS -X POST "http://localhost:8080/t/15/change-owner.json" 
-H "Api-Key: api-key" \
-H "Api-Username: system" \
-F "username=blake" \
-F "post_ids[]=29" \
-F "post_ids[]=30"

```

---

<div class="post-metadata">

### Author: ![Nacho\_Caballero](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nacho_caballero/32/130189_2.png) [@Nacho\_Caballero](https://meta.discourse.org/u/Nacho_Caballero)
#### Post date: [6 september 2020 om 12:35 UTC](https://meta.discourse.org/t/how-do-you-pass-an-array-to-the-api/121598/3 "2020-09-06T12:35:54Z")

</div>

Hey Blake,

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)

```plaintext
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"]}%

```

And with [httpie](https://httpie.org/docs#usage) (as application/json):

```plaintext
http POST https://MYSITE.com/admin/api/web_hooks \
  Api-Key:KEY \
  Api-Username:USER \
  payload_url=https://MYOTHERSITE.com \
  content_type=1 \
  wildcard_web_hook:=false \
  verify_certificate:=true \
  active:=true \
  web_hook_event_type_ids:='[2]'

# I get
{
    "errors": [
        "Web hook event types can't be blank"
    ]
}

```

---

<div class="post-metadata">

### Author: ![blake](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/blake/32/157322_2.png) [@blake](https://meta.discourse.org/u/blake)
#### Post date: [6 september 2020 om 12:48 UTC](https://meta.discourse.org/t/how-do-you-pass-an-array-to-the-api/121598/4 "2020-09-06T12:48:46Z")

</div>

Looks like this whole endpoint wants the values in a nested `web_hook` param:

> [@Nacho\_Caballero](#):
>
> `param is missing or the value is empty: web_hook`

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:

 ![image](https://global.discourse-cdn.com/meta/original/3X/b/1/b130a503a438a684f4973a593851f35d99ed22e7.png)

Notice how each parameter has the “array” syntax `web_hook[payload_url]`. If you are sending your request with json it will look like:

```plaintext
{
  "web_hook": {
    "payload_url": "https://example.com/hello",
    "content_type": "1",
    ...
  }
} 

```

---

<div class="post-metadata">

### Author: ![Nacho\_Caballero](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nacho_caballero/32/130189_2.png) [@Nacho\_Caballero](https://meta.discourse.org/u/Nacho_Caballero)
#### Post date: [6 september 2020 om 12:55 UTC](https://meta.discourse.org/t/how-do-you-pass-an-array-to-the-api/121598/5 "2020-09-06T12:55:00Z")

</div>

Ah, thank you so much. That’s not what it said in the [Discourse API](https://docs.discourse.org/#tag/Web-Hooks/paths/~1admin~1api~1web_hooks/post), 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.
