# Filebeat CEL Input: how to pass headers in request?

**URL:** <https://discuss.elastic.co/t/filebeat-cel-input-how-to-pass-headers-in-request/351746>\
**Category:** Beats\
**Tags:** filebeat\
**Created:** [January 24, 2024, 5:56pm UTC](https://discuss.elastic.co/t/filebeat-cel-input-how-to-pass-headers-in-request/351746 "2024-01-24T17:56:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![kelk](https://avatars.discourse-cdn.com/v4/letter/k/13edae/32.png) [@kelk](https://discuss.elastic.co/u/kelk)\
**Post date:** [January 24, 2024, 5:56pm UTC](https://discuss.elastic.co/t/filebeat-cel-input-how-to-pass-headers-in-request/351746/1 "2024-01-24T17:56:40Z")

</div>

I'm trying to pull from an API which has got Digest authentication ONLY enabled. Hence cannot use `httpjson`

But in input.type of `cel`, how do I pass request headers like 'Content-Type: application/json' etc?

Below is my sample code,

```auto
- type: cel
  auth.digest:
	user: myuser
	password: mypass
  resource.url: https://myapi.com/v3/someapi/
  program: |
    bytes(get(state.url).Body).as(body, {
        "events": [body.decode_json()]
    })
  http_headers:
	Content-Type: "application/json"
	my-key: "my-value"

```

but the http\_headers is getting discarded. Any options to pass on the headers?

---

<div class="post-metadata">

**Author:** ![strawgate](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/strawgate/32/131008_2.png) [@strawgate](https://discuss.elastic.co/u/strawgate)\
**Post date:** [January 24, 2024, 7:34pm UTC](https://discuss.elastic.co/t/filebeat-cel-input-how-to-pass-headers-in-request/351746/2 "2024-01-24T19:34:44Z")

</div>

Are you sure you need to set a content-type on the GET request?

Generally GET requests should not have content-type because they do not have request entity (that is, a body), normally content-type would be set on a PUT/POST request.

You can set the Content-Type for a post/put by providing it as the second parameter to the POST request: `post(state.url,"application/json",...)`

But I dont think CEL supports this for a GET request and I don't think http\_headers is a supported field for CEL inputs.

---

<div class="post-metadata">

**Author:** ![kelk](https://avatars.discourse-cdn.com/v4/letter/k/13edae/32.png) [@kelk](https://discuss.elastic.co/u/kelk)\
**Post date:** [January 25, 2024, 7:56am UTC](https://discuss.elastic.co/t/filebeat-cel-input-how-to-pass-headers-in-request/351746/3 "2024-01-25T07:56:27Z")

</div>

Atlast found a way. CEL is very powerful, but very hard to understand from docs !! doh !  
So the concept is

- don't directly use `GET`, but use `request(GET..)`
- This way you can customise the `request` into any format you need and pass on the Header using `.with` function
- Then do a `.do_request()`  
Documentation here: [lib package - github.com/elastic/mito/lib - Go Packages](https://pkg.go.dev/github.com/elastic/mito/lib#hdr-Do_Request)

```auto
- type: cel
  interval: 10m
  resource: 
    url: "https://myapi.com/v3/someapi/"
  program: |
    bytes(request("GET", state.url)
      .with({"Header": {"Accept": ["application/json"], "my-key": ["my-value"]}})
      .do_request().Body
    ) as(body, { 
            "events" : [body.decode_json()]}
          )

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [February 22, 2024, 9:56am UTC](https://discuss.elastic.co/t/filebeat-cel-input-how-to-pass-headers-in-request/351746/4 "2024-02-22T09:56:51Z")

</div>

Closed on February 22, 2024, 9:56am UTC

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
