I am new to ticketing system - OTRS. I can successfully create a OTRS ticket using pyotrs, also access ticket attributes like ticket number etc. However, I dont have any idea how to close a ticket using otrs ticket-id or ticket number. On close inspection in OTRS documentation I got the following -
"Attention: PyOTRS can only retrieve Ticket data at the moment!".
So any suggestion as to how to close an OTRS ticket with or without python (non-GUI)?
I assume you already have a webservice named "GenericTicketConnectorREST" (because of the pyotrs example webservice). In there you need to have an operation called TicketUpdate (last entry in the image).
Under "Configuration" you should add/change the entry for TicketUpdate (i had to change it):
Using Postman (or any tool to send your rest request) you can send the following JSON to close a Ticket. Remember to set the Postman request to Patch, as it is set in the configuration.
{
"UserLogin":"root#localhost",
"Password":"root",
"TicketID":"1",
"Ticket":{
"State": "closed successful"
},
"Article":{
"ContentType":"text/plain; charset=utf8",
"Subject":"Ticket closed",
"Body":"Ticket closed"
}
}
The URL Depends on the name of your webservice and how you set the routing (TicketUpdate). http://localhost/otrs/nph-genericinterface.pl/Webservice/GenericTicketConnectorREST/TicketUpdate.
You can change anything listed in the api for the operation "TicketUpdate". Eveything under the key Data is something you can add to change.
https://doc.znuny.org/doc/api/otrs/6.0/Perl/Kernel/GenericInterface/Operation/Ticket/TicketUpdate.pm.html
Related
I'm trying to create a monthly subscription with stripe.
I wrote a sample code like that
if event_type == 'checkout.session.completed':
# Payment is successful and the subscription is created.
# You should provision the subscription and save the customer ID to your database.
try:
session = stripe.checkout.Session.retrieve(
event['data']['object'].id, expand=['line_items', 'subscription'])
_current_period_end = session['subscription']['current_period_end']
_current_period_start = session['subscription']['current_period_start']
_product_id = session['subscription']['items']['data'][0]['plan']['product']
_user_id = session['client_reference_id']
_stripe_customer_id = session['customer']
_subscription_id = session["subscription"]['id']
'''
do other things to update user package
'''
except Exception as e:
'''
error log
'''
elif event_type == 'invoice.paid':
if THIS_IS_NOT_FIRST_TIME:
parse_event_data
'''
do other things to extend subscription
'''
I have some questions;
I parsed web hook result from a dict which is returned from stripe.checkout.Session.retrieve object. It seemed a little bit odd to me. What if stripe update his API response and use a different names for dict keys that i used? Is there another way to get these values such as with dot notation maybe (session.get.product_id)?
How can i understand that invoice.paid event not triggered for the first time of subscription?
I want to test renewal process of my monthly subscription. I used stripe trigger invoice.payment_succeeded but i need a real data for my test accounts (with a test customer, subscription, product etc...)
I can update my user package with using CHECKOUT_SESSION_ID
from checkout success url ("success?session_id={CHECKOUT_SESSION_ID}). Should i do that or use checkout.session.completed web hook?
I have just returned HTTP 500 response to every request to my webhook URL to see if STRIPE show an error message to user in checkout page. However, STRIPE just created a successful subscription. In that case, STRIPE will take a payment from my customer, however even if i can not update my customer package on my database. What should i do to prevent this issue? Should i create a scheduled job to sync data between STRIPE and my db?
You have many separate questions that would be better suited for Stripe's support team directly: https://support.stripe.com/contact/email
Now I will try to touch on some of the questions you had starting with the first one.
When you call session = stripe.checkout.Session.retrieve(...) you get back a class that is a Checkout Session. All the properties of the class map to the properties covered in the API Reference for Session. This means you can do session.id which is cs_test_123 or session.created which is a timestamp of the creation date. It's not really different from accessing as a dictionary overall.
You're also asking if those can change and Stripe explains their backwards compatibility policy in details in their docs here. If they were to change a name from created to created_at, they would do it in a new API version for new integrations and it wouldn't impact your code unless you manually changed the API version for your account so that is safe.
For the invoice.paid event, you want to look at the invoice's billing_reason property which would be subscription_create for the first invoice.
You can test all of this easily in Test mode, create a session, start a subscription, etc. You can also simulate cycle changes.
I hope this helps but chatting with their support team is your best bet since those are more integration questions and not coding questions.
First of all, I'm a beginner at discord.py. It's hard to explain my problem but I'll try my best:
I'm trying to make a single command which sends different messages to users with different settings.
For example:
Let's say my bot has 2 commands !command and !settings.
A user changes his/her setting with the setting command: "!settings (setting1/setting2/setting3/setting4...)"
If the user uses the !command with (setting1), it will send "response1". But if user has (setting2) it will send "response2", and if user has (setting3) it will send "response3" and so on...
I will appreciate any help :)
I will try my best to explain to you!
To make it happen, we need to store those data in the database!(what is database? to store some data which we can update, delete, and use anytime.) So, we are going to store it in the database. (what we are going to store? we are going to store each user's settings)
For Example! if a person used !settings 1 then we are going to store it in database like this.
{ "user_id": discord_user_id_here,"settings":1}
the discord user id of each person is unique so we use that to store it in the database!.(but where we are going to store it? there is a free best company called "MongoDB" is providing us free database! we will save our data there. and we can completely control it with python)
Now we have saved that user in database and we can do anything in that! but now the important thing, after saved when he uses the first command "!command", we need to fetch the settings from the database! and we can run anything according to his settings!.
LINKS:
MongoDB - https://www.mongodb.com/
MongoDB python Docs - https://pymongo.readthedocs.io/en/stable/
Complete Best Tutorial For MongoDB python - https://www.youtube.com/watch?v=rE_bJl2GAY8
I wanted to know if there is a way to create a watch channel for specific users or attributes ?
For example when I update the field organizational unit on a user i want to be notified when the action have been effectively performed without being obliged to get the user periodically.
I tried the use the query parameter when initializing the watch channel, in this case for what i understood of the documentation to watch users having a given name containing Jane, but it seems not to work because as I receive updates for all the domain.
users_service = service.users()
channel_id = str(uuid4())
watch_body = {
"id": channel_id,
"type": 'web_hook',
"address": notifications_script,
"params": {
"ttl": watch_duration
}
}
watch = users_service.watch(
body=watch_body,
event=event,
customer=customer,
query="givenName:Jane*"
).execute()
Can you please tell me if I am doing or understanding wrong or if what I entend to do is even possible.
Thank you very much in advance,
Raphaël
PS : I am using the google-api-python-client
It appears that I was using the wrong API to fulfill my use case.
Use the reports API instead if you want to monitor activity on specif attributes or users of your domain.
Here is the corresponding documentation : https://developers.google.com/admin-sdk/reports/v1/guides/push.
Kind regards,
Raphaël
I was wondering how I could display a simple message to the user at the top of their screen at a certain time in Django. I haven't been able to find anything online about this, so I was wondering how I would go about doing this.
Would I need to do something with DateTime? What view/model would I include the code in?
Thanks for any help you can give :)
I still don't have enough reputation to comment:
So just tell me when you 'read' this answer and I will delete it.
If you want you might copy / paste the interesting parts into a comment.
I think the exact use case is very important for giving the right answer.It all depends what exactly you mean with 'certain time'.
Notification time is known upfront (javascript alert)
Asking the Django server periodically can determine when to send the message (polling long / polling)
The Django server needs to perform some background task and the message should be sent at the end of this task
If you know already upfront (at the time the user opens the page) when this notification should happen, then Kostas Charitidis is right.
The page can just use javascript to program a timer and it will be the web browser who can at the given time make a request to Django to fetch an display the message.
To 'push' anything from a web server to a web browser at a given time one requires something like continous polling, long polling, web-sockets.
If the notification time is not known upfront, then
a polling approach would for example use a piece of javascript, that periodically (every few seconds / minutes / depending on your use case) queries the Django server whether a message should be fetched.
Long polling is an approach where the web browser performs a get request to the server and the server stalls the answer until the message should be sent. (if the requests times out a new polling request will be initiated)
However to use long polling (efficiently) you'd need some special plugins on the server side to make this efficient / resource friendly.
If your web site does not need to be accessed from behind some old corporate (or paranoid) firewalls, then you might consider using web sockets (but there are still some public services / big companies who do block web sockets)
django-channels ( https://pypi.org/project/channels/ ) can help you with web socket notifications and some background tasks
celery ( https://pypi.org/project/celery/ ) can help you with running periodic / defered / tasks, but does not contain the means to send the message to your browser.
Celery is one of the most recommended solutions, but is (in my opinion) rather painful to set up.
Depending on the project something lighter (like for example django-background-tasks https://pypi.org/project/django-background-tasks/ ) might do the job
You might look at the django message frame work ( https://docs.djangoproject.com/en/2.2/ref/contrib/messages/) . But very probably it is not the right answer in your context.
You don't need any model to do this,
Option 1
Use ajax (Use when you want to refresh certain time on specific interval)
Just create a view like,
import datetime
from django.http import JsonResponse
def get_certain_date(request):
# or get certain date from database or somewhere else.
return JsonResponse({'certain_date':datetime.datetime.now()})
And use ajax call to update html contents.
Option 2 (Use when you dont want to update certain time untill user refreshes page)
render certain time in django view.
from django.shortcuts import render
def home(request):
render(request, "html.html", {'certain_time': certain_time}) # get it from database.
You can do it purely with frontend Javascript. No Django code needed at all. However, it depends on what you intend to do.
<p id="demo" ></p>
<script>
var today = new Date();
var date = today.getFullYear()+'-'+(today.getMonth()+1)+'-'+today.getDate();
var time = today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds();
var dateTime = date+' '+time;
if (today.getHours() >= 1){
document.getElementById("demo").innerHTML = "Insert your message here!!";
}
else {
document.getElementById("demo").innerHTML = "We don't want you to know the message yet";
}
</script>
If the time when the user loads the page is past 1AM for the day (the time I am using given where I am for testing), it shows the "Insert your message here!!". If it is not yet that time, it shows "We don't want you to know the message yet".
Insert your chosen hour in the if statement and set your chosen message to the innerHTML.
Alternatively, you could use Javascript to show or hide an element. You can use something like this for that.
if (if (today.getHours() >= 1)) {
document.getElementById("demo").style.display = "block";
} else {
document.getElementById("demo").style.display = "none";
}
For the case (proposed by Nishant) where you need it for the server time rather than the user time, you would get the hour from datetime.datetime.now(), and pass as a variable (say perhaps curr_date_hour) and substitute it into the Javascript if statement like so:
if (if (today.getHours() >= {{curr_date_hour}})) {
document.getElementById("demo").style.display = "block";
} else {
document.getElementById("demo").style.display = "none";
}
I'm trying to use AJAX with web2py language but I have a problem
My code is:
javascript
$(document).ready(function(){
$(".className").click(function(){
jQuery.ajax({
type:'POST',
url:'getName',
data:{
itemName:'a'
},
timeout: 20000,
success: function(msg) {
alert(msg);
},
error: function(objAJAXRequest, strError){
alert( "Error:" + strError );
}
});
});
default.py
def getName():
itemName=request.vars.itemName
return "Name: " + itemName
The thing is I want to use the data from the database, but is it possible to use
{{for item in tableName:}}
var name={{=item.name}}
like this?
I'm not sure how to extract data from DB in javascript.
Can you help me a bit?
Cheers
The short answer is that you can't directly extract data from the db in javascript using web2py. You have to query the db with web2py, and then use web2py to send your query data to the javascript (or more accurately since you're using ajax, use jquery/javascript to pull your query data down from web2py). Make sure that you actually need to perform logic on the client (javascript) side here, because the easiest thing to do would be to perform all your logic in python in the web2py controller.
However, if you do for some reason need to perform logic on your data on the client side, then you are on the right track. The easiest thing for you to do would be fetch the records you need from the db in the web2py controller, then package the records up as a json object in your web2py controller ("import simplejson" or you can do it with the standard library with the latest version of python), then return that json object to make it available for your js to fetch using the ajax request you've included above. Only at that point should you loop through the json object using the javascript to get the data you need.
That said, if you're just trying to get a field from a single record from the database, the easiest thing to do would be just to query the database correctly to get that record, and return it in a web2py controller for your ajax script to get.