Skip to content

Add ability to send custom PUT and PATCH requests with JSON body #577

Closed

Description

@moschi

Bug description
We have a REST endpoint to update a datastructure that requires the use of the HTTP PUT method.
We're using request from the Context class to send a request to that endpoint.
On binding.py#L876, the _encode method is called, whose result is used to overwrite the original body parameter of the method. This causes the request-body to be url-encoded and url-formatted.

Steps to reproduce the behavior:

Send a HTTP PUT request with a JSON body to an endpoint, using the request method of the Context class.

Expected behavior

The request method correctly escapes a JSON body, or provides instructions on how to call it to prevent the URL-encoding.

Logs or Screenshots

Currently, our REST endpoint receives a payload similar to this:

event=%7B%27_key%27%3A+%2766548f65179fc9792600b193%27%2C+%27tenant_uid%27%3A+%27default%27%7D&update_objects=%7B%27attribute%27%3A+status%2C+%27value%27%3A+%2766436bc36265a3697e049fe6%27%7D&comment=Updated

which does not decode to a valid JSON structure:

event={'_key':+'66548f65179fc9792600b193',+'tenant_uid':+'default'}&update_objects={'attribute':+status,+'value':+'66436bc36265a3697e049fe6'}&comment=Updated

Splunk:

  • Version: Enterprise 9.1.1
  • OS: RHEL 8.8 (Ootpa)
  • Deployment: single-instance

SDK:

  • Version: 1.7.4, bug persists in 2.0.1
  • Language Runtime Version: python 3.7
  • OS: RHEL 8.8 (Ootpa)

Activity

  1. seiimonn commented on Aug 19, 2024

    @seiimonn
    Contributor

    Hi team!

    Could we please get a response on this?
    It seems to be a minor fix!

    Thank you!

  2. Ickerday commented on Sep 8, 2025

    @Ickerday
    Collaborator

    Dismissed as stale. Please tell us if the issue persists!

  3. seiimonn commented on Sep 9, 2025

    @seiimonn
    Contributor

    @Ickerday, this is not stale and still makes using the SDK infeasible.

  4. Ickerday commented on Sep 9, 2025

    @Ickerday
    Collaborator

    Thanks @seiimonn, we're taking a look!

  5. mateusz834 commented on Sep 9, 2025

    @mateusz834
    Member

    Could you provide us with a complete reproducer?

    From the description i assume you are doing something like:

    service.request("test", method="PUT", body={"key": json.dumps({"key": 1})})

    I observe that in such case we are sending following HTTP body:

    key=%7B%22key%22%3A+1%7D
    

    Which decodes successfully:

    from urllib.parse import parse_qs
    
    out = parse_qs("key=%7B%22key%22%3A+1%7D")
    for k, v in out.items():
        for v in v:
            print(k, json.loads(v))
  6. moschi commented on Sep 9, 2025

    @moschi
    Author

    The original issue description is a bit imprecise.
    The post method of the service allows sdk users to pass the body param as a string - this leads to the service class skipping the encoding, as opposed to automatic encoding if a dict is passed. However, the request method (as a stand-in for the missing put and patch method) does not behave the same way. It would force us to check if we're working with form-data or with stringified JSON in our script endpoints.

    Our desire is for the sdk API to be persistent so that we can use put and patch the same way we can use post - with stringified JSON, which we escape ourselves.
    You can find an implementation for put and patch here: #586

    If adding put and patch to the sdk is not an option, a check similar to the one in post before encoding the body in the generic request method would be feasible as well.

  7. changed the title [-]binding.py // Context.request URL-encodes request body[/-] [+]Add ability to send custom `PUT` and `PATCH` requests with JSON body[/+] on Sep 15, 2025
  8. mateusz834 commented on Nov 5, 2025

    @mateusz834
    Member

    So we plan to support both ways to make it consistent:

    I sent: #683 (which add more tests and implements the logic in the request method).

    We also plan to go with #586, so that we are consistent. We are waiting for @seiimonn to get that change rebased on top of the develop branch.

  9. seiimonn commented on Nov 6, 2025

    @seiimonn
    Contributor

    Hi @mateusz834 - did the rebase!

  10. self-assigned this
    on Nov 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions