0

I'm trying to send some post json data but I want to make it custom on every post I do with the user input, right now I'm doing it via CLI just to get the PoC.

Im having problems adding the custom input though, I tried this but it didn't work.

import requests
import json

ticket = input("Type the ticket you want to answer : ") 
print("Ticket #" + ticket)

customInput = input("Type the message you will post : ") 
print(answer)

headers = {
    'Content-Type': 'application/json',
}

data = '{ "helpdesk_note": { "body":customInput, "private":true }}'

response = requests.post('http://my.site.com/dir/dir/'+ticket+'/conversations/note.json', headers=headers, data=data, auth=('SOMEKEY', 'X'))

print("Ticket has been answered.")

When this happens it does not post any message but if I do have a premade "body" it posts if I add "" to my message e.g

data = '{ "helpdesk_note": { "body":"This will actually work", "private":true }}'

How can I make it as a custom input ??

IceeFrog
  • 327
  • 3
  • 16

1 Answers1

0

Hello everyone thanks for your time and review, I just found out how to solve this situation in this link .

The code would look like this

data = json.dumps({ "helpdesk_note": { "body":customInput }})

Took it from this example

my_json_string = json.dumps({'key1': val1, 'key2': val2})

Thanks for the read stranger have a nice day stack.

IceeFrog
  • 327
  • 3
  • 16