I'm very new to development, I'm writing a Python Flask app which is executing a POST request to log a new ticket on a system, I just need someone to verify how I structure this request as I'm really not sure.
The documentation says, for example:
curl api/v3/requests
-X POST
-H "Accept: application/vnd.manageengine.sdp.v3+json"
-H "Authorization: Zoho-Oauthtoken 1000.7xxx98976ab0xxxxxx19901e7551be57.bxxxx921ed64c04f79622bebcfxxxxxx"
-H "Content-Type: application/x-www-form-urlencoded"
-d input_data= '{
"request": {
"subject": "Need an External Monitor",
"resolution": {
"add_to_linked_requests": false,
"content": "The following is the resolution to the above request"
}
}
It's expecting input_data key, followed by the JSON array of info to submit.
The documentation is (here)
My code:
#app.route("/log", methods=["GET"])
def log():
"""Fetching a protected resource using an OAuth 2 token.
"""
servicedesk = OAuth2Session(client_id, token=session['oauth_token'])
headers = {"Authorization": "Bearer " + token, "Accept": "application/vnd.manageengine.sdp.v3+json", "Content-Type": "application/x-www-form-urlencoded"}
data = {
"request": {
"subject": "New Incident",
"mode": {
"name": "E-Mail",
},
"group": {
"name": "Incident"
},
"requester": {
"name": "Sarah Curtis Test"
},
"status": {
"name": "Open",
},
"template": {
"name": "Report an Incident"
},
"request_type": {
"name": "Incident",
},
"description": "This is a test. please ignore",
"category": {
"name": "Incident"
}
}
}
requests.post('https://sdpondemand.manageengine.eu/api/v3/requests?input_data=', data=data, headers=headers)
I don't have access to logs on the server to see what it is receiving either as it's a cloud service (unless there's a way to echo back the original raw POST request?)
The ticket isn't being logged when I try and do so via my app. It does work through Postman app to test the API request, when I add the JSON above into the x-www-form-urlencoded section on the body tab and put input_data into the key.
I need to know how to structure the POST request in my code. Any help appreciated! Thanks
Related
I am using Python with Requests module to connect to an EasyRedmine API. I'm having trouble creating a project using the post method in order to post a JSON. It returns "[Unprocessable Entity
<Response [422]>]". I have tried the same request using Postman and Curl and it works perfectly. Does anyone know what could be causing this problem? The following curl command works fine.
curl -X 'POST'
'https://cafte.easyredmine.com/projects.json?key=0224b4238XXXX'
-H 'accept: application/json'
-H 'X-Redmine-API-Key: 0224b4238XXX'
-H 'Content-Type: application/json'
-d '{
"project": {
"easy_external_id": "external-system-1",
"name": "Blue 2",
"homepage": "blue-7",
"description": "I can’t abide these Jawas. Disgusting creatures.",
"author_id": 0,
"is_planned": true,
"easy_is_easy_template": true,
"easy_currency_code": "EUR"
}
This is the methode code:
def create_project(self, name: str, description="", external_id="", homepage="", parent_id="", author_id="",
is_planned= 'false', is_easy_template= "true", start_date="", due_date="", custom_fields=[],
tag_list=[], currency='EUR'):
print(name)
data = {"project": {
"easy_external_id": external_id,
"name":name,
"homepage": homepage,
"description": description,
"parent_id": parent_id,
"author_id": author_id,
"is_planned": is_planned,
"easy_is_easy_template": is_easy_template,
"easy_start_date": start_date,
"easy_due_date": due_date,
"custom_fields": custom_fields,
"tag_list": tag_list,
"easy_currency_code": currency
}
}
endpoint_path = "/projects"
endpoint = f'{self.base_url}{endpoint_path}'
headers = {'X-Redmine-API-Key': f'{self.api_key}',
'accept': 'application/json',
'Content-Type': 'application/json'
}
r = requests.post(endpoint, headers=headers, json= data)
Hey Stackoverflow fam,
I am working on an API which pulls requests from elastic search tool and displays it.
I am trying to pull data using get request
import requests
import json
payload = {
"query": {
"match": {
"metric": "metric_name"
}
}
}
url = "https://url_name:9200/siren-kinesis*/_search"
payload = json.dumps(payload)
print(type(payload))
headers = {
'Content-Type': 'application/json',
}
result = requests.get(url=url,data=payload,headers=headers,auth=("test#example.com","*"))
print(result.json())
and getting the following error
{
"error": {
"root_cause": [
{
"type": "security_exception",
"reason": "unable to authenticate user [test#example.com] for REST request [/_search]",
"header": {
"WWW-Authenticate": "Basic realm=\"security\" charset=\"UTF-8\""
}
}
],
"type": "security_exception",
"reason": "unable to authenticate user [test#example.com] for REST request [/_search]",
"header": {
"WWW-Authenticate": "Basic realm=\"security\" charset=\"UTF-8\""
}
},
"status": 401
}
I am Basic Auth .i.e. passing username and password for authorization.
Can somebody help me ?
In the case of Basic Auth in any request, if you're requesting via postman you can provide the credentials in the Authentication tab. But In the case of Code/Console/Browser, the certificates must be given in the request URL.
e.g.
https://username:password#URL
https://admin:admin#www.the-internet.herokuapp.com/basic_auth
I have completely write 86 blog posts. I tried to upload it manually but seems like a long process, so I decided to make it by xml file and worked on it but no xml format on web helps me. This is the code I tried with,
<?xml version='1.0' encoding='UTF-8'?>
<ns0:feed xmlns:ns0="http://www.w3.org/2005/Atom">
<ns0:generator>Blogger</ns0:generator>
<ns0:entry>
<ns0:category scheme="http://schemas.google.com/g/2005#kind" term="http://schemas.google.com/blogger/2008/kind#post" />
<ns0:category scheme="http://www.blogger.com/atom/ns#" term="CATEGORY A" />
<ns0:id>BLOGGER TEST</ns0:id>
<ns0:content type="html">Blogger CONTENT</ns0:content>
<ns0:title type="html">BLOGGER TITLE</ns0:title>
</ns0:entry>
</ns0:feed>
If using xml is bad choice then any chance in python or any other coding.
Use the API as in the example below
POST https://www.googleapis.com/blogger/v3/blogs/8070105920543249955/posts/
Authorization: /* OAuth 2.0 token here */
Content-Type: application/json
{
"kind": "blogger#post",
"blog": {
"id": "8070105920543249955"
},
"title": "A new post",
"content": "With <b>exciting</b> content..."
}
See here for more:
https://developers.google.com/blogger/docs/3.0/using#AddingAPost
You can add a post for a blog by sending a POST request to the post-collection URI with a post JSON body:
https://www.googleapis.com/blogger/v3/blogs/YOUR_BLOG_ID/posts/
Request (You must be authenticated to create a post) :
POST https://www.googleapis.com/blogger/v3/blogs/8070105920543249955/posts/
Authorization: /* OAuth 2.0 token here */
Content-Type: application/json
{
"kind": "blogger#post",
"blog": {
"id": "8070105920543249955"
},
"title": "A new post",
"content": "With <b>exciting</b> content..."
}
Response (If your request is successful, you will get an HTTP 200 OK status) :
{
"kind": "blogger#post",
"id": "6819100329896798058",
"blog": {
"id": "8070105920543249955"
},
"published": "2012-05-20T20:08:00-07:00",
"updated": "2012-05-20T20:08:35-07:00",
"url": "http://brettmorgan-test2.blogspot.com/2012/05/new-post.html",
"selfLink": "https://www.googleapis.com/blogger/v3/blogs/8070105920543249955/posts/6819100329896798058",
"title": "A new post",
"content": "With <b>exciting</b> content...",
"author": {
"id": "16258312240222542576",
"displayName": "Brett Morgan",
"url": "http://www.blogger.com/profile/16258312240222542576",
"image": {
"url": "https://resources.blogblog.com/img/b16-rounded.gif"
}
},
"replies": {
"totalItems": "0",
"selfLink": "https://www.googleapis.com/blogger/v3/blogs/8070105920543249955/posts/6819100329896798058/comments"
}
}
For more details please you can read the API doc.
https://developers.google.com/blogger/docs/3.0/using
So, I try to make a program who tell me the schedule of my bus, i take this real time information on an Api:
https://api-lab-trone-stif.opendata.stif.info/service/tr-vianavigo/departures?line_id=100100385%3A385&stop_point_id=StopPoint%3A59%3A6195786
but when i lunch it there is an error :
"error": "Unknown dataset: tr-vianavigo"
I have a token to use I think but how ?
the Curl for this api is :
curl -X GET --header "Accept: application/json" "https://api-lab-trone-
stif.opendata.stif.info/service/tr-vianavigo/departures?
line_id=100100020%3A20&stop_point_id=59%3A4726914"
when i use the first url on my web browser it work and show me :
[
{
"lineDirection": "Juvisy RER",
"code": "duration",
"time": "12"
},
{
"lineDirection": "Savigny Toulouse-Lautrec",
"code": "duration",
"time": "20"
},
{
"lineDirection": "Juvisy RER",
"code": "duration",
"time": "38"
},
{
"lineDirection": "Savigny Toulouse-Lautrec",
"code": "duration",
"time": "45"
}
]
but in python if i just test :
import requests
#my token
apikey = 'ef169369dfd911b01371b73e975ed88adce881bc92dbbd9720551c94'
#url of the api
url ='https://api-lab-trone-stif.opendata.stif.info/service/tr-vianavigo/departures?line_id=100100385%3A385&stop_point_id=StopPoint%3A59%3A6195786'
#requests
r = requests.get(url, apikey)
print(r.text)
it make the error :
"error": "Unknown dataset: tr-vianavigo"
You must use one of your API keys for this purpose. An API key is obtained via your user account in My API keys. Once generated, the key must be inserted as a query parameter (apikey) in the URL of your
call. For your example:
curl -X GET --header "Accept: application/json" "https://api-lab-trone-stif.opendata.stif.info/service/tr-vianavigo/departures?line_id=100100020%3A20&stop_point_id=59%3A4726914&apikey=<YOUR-API-KEY>"
FYI, the scope of the real-time data available on the dataset tr-unitaire-stif is avalaible here.
I am in the process of migrating my Parse push notification data to CleverTap. The problem that I am having is that the documentation is not very good about it and the examples that they give don't cover push notifications.
Anyone have an example of how to send pushes with CleverTap API using Python or at least evidence that this is possible?
The documentation now covers how to migrate your Parse installations to CleverTap. For example, say we are creating a push notification to be sent to users subscribed to the "yankees" and "mets" channels.
curl -H "Content-Type:application/json"
-H "X-CleverTap-Account-ID: Your CleverTap Account ID"
-H "X-CleverTap-Passcode: Your CleverTap Account Passcode"
--data "#payload"
"https://api.clevertap.com/1/targets/create.json"
Payload
"name": "My API Campaign",
"where": {
"common_profile_prop": {
"profile_fields": [
{
"name": "channels",
"value": ["yankees", "mets"]
}
]
}
},
"content":{
"title": "Breaking News",
"body": "Yankees Win 5-4",
"platform_specific": {
"ios": {
"deep_link": "example.com",
"sound_file": "example.caf",
"category": "reactive",
"badge_count": 1,
"key": "value_ios"
},
"android": {
"background_image": "http://example.jpg",
"default_sound": true,
"deep_link": "example.com",
"key": "value_android"
}
}
},
"devices": [
"android",
"ios",
],
"when": "now"
}
Response
{
"status": "success",
"id": 1457433898,
"estimates": {
"android": 90,
"ios": 300
}
}
Hope this helps. More documentation can be found here -
https://github.com/CleverTap/parse-migrate