- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-21-2017 03:03 PM
Hi,
Can someone please advise me on how can i access a REST full API's endpoint? I have to access an endpoint say for example
http://someotherdomain/api/doSomething/1
is there a way that i can do it in a business rule using the REST Client?
Regards
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-23-2017 08:19 AM
Hi John,
You have everything setup properly except for two notes.
1) I had a typo in mine: setHTTPMethod should be setHttpMethod
2) if you are going to use setQueryParameter(), you don't need to set the parameters on the endpoint url. (Anything after a "?" is a parameter)
rm.setEndpoint('http://api.tvmaze.com/search/shows');
rm.setQueryParameter("q", "girls");
Otherwise if you do both the endpoint would end up looking like this http://api.tvmaze.com/search/shows?q=girls?q=girls
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-21-2017 11:48 PM
HI,
You can refer the below thread on your query:
Hope this helps.Mark the answer as correct/helpful based on impact.
Regards,
Shloke
Regards,
Shloke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-04-2019 05:07 AM
Hi, I have the similar problem.
I created a business rule in such a way that when ever there is an update in the incidents table it have to get the updated data to External API
This is When condition
Just Created Action Script for sending incidents data using Rest API.
This is my action script:
(function executeRule(current, previous /*null when async*/) {
var method = 'post';
var endpoint = 'http://192.168.**.**:8010/incidents/api/servicenow';
var r = new sn_ws.RESTMessageV2();
r.setHttpMethod(method);
r.setEndpoint(endpoint);
r.setRequestHeader("Accept","application/json");
r.setRequestHeader('Content-Type','application/json');
r.setBasicAuth("admin", "Password@123");
var body = incident;
r.setRequestBody(body);
r.setStringParameter("data", incident);
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
gs.addInfoMessage("Response Body:" + response);
gs.addInfoMessage("Response status:" + httpStatus);
})(current, previous);
The problem is I am unable to hit this endpoint URL. The code at the ENDPOINT url is
@api_view(['POST'])
def servicenow(request):
if request.method == 'POST':
from ast import literal_eval
d = literal_eval(request.data)
try:
sn = IncidentsServicenow.objects.get(number=d['number'])
sn.number = d['number']
sn.title = d['title']
sn.description = d['description']
sn.state = d['state']
except ServiceNow.DoesNotExist:
sn = ServiceNow()
sn.number = d['number']
sn.title = d['title']
sn.description = d['description']
sn.state = d['state']
sn.save()
# sn = ServiceNowSerializer(data=request.data)
# print (request.data)
# if sn.is_valid():
# sn.save()
return Response({"message": "Got some data!", "data": request.data})
return Response({"message": "Data mismatching"})
ANY HELP PLEASE