Powershell API web service calls - web-services

So first of all I am fairly new to PowerShell (within the last year) I understand a lot of it now, however now API calls are new to me.
I have figure out how to make API calls with web calls that do not require any values. Or ones that don't require an array of values. Such as: $BSSPrincipalManagementWSP.ReadAccount("1_V4-0119341")
Returns everything I want. But If I get into something fancy like the web call for $BSSPrincipalManagementWSP.UpdateAccountValues the first variable is the account external ID, but the second variable required is the accountValues, in an array.
I have tried something like this to accomplish it:
function Update-AccountValues
(
[string]$accountExternalId,
[array]$accountValues = #(Import-Csv -Path $ImportPath)
)
{
$accountValues
$BSSPrincipalManagementWSP.UpdateAccountValues($accountExternalId, $accountValues)
}
Update-AccountValues "1_V4-0119341"
But I get the following error:
Cannot convert argument "accountValues", with value: "System.Object[]", for "UpdateAccountValues" to type "BSSPrincipalManagementNS.AccountValue[]": "Cannot convert value
"#{Key=ScreenSaverTimeoutMinutes; Value=60}" to type "BSSPrincipalManagementNS.AccountValue". Error: "Cannot convert the "#{Key=ScreenSaverTimeoutMinutes; Value=60}" value of type
"System.Management.Automation.PSCustomObject" to type "BSSPrincipalManagementNS.AccountValue".""
At C:\Users\Matt Bergeron\AppData\Local\Temp\ff88f967-9d7c-4f6f-a424-212298a69655.ps1:61 char:2
+ $BSSPrincipalManagementWSP.UpdateAccountValues($accountExternalId, $accountValu ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodException
+ FullyQualifiedErrorId : MethodArgumentConversionInvalidCastArgument
I thought I was passing it "an array of accountValue objects" as it asked for.
All that is in the CSV file is 2 columns, 1 listed as Keys and the other listed as Values. These are named exactly as the OSS/BSS CHM file called them.
Can anyone else tell where I went wrong? Any help would be much appreciated.

You API is expecting the value to be of a specific type BSSPrincipalManagementNS.AccountValue[]. You need to find another API call where you can create instances of BSSPrincipalManagementNS.AccountValue and put them in an array. Then call the original API with that array.

Related

Im trying to convert a wxVector<m_Product*> element to a wxArrayString without any result (Exception thrown at...)

The thing is, im trying to transform the data of a class that is the name of the products. That name is into a std::string format and it should be easy to just make a simple for to put it in a wxArrayString right? but the thing is that the vector where is stored the information its like "corrupted" or "private" i'd like to say.
By the way i tried this function made by me:
BUT i do get this message when i try to use that function
ERROR:
Any idea why is this happening? i mean in the previous line i used de m_GlobalProductVector to print its size to the console...

Error invalid use of void expression. Trying to pass a parameter through to the function

I am trying to initialize a server to look as specific inputs based on the request it gets. there are a lot of them so I want to initialize it with a loop as follows:
void serverInit() {
for (int i = 1; i <= qty; i++) {
String s = "/readBatt" + i;
server.on(s, runTest(i));
}
server.begin();
Serial.println("Server started.");
}
It's telling me that server.on(s, runTest(i)); is an invalid use of void expression. I know it wants it formatted as server.on(s, runTest) but the function runTest(int n) takes a parameter. How can i pass this parameter through to the function?
It seems you are using the WebServer class from the ESP32 Arduino libraries. As you have gleaned already, the callback specified in the on() method does not accept any arguments.
You have an alternative, however. You can specify a 'placeholder' in the URL path - using curly brackets - {}. In the callback, then, the corresponding argument can be retrieved by using the pathArg() method - which accepts the argument index as parameter.
Example ...
You could define your API endpoint as /readBatt/<battery number>. To configure the server to handle requests to this endpoint, then, you would use something like
#include <uri/UriBraces.h>
server.on(UriBraces("/readBatt/{}"), runTest);
In your callback, you would retrieve the first argument as follows ...
static void runTest() {
String batteryNumber = server.pathArg(0);
Serial.println("Request to read battery");
String response = "You attempted to read battery " + batteryNumber;
response += ".\nThis endpoint is a placeholder. Check again soon!";
server.send(200, "text/plain", response);
}
Finally ... Suppose your ESP8266 was running on local IP address 192.168.1.9. You could access your new API endpoint by opening
http://192.168.1.9/readBatt/1
in your browser. (Replace 1 with the relevant battery number.)
I don't think there are versions of the pathArg() which return an integer, unfortunately, so you may have to perform a conversion at some point.
You can use what's called a "closure". A closure lets you compose a function which retains access to variables outside of its scope.
A closure is written using a "lambda expression" - basically an anonymous function. C++'s syntax for lambda expressions looks like this:
[capture variable list](argument list) { body}
The capture variable list is a list of variables you want to be made available inside the body. The argument list is the normal function argument list that would get passed in by the caller. You'd write the lambda expression you need like this:
[i]() { runTest(i); }
and use it like this:
server.on(s, [i]() { runTest(i); });
To be clear, #David Collins' answer is the better way to write the web server. Using a parameter in the URL is better than creating several URLs with the parameter embedded in them. I'm just answering the question of how to pass a parameter to a function that gets called without arguments. If you write the web server code the better way, you won't need to do this (although I would do a bounds check on the value passed in the URL to make sure you're getting a valid battery number).

Progress 4GL REST webservice getting an error

USING OpenEdge.Net.HTTP.*.
USING OpenEdge.Net.URI.
USING Progress.Json.ObjectModel.JsonObject.
DEFINE VARIABLE oClient AS IHTTPClient NO-UNDO.
i am getting an error
Multiple markers at this line - Could not understand line 8. (196) -
Invalid datatype specified: IHTTPClient. Specify a datatype such as
'character' or the name of a class. (5638)"
The REST client isn't really provided out of the box so you need to make sure you have it in your PROPATH.
Depending on your enviroment you might need to change it in a ini-file via PROTOOLS or programatically:
PROPATH = PROPATH + ",C:\Progressx86\OpenEdge\gui\netlib\OpenEdge.Net.pl".
Make sure to change the actual PATH to something that matches your installation. Also the "gui" part should be changed to tty if you're running a character client.
Helpful knowledgebase entry

How to convert object type between two webservice instances in Powershell?

I'm programming with Powershell for SSRS webserivce.
I have two SSRS site, I want to use GetSubscriptionProperties method to get subscription info, then copy it to another site using CreateSubscription.
$SSRS0 = New-WebServiceProxy -Uri $Uri0 -UseDefaultCredential;
$SSRS1 = New-WebServiceProxy -Uri $Uri1 -UseDefaultCredential;
.....
$SSRS0.GetSubscriptionProperties($subscription.SubscriptionID, [ref]$extSettings, [ref]$desc, [ref]$active, [ref]$status, [ref]$eventType, [ref]$matchData, [ref]$values);
$SSRS1.CreateSubscription($URL, $extSettings, $desc, $eventType, $matchData, $values);
Then I got the error:
Cannot convert argument "ExtensionSettings", with value: "Microsoft.PowerShell.Commands.NewWebserviceProxy.AutogeneratedTypes.WebServiceProxy1er_ReportService20
10_asmx_WSDL.ExtensionSettings", for "CreateSubscription" to type "Microsoft.PowerShell.Commands.NewWebserviceProxy.AutogeneratedTypes.WebServiceProxy5er_Report
Service2010_asmx_WSDL.ExtensionSettings": "Cannot convert the "Microsoft.PowerShell.Commands.NewWebserviceProxy.AutogeneratedTypes.WebServiceProxy1er_ReportServ
ice2010_asmx_WSDL.ExtensionSettings" value of type "Microsoft.PowerShell.Commands.NewWebserviceProxy.AutogeneratedTypes.WebServiceProxy1er_ReportService2010_asm
x_WSDL.ExtensionSettings" to type "Microsoft.PowerShell.Commands.NewWebserviceProxy.AutogeneratedTypes.WebServiceProxy5er_ReportService2010_asmx_WSDL.ExtensionS
ettings"."
It's trying to convert the type from site A webservice type to site B webservice type, in fact, it's the same type, but create by two New-WebServiceProxy statements.
How can I convert it without copying all members manually?
I've tried these ways from Internet, but no help:
Use -as operator to convert, $null returns.
Use -namespace in both two New-WebServiceProxy, only one proxy works, another corrupted.
Thanks

JToolBarHelper :: DeleteList - Does not work

I created a Joomla 2.5 custom component and load data to grid on administrator side. All data loaded and adding and editing work well. But deleting is not working. It gives following error.
Fatal error: Call to a member function delete() on a non-object in
C:\wamp\www\Joomla\libraries\joomla\application\component\controlleradmin.php on line 131
In view class I used JToolBarHelper for delete action as follows.
JToolBarHelper::deleteList('', 'regions.delete', 'JTOOLBAR_DELETE');
I had this problem myself, and I've just figured it out. Look into your file corresponding to admin/controllers/helloworlds.php, there should be this line:
public function getModel($name = 'HelloWorld', $prefix = 'HelloWorldModel')
The first param's default value is the name of a single item (in your case, probably Region) and the second one contains the name of the component. So it should be:
public function getModel($name = 'Region', $prefix = 'NameOfYourComponentModel')
I hope this helps also in your case. In the HelloWorld example, they use HelloWorld all over the code, both as the name of the component and the main view, so it's sometimes hard to distinguish which one is what.