Comments (5)
Hi Atul,
Please refer to the following code.
## This script requires "requests": http://docs.python-requests.org/
## To install: pip install requests
import requests
import json
api_key = "YOUR_API_KEY"
domain = "YOUR_DOMAIN"
password = "x"
multipart_data = {
'email': (None, '[email protected]'),
'subject': (None, 'Ticket Title'),
'description': (None, 'Ticket description.'),
'attachments[]': ('bat.jpg', open('bat.jpg', 'rb'), 'image/jpeg'),
'status': (None, '2'),
'priority': (None, '2'),
'custom_fields[sample_text]': (None, 'this is the text'),
'cc_emails[]': (None, '[email protected]')
}
r = requests.post("https://"+ domain +".freshdesk.com/api/v2/tickets", auth = (api_key, password), files = multipart_data)
if r.status_code == 201:
print "Ticket created successfully, the response is given below" + r.content
print "Location Header : " + r.headers['Location']
print "x-request-id : " + r.headers['x-request-id']
else:
print "Failed to create ticket, errors are displayed below,"
response = json.loads(r.content)
print response
print "x-request-id : " + r.headers['x-request-id']
print "Status Code : " + str(r.status_code)
from fresh-samples.
Nevermind, I figured out.
If you need to send multiple attachments, then you have to send the ticket field values inside the "data" argument in the post, and only use the "files" argument to send the multiple attachments:
requests.post(
post_url,
auth=post_auth,
data={
'subject': 'sub',
'description': 'desc',
'email': '[email protected]',
'priority': 2,
'status': 2
},
files=[
('attachments[]', ('photo.png', open('photo.png', 'rb'))),
('attachments[]', ('textfile.txt', open('textfile.txt', 'rb'))),
('attachments[]', ('compressed.zip', open('compressed.zip', 'rb'))),
]
)
It works like that.
from fresh-samples.
Even the sample code which is given for creating ticket with attachment is not working.
from fresh-samples.
And how do i send multiple attachments...with attachment url not stream
from fresh-samples.
Hi @seetharam-rajagopal your code works great, thanks for sharing.
However, I can't figure out how to adapt it for multiple attachments.
Giving that multipart_data is a dictionary, 'attachments[]' key can be present only once. I've tried to set the value for that key to a list, but it doesn't work.
How would you do it for multiple attachments?
from fresh-samples.
Related Issues (20)
- Inconsistent api endpoint in code
- How can I post more than one attachments? HOT 3
- PHP Attatchment with Custom field
- The underlying connection was closed: An unexpected error occurred on a send. HOT 5
- PHP: validation error for all ticket fields when setting header content-type "multipart/form-data" HOT 2
- Creating ticket with attachments giving strange error
- Could you add examples when handling paging ?
- How add public Notes HOT 1
- Using JavaLite HTTP library
- having non ASCII characters in filenames
- Full .NET/C# Wrapper
- Error while trying to create a ticket with attachment
- Location for Knowledge Base HOT 1
- Nodejs samples don't look satisfying
- Viewing and Updating a ticket with custom fields HOT 1
- Licensing the samples
- How to send input value throw freshdesk api? Need help asap HOT 1
- Not able to create custom fields using PHP HOT 1
- Python - Create ticket with attachment HOT 1
- Basic Authentication Deprecation in Exchange Online
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fresh-samples.