Request from coda.io

Hello.
I send a request from Python:

requests.request("POST", "https://test/test/", data={'user': 'demo', 'pass': '12312313'})

and from Coda.io:

let payload = {
       "user": user,
       "pass": pass,
     };
     let url = "https://test/test/";
     let body = JSON.stringify(payload);
     let response = await context.fetcher.fetch({
       cacheTtlSecs: 0,
       method: "POST",
       url: url,
       headers: {
         "Content-Type": "application/json"
       },
       body: body,
     });

     let data = response.body;

And I see that data is coming to the server in different formats.
"user=demo&pass=12312313"
"{\"user\":\"demo\",\"pass\":\"12123\"}"

I think that at the output of the coda.io the request somehow changes…
Can you tell me how to get around this, or maybe I don’t understand something. Thank you in advance!

The first suggests the values are passed in the URL. The second suggest the data is passed in the body.

I’m no Python expert, but I think you want something like this where myobj is the json data object.

x = requests.post(url, json = myobj)

Thanks for the answer)

I’m more concerned about what the coda.io does with the data, it feels like the coda.io is adding something somewhere at the output, and authorization is not going on the server (which I also don’t control)…

Don’t you mean - you’re more concerned with what //test/test does with the data passed from Coda?

Which format is working? The Python or the JavaScript examples?

Hi @pavel_tsvetov - Welcome to the Coda community! It looks like the data parameter of Python’s Requests library passes the values as form-encoded pairs:

Your dictionary of data will automatically be form-encoded when the request is made:

https://requests.readthedocs.io/en/latest/user/quickstart/#more-complicated-post-requests

You can do the same thing in the Pack SDK Fetch using the form field of the request:

let response = await context.fetcher.fetch({
  method: "POST",
  url: "https://httpbin.org/post",
  form: {
    name: "Alice",
    active: String(true),
    days: String(15),
  },
});
3 Likes

Python is running.
Below is an explanation of what I did wrong in js

Thanks a lot! have a nice day!
I realized that I was doing it wrong!

Didn’t display?