We're trying to create ServiceNow KB article using ServiceNow Table API
url = 'https://devXXXX.service-now.com/api/now/table/kb_knowledge'
Currently we're passing html content data (with tags) in ‘text’ field and able to create KB article
[..]
response = requests.post(url, auth=(user, password), headers=headers, data="{\"active\":\"True\",\"valid_to\":\"01-01-2100\",\"short_description\":\"KB Article\",\"text\":\"<h1> Example Article </h1> <p>Testing</p>}")
[..]
Instead of passing the html content in ‘text’ field, we're trying options to read the entire html file or any file content and create KB article in ServiceNow
Any suggestions please..
From the docs section Table - POST /now/table/{tableName} it seems like what you might be looking for is the "data" option - it allows you to put any type of text/XML into the article.
# Example 1 Python XML
response = requests.post(url,
auth=(user, pwd),
headers=headers,
data="""<request><entry>
<short_description>Unable to connect to office wifi</short_description>
<assignment_group>
287ebd7da9fe198100f92cc8d1d2154e
</assignment_group>
<urgency>2</urgency>
<impact>2</impact>
</entry></request>"""
)
# Example 2 CURL - JSON
curl "https://instance.servicenow.com/api/now/table/incident" \
--request POST \
--header "Accept:application/json" \
--header "Content-Type:application/json" \
--data "{'short_description':'Unable to connect to office wifi','assignment_group':'287ebd7da9fe198100f92cc8d1d2154e','urgency':'2','impact':'2'}" \
--user 'username':'password'
If you want to use HTML it seems you'll have to stick with text for that case, as it doesn't seem like they are using "text" option for anything in their Tables API (might be the case that you're using a deprecated API option for that so be careful)
Instead of posting the actual html in the data field, maybe you could just put the URL to actual page, but store the actual page elsewhere.
Related
I want to create a "mock" server using Ratpack/Groovy and we need to read the data-raw from a call
I haven't had a problem reading headers or parameters, but I need to read the body of a request
Examplle:
curl --location --POST request 'http://localhost:5050/authenticate' \
--header 'Content-type: application/json' \
--raw-data '{
"username": "testbase01#domain.com",
"password": "12345678"
}'
we need to parse and process the username and password fields
We have tried to read the request.body, or the body.text, but we have not been successful.
Basically the example found in the solution at https://stackoverflow.com/questions/23636248/parse-json-in-ratpack-groovy would be what we need, but it hasn't worked for us either
Our environment has the following dependencies
#Grab('io.ratpack:ratpack-groovy:1.6.1'),
#Grab('org.slf4j:slf4j-simple:1.7.22'),
#Grab("io.ratpack:ratpack-jackson:0.9.17")
and we are using https://github.com/Vad1mo/hello-world-rest as primary image
If you have a small example, to be able to adapt it to our needs
Both GET and POST methods supported by the endpoint. The POST method is recommended to call endpoint with a huge number of user ids to follow, because the GET method will lead to an oversized URL that the server can't handle. How the "follow" parameter can be passed in the body of the request?
UPD: here is what I've already tried using Insomnia (the URL is always 'https://stream.twitter.com/1.1/statuses/filter.json' and the method is always 'POST' and the server response is always "No filter parameters found. Expect at least one parameter: follow track locations"):
A plain text body with Content-Type: text/html
follow=2731236345
A json body with Content-Type: application/json
{
"follow": "2731236345"
}
Another json body
{
"follow": [
2731236345
]
}
However, when I use form-url-encoded with field "follow" and the value "2731236345" I receive the response "Unauthorized".
First of all, consider looking at the Twitter Developer Labs new endpoint, because this existing API will be retired, likely (but not yet confirmed) in 2020.
When you say "without any success", what libraries are you using, and at what levels of query parameters - you're not being very clear about what is not working here. 5000 user IDs is very large. Can you please be more specific about the errors you're seeing, and the code you're trying to run?
I've managed to connect using curl:
curl --request POST \
--url 'https://stream.twitter.com/1.1/statuses/filter.json' \
--header 'authorization: <censored>' \
--data 'follow=2731236345'
The same request doesn't work in Insomnia for some reason, but it doesn't matter for the goal of this post.
I'm trying to figure out if it's possible to use a single REST request to have Twilio call out to a phone number, and play out a voice message. The content of the voice message will be different each time, so that message would need to be passed as a parameter.
In looking at the Twilio API "Making Calls" doc, I see this curl sample:
$ curl -XPOST https://api.twilio.com/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls.json \
--data-urlencode "Url=http://demo.twilio.com/docs/voice.xml" \
--data-urlencode "To=+14155551212" \
--data-urlencode "From=+14158675309" \
-u 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token'
This specifies a URL for an XML configuration. For dynamic text, is the expectation that I should publish an xml file to a URL before making the REST call, and then provide that URL in the call? Is there a way to provide the XML as POST data to the end point, rather than using a URL?
Thanks in advance.
gmc
Twilio developer evangelist here.
You can't include the XML as POST data I'm afraid. However, we do offer TwiML Bins which you can use to host your XML without getting a server of your own. Recently we added support for templating in TwiML Bins. This means that you can pass URL parameters to a TwiML Bin URL and use those parameters in your response.
So, if you are intending to use speech to text to read out a message with <Say> then you could write the following TwiML as a TwiML Bin:
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Say>{{ Message }}</Say>
</Response>
You'll get a URL that looks like: https://handler.twilio.com/twiml/EHsomerandomcharacters
You can then use that URL in your call creation, with a URL parameter of Message to read a different message each time.
$ curl -XPOST https://api.twilio.com/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls.json \
--data-urlencode "Url=https://handler.twilio.com/twiml/EHsomerandomcharacters?Message=Hello+from+your+TwiML+Bin!" \
--data-urlencode "To=+14155551212" \
--data-urlencode "From=+14158675309" \
-u 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token'
Let me know if that helps at all.
I am using webhooks for the first time with calendly.com. I would like to create a subscription as described here. When I get to doing this
curl --header "X-TOKEN: <your_token>" --data "url=https://blah.foo/bar&events[]=invitee.created" https://calendly.com/api/v1/hooks
I am concerned that the url is not in a valid format. I tried replacing the & with a ? as in here
curl --header "X-TOKEN: <your_token>" --data "url=https://blah.foo/bar?events[]=invitee.created" https://calendly.com/api/v1/hooks
but I receive this error
{"events":{"events":["can't be blank]}}
Likewise, I try to leave the & and everything after it blank and it give the same error as above.
But using a url with the & and everything in it gives a 404 not found error. Can a url even have the format they are saying is required?
But using a url with the & and everything in it gives a 404 not found error.
The URL part in the following is just the https://blah.foo/bar part before the & character.
curl --header "X-TOKEN: <your_token>" --data "url=https://blah.foo/bar&events[]=invitee.created" https://calendly.com/api/v1/hooks
The events[]=invitee.created part is a separate parameter and value. It’s not part of the url.
See the Create A Webhook Subscription page in the calendy docs:
So the URL is the site that runs your webhook; you don’t send the events parameter/value back to that site—instead you’re sending both the url param and events param to the calendly API endpoint at https://calendly.com/api/v1/hooks. The calendly backend presumably then calls to https://mywebsite.com/webhooks/invitee_created or https://blah.foo/bar whatever url you’ve given it—but without the events parameter, which is for calendly’s internal use.
I have a simple question regarding to the usage of cURL. Didn't find much during my Google search or Man page to get a clear answer.
In here talks about using either --data vs --form on sending file/attachment. I'm curious to know what are the main difference and under what scenarios you would pick --data-binary VS --form ?
The POST "body" can be sent via either --data (for application/x-www-form-urlencoded) or --form (for multipart/form-data):
-F "foo=bar" # 'foo' value is 'bar'
-F "foo=<foovalue.txt" # the specified file is sent as plain text input
-F "foo=#foovalue.txt" # the specified file is sent as an attachment
-d "foo=bar"
-d "foo=<foovalue.txt"
-d "foo=#foovalue.txt"
-d "#entirebody.txt" # the specified file is used as the POST body
--data-binary "#binarybody.jpg"
The difference is explained in the HTML 4.01 Specification section on Forms:
application/x-www-form-urlencoded is the default content type.
The content type "application/x-www-form-urlencoded" is inefficient for sending large quantities of binary data or text containing non-ASCII characters. The content type "multipart/form-data" should be used for submitting forms that contain files, non-ASCII data, and binary data.
That's exactly the main difference, type of data that's being sent to the server (application/x-www-form-urlencoded vs multipart/form-data)