Having trouble understanding how npm soap package works - api

I'm using the npm soap package to connect to a SOAP API and call methods, and I'm not grasping how this is supposed to work.
For instance, in the API documentation, it gives this as an example:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://xxx">
<soapenv:Header/>
<soapenv:Body>
<ser:setSessionParameters>
<viewSettings>
<forceLogoutSession>yes</forceLogoutSession>
<rollingPeriod>Minutes30</rollingPeriod>
<shiftStart>21600000</shiftStart>
<statisticsRange>CurrentDay</statisticsRange>
<timeZone>-28800000</timeZone>
<idleTimeOut>1800</idleTimeOut>
</viewSettings>
</ser:setSessionParameters>
</soapenv:Body>
</soapenv:Envelope>
And if I use a REST tool to send this content to the API endpoint, it works as expected.
In my code, if I invoke this method call:
var x = client.describe();
console.log(x.WsSupervisorService.WsSupervisorPort.setSessionParameters);
I get this response:
{
input: {
viewSettings: {
appType: 'xs:string',
forceLogoutSession: 'xs:boolean',
rollingPeriod: 'rollingPeriod|xs:string|Minutes5,Minutes10,Minutes15,Minutes30,Hour1,Hours2,Hours3,Today',
shiftStart: 'xs:int',
statisticsRange: 'statisticsRange|xs:string|RollingHour,CurrentDay,CurrentWeek,CurrentMonth,Lifetime,CurrentShift',
timeZone: 'xs:int',
targetNSAlias: 'tns',
targetNamespace: 'http://xxx'
},
targetNSAlias: 'tns',
targetNamespace: 'http://xxx'
},
output: {
targetNSAlias: 'tns',
targetNamespace: 'http://xxx'
}
}
But this fails:
client.setSessionParameters({
input: {
viewSettings: {
forceLogoutSession: true,
rollingPeriod: 'Minutes30',
shiftStart: 216000000,
statisticsRange: 'CurrentDay',
timeZone: -288000000,
idleTimeOut: 1800
}
}
});
...yielding this error:
{ [Error: env:Client: Endpoint {http://xxx/}WsSupervisorPort does not contain operation meta data for: setSessionParameters] stack: [Getter] }
I'm at a loss here. Any help would be hugely appreciated!

Simply try:
client.setSessionParameters({
viewSettings: {
forceLogoutSession: true,
rollingPeriod: 'Minutes30',
shiftStart: 216000000,
statisticsRange: 'CurrentDay',
timeZone: -288000000,
idleTimeOut: 1800
}
});

Related

mail.send is not accepting HTML/ CSS code

I have copied the (HTML) source code from a received email just to have the template/format of that email, and this is the error message that I am receiveing when running the API:
Internal : Unexpected error Error during Web API HTTP Request
HTTP Status Code: 400
HTTP Response Content: {
"error": {
"code": "BadRequest",
"message": "Unable to read JSON request payload. Please ensure Content-Type header is set and payload is of valid JSON format.",
"innerError": {
"date": "2020-12-02T17:01:05",
"request-id": "3ab50fc1-0c13-4536-96db-bf6b9b7a736d",
"client-request-id": "3ab50fc1-0c13-4536-96db-bf6b9b7a736d"
}
}
}
I have tested basic commands using HTML such as making text bold and line breaks which work, but anything more complex and I will receive an error.
Update**
Thank you for your response guys, the call that I'm using looks like this:
{
"message": {
"subject": "[Subject]",
"body": {
"contentType": "HTML",
"content": "[Email Body Content]"
},
"toRecipients": [
{
"emailAddress": {
"address": "[Email Address]"
}
}
],
"internetMessageHeaders":[
{
"name":"x-custom-header-group-name",
"value":"Nevada"
},
{
"name":"x-custom-header-group-id",
"value":"NV001"
}
]
}
}
**Another update ** Upon changing the content type to text/html is recieved this error:
Internal : Unexpected error Error during Web API HTTP Request
HTTP Status Code: 415
HTTP Response Content: {"error":{"code":"RequestBodyRead","message":"A supported MIME type could not be found that matches the content type of the response. None of the supported type(s) 'Microsoft.OData.ODataMediaType, Microsoft.OData.ODataMediaTyp...' matches the content type 'text/plain; charset=utf-8'."}}
note i also have tried text/plain as the content type.
Thank you
Ok, I tried the above payload (just updated the email address) and tested with Microsoft Graph Explorer. It works for me :)
Here's the payload:
{"message":{"subject":"[Subject]","body":{"contentType":"HTML","content":"[Email Body Content]"},"toRecipients":[{"emailAddress":{"address":"test#domain.onmicrosoft.com"}}],"internetMessageHeaders":[{"name":"x-custom-header-group-name","value":"Nevada"},{"name":"x-custom-header-group-id","value":"NV001"}]}}
Here's the snapshot:

How to add a simple flow rule via OpenDaylight DLUX using the /operations/sal-flow:add-flow api

I am trying to add a simple flow rule via Lithium's DLUX using the /operations/sal-flow:add-flow api call but getting nothing but errors, please can someone help?
Even a preview of a sample flow someone has added would be really helpful?
My current input as displayed in the preview frame is:
http://localhost:8181/restconf/operations/sal-flow:add-flow
{
"add-flow": {
"input": {
"match": {
"ethernet-match": {
"ethernet-type": {
"type": "2048"
}
},
"ipv4-source": "10.0.0.1/32"
},
"instructions": {
"instruction": [
{
"order": "0",
"apply-actions": {
"action": [
{
"drop-action": {},
"order": "0"
}
]
}
}
]
},
"flow-name": "test",
"table_id": "0"
}
}
}
The current error is:
"Server Error : The server encountered an unexpected condition which prevented it from fulfilling the request. - : The operation encountered an unexpected error while"
The same request in Postman gives the error:
{
"errors": {
"error": [
{
"error-type": "protocol",
"error-tag": "malformed-message",
"error-message": "Error parsing input: Schema node with name add-flow wasn't found under (urn:opendaylight:flow:service?revision=2013-08-19)add-flow."
}
]
}
}
I have seen examples using xml but nothing that seems to work. I am able to view the network topology via dlux so I presume I am connected to everything ok.
Many thanks in advance.
Remove the add-flow and the corresponding brackets from the input data. Use things like
{
input: {...},
output: {...}
}
I am having the same problem using DLUX. Anyway I managed to find a solution using XML POST requests from this link https://wiki.opendaylight.org/view/OpenDaylight_OpenFlow_Plugin:End_to_End_Flows. You can use POSTMAN application on Chrome to send requests. The body of the request should be something like:
POST http://localhost:8080/restconf/operations/sal-flow:add-flow
Add authentication header too.
Content-type: application/xml
Accept: application/xml
Body:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<input xmlns="urn:opendaylight:flow:service">
<barrier>false</barrier>
<node xmlns:inv="urn:opendaylight:inventory">/inv:nodes/inv:node[inv:id="openflow:1"]</node>
<cookie>55</cookie>
<flags>SEND_FLOW_REM</flags>
<hard-timeout>0</hard-timeout>
<idle-timeout>0</idle-timeout>
<installHw>false</installHw>
<match>
<ethernet-match>
<ethernet-type>
<type>2048</type>
</ethernet-type>
</ethernet-match>
<ipv4-destination>10.0.10.2/32</ipv4-destination>
</match>
<instructions>
<instruction>
<order>0</order>
<apply-actions>
<action>
<output-action>
<output-node-connector>1</output-node-connector>
</output-action>
<order>0</order>
</action>
</apply-actions>
</instruction>
</instructions>
<priority>0</priority>
<strict>false</strict>
<table_id>0</table_id>
</input>

OSX - AFNetworking sending text even with JSON Serializer set

I have an issue with AFNetworking and AFJSONRequestSerializer. I try to access an API, and the request contains a text/plain header. Here's my code :
class BaseService {
var manager: AFHTTPRequestOperationManager!
init() {
manager = AFHTTPRequestOperationManager()
manager.responseSerializer = AFJSONResponseSerializer()
manager.requestSerializer = AFJSONRequestSerializer(writingOptions: NSJSONWritingOptions.allZeros)
}
}
class UserService: BaseService {
func startNewEntry(name: String) {
let params = [
"time_entry": [
"description": name,
"created_with": "fooBar"
]
]
manager.POST(
"endpoint",
parameters: params,
success: { (operation, response) -> Void in
let json = JSON(response)
println("OK")
println(json)
Context.shared.entries.getFromJSON(json)
}) { (operation, error) -> Void in
println("-- ERROR --")
println(operation)
println(error)
}
}
Do you know this issue ?
No, this code will create a request with a content type of application/json. But I wonder if you perhaps mislead by an error message that said:
Request failed: unacceptable content-type: text/html
If you got that, that's not telling you that that the request had an unacceptable content type, but rather that the request failed because the response was text/html. And this is a very common issue: If server code that is attempting to create a JSON response fails for some reason, sometimes the error message isn't JSON, but rather it's HTML.
I would suggest adding the following inside the failure block of your POST method in order to see what this text/html response was:
if operation.responseData != nil {
println(NSString(data: operation.responseData, encoding: NSUTF8StringEncoding))
}
This way, if you get a text error message from the server (e.g. the request was malformed or what have you), you'll be able to read the HTML response you got back.

POST command to WebCeo API

Trying to connect to this WebCEO API.
function getProjects() {
var payload = {
"key": "CUSTOMER_KEY",
"method": "get_projects"
};
payload = JSON.stringify(payload);
var url = "https://online.webceo.com/api/";
var options = {
"method": 'POST',
"contentType" : "application/json",
"payload": payload
};
var response = UrlFetchApp.fetch(url, options);
}
Receiving "Request failed for https://online.webceo.com/api/ returned code 404".
Any hint on what else I need to include / change?
Body must contain the following:
json={"key": "YOUR_API_KEY", "method": "get_projects"}
Well, https://online.webceo.com/api/ does return a 404 when you just try to access it. Did you manage to get that page to not return a 404 error from another client?
Doing so will probably tell you what you're missing here.
However, I'd suspect their API might be having issues.
That's true, you don't make a GET request. You have to send parameters in the body of a POST request. Below is an example in CURL for a situation when you need to get the list of projects:
curl -X POST -d 'json={"key": "YOUR_API_KEY", "method": "get_projects" }' https://online.webceo.com/api/

how to send jsonp request to server in sencha 2.0

I will get this error Repeatedly
Uncaught SyntaxError: Unexpected token : ajax.php
{"error":"Server Error</b>: Method file_get_contents unable to open request body!"}
Ext.data.JsonP.request({
url: 'http://yaksee.com/facebook/ajax.php',
callbackKey: 'callback',
params: {
format: 'json',
},
success: function(result) {
if (result) {
alert('success');
alert(result);
} else {
Ext.Msg.alert('Error', 'There was an error retrieving the weather.');
}
}
});
}},
You Have to disable the Browser's web security
Then it will be ok
Check out the example which works : http://docs.sencha.com/touch/2.1.1/#!/api/Ext.data.JsonP
I changed it to your URL and it stopped working in this fiddle so it seems like issue with webservice or it requires some more data to make request because it is returning HTTP 200 status but with some custom error message