Sending named variables to SOAP via New-WebServiceProxy in Powershell - powershell

Please forgive any errors in terminology, I am self taught :)
I am using New-WebServiceProxy to interact with a SOAP API.
Everything works when variables are at a single level, as long as they are entered in the correct order they are parsed correctly. However I can't work out how to enter 2nd level variables.
For example once the web service proxy has been set up as $Forms via the WSDL the following SOAP call
<x:Body>
<pri:AddForm>
<pri:apiToken>12345</pri:apiToken>
<pri:FormTemplateID>xyz</pri:FormTemplateID>
<pri:OrganisationID>A1</pri:OrganisationID>
</pri:AddForm>
</x:Body>
Will work as $Forms.AddForm(1234, xyz, A1)
However if some of the variables are within a subheading such as
<x:Body>
<pri:AddForm>
<pri:apiToken>12345</pri:apiToken>
<pri:formRequest>
<pri:FormTemplateID>xyz</pri:FormTemplateID>
<pri:OrganisationID>A1</pri:OrganisationID>
</pri:formRequest>
</pri:AddForm>
</x:Body>
The same command won't work and presents an error "Cannot find an overload for "AddForm" and the argument count: "3".
Is there a way to structure the command so it will recognise the arguments within the subheading?

After a lot of trial and error I've found the following works
$formRequest = [PSCustomObject] #{
FormTemplateID = "xyz"
OrganisationID = "A1"
}
$FVForms.AddForm($apiToken, $FormRequest)

Related

Send log with customDimensions to Application Insights using Powershell

I want to send logs to my Application Insights using PowerShell script and I want it to contain customDimensions value.
I tried something like this:
$client = [Microsoft.ApplicationInsights.TelemetryClient]::new()
$client.InstrumentationKey = "xxxx"
$client.TrackTrace("MY CUSTOM LOG", "Information", #{foo="bar"})
$Client.Flush()
but it gives me an error:
Cannot find an overload for "TrackTrace" and the argument count: "3".
Ideally I want the code above to work so that I can read the log like this:
I know how to do it using Python and opencensus-ext-azure lib but now I also need Powershell as well.

core_user_create_user and moodle webservice setup not working

I have done everything needed to setup webservices on my moodle 3.11 instance, including roles/capabilities/user. However sending a test request always gives {
"exception": "dml_missing_record_exception",
"errorcode": "invalidrecord",
"message": "Can't find data record in database table external_functions."
}
The URL to access it is of the format https:///moodle/webservice/rest/server.php?wsfunction=core_user_create_user&service=mymoodleusermanage&moodlewsrestformat=json&users[0][username]=ABC&users[0][firstname]=VPTest&users[0][lastname]=None&users[0][email]=mail#xxx.com&users[0][password]=xxxxx&users[0][auth]=manual&wstoken=xxxxxxxxxxxxxx
The service parameter is correctly set to the shortname of the service. Does the service have to be defined anywhere additionally apart from Site Administration->Server->Web Services->External Services->Custom Services
Thanks for any help that can be given
The answer is very simple - you are trying to call a non-existent webservice function (hence the error message about being unable to find the database record for the function in the external_functions database table).
If you look in the Moodle code: https://github.com/moodle/moodle/blob/master/lib/db/services.php#L1717 you will see that the function is called core_user_create_users - with an "s" at the end of it.
If you add that extra "s" into the URL parameters you are using, then it should work.
https:///moodle/webservice/rest/server.php?wsfunction=core_user_create_user&service=mymoodleusermanage&moodlewsrestformat=json&users[0][username]=ABC&users[0][firstname]=VPTest&users[0][lastname]=None&users[0][email]=mail#xxx.com&users[0][password]=xxxxx&users[0][auth]=manual&wstoken=xxxxxxxxxxxxxx
you must change username all character small letter [username]=ABC like this [username]=abc and add s wsfunction=core_user_create_users

AllowGuestsSignIn parameter in New-AzureADApplication

Trying to use New-AzureADApplication with the parameter AllowGuestsSignIn which is of type [Nullable[boolean]]
If I don't set any value, I get:
Missing an argument for parameter 'AllowGuestsSignIn'. Specify a
parameter of type 'System.Nullable`1[System.Boolean]' and try again.
If I pass $true or $false, I get Bad Request:
New-AzureADApplication : Error occurred while executing NewApplication
Code: Request_BadRequest Message: One or more property values
specified are invalid.
I also tried using the specific type in a variable: [Nullable[boolean]]$MyBool
and using 1/0 using true/false as strings, nothing works
Anyone has any idea how to pass this parameter?
By the way, this works fine https://www.exospheredata.com/2017/01/27/how-to-pass-null-to-a-boolean-parameter-in-powershell/
I can reproduce your issue, what you are using is AzureADPreview powershell module, it is a preview persion, I believe the feature of the parameter -AllowGuestsSignIn has not been implemented yet.
The command New-AzureADApplication calls the Azure AD Graph API, if you catch the request of the command e.g. New-AzureADApplication -DisplayName joytest123 -AllowGuestsSignIn $true, you will find it uses the allowGuestsSignIn in the request body.
But if you look into the Application Entity of AAD Graph, you will find there is no such property supports the POST method(also PATCH, the -AllowGuestsSignIn also not work for Set-AzureADApplication).

how to get dictionary value from webrequest using sharepoint designer

I am trying to retrieve a value from a HTTP web service call in sharepoint designer. This should be simple. the Rest query is simple, and always returns only a single value:
https://Site.sharepoint.com/sites/aSiteName/_api/web/lists/getByTitle('MyListTitle')/items/?$select=Title&$top=1
In the Sharepoint Designer workflow, I'm setting the required Accept and Content-type header to the value of "application/json;odata=verbose
I am unable to get the value of the "Title" field that is returned by the call.
when I execute the REST query in the browser, I get the following data returned:
{"d":{"results":[{"__metadata":{"id":"af9697fe-9340-4bb5-9c75-e43e1fe20d30","uri":"https://site.sharepoint.com/sites/aSiteName/_api/Web/Lists(guid'6228d484-4250-455c-904d-6b7096fee573')/Items(5)","etag":"\"1\"","type":"SP.Data.MyListName"},"Title":"John Doe"}]}}
I've tried dozens of variations of the dictionary 'query', but they always return blank.
I'm using the 'get an item from a dictionary' action in SP Designer, using item name or path values like:
d/results(0)/Title
d/Title
d/results/Title
and literally dozens of other variations - but it always returns blank.
I'm writing the raw response from the webRequest to the list for debugging, and it shows the value like this:
{"odata.metadata":"https:\/\/site.sharepoint.com\/sites\/aSiteName\/_api\/$metadata#SP.ListData.MyListTitle&$select=Title","value":[{"odata.type":"SP.Data.MyListTitle","odata.id":"616ed0ed-ef1d-405b-8ea5-2682d9662b0a","odata.etag":"\"1\"","odata.editLink":"Web\/Lists(guid'6228d484-4250-455c-904d-6b7096fee573')\/Items(5)","Title":"John Doe"}]}
I must be doing something simple that is wrong?
Using "d/results(0)/Title" is right. Check the steps in article below to create a workflow.
CALLING THE SHAREPOINT 2013 REST API FROM A SHAREPOINT DESIGNER WORKFLOW
It working fine in my test workflow.
I faced the exact same issue. In my case the reason was that in the API call, the header was not set properly.
As you would have noticed many times, that if you type the variables inline when creating the "Call Http Web service" action, those might not get set properly. The surest way is to open the properties and set from there. In my case when i opened the properties i found that RequestHeaders was not set. Once i set it from there, i got the desired results.
Hope this helps to someone in future, this question being unanswered till now!!
tried dump those json called from sharepoint workflow into a list. Sometimes you'll get a different format than when you called that from browser. I experienced this issue when calling API projectserver (project online). When I called it using servistate (chrome extension) it returns d/results, but when I dump the value into the list I got value and yet I used same request header value.

Invalid_request_parameter (create and sending envelopes)

I'm trying to use a service of DocuSign API in an abap project. I want to send a document to a specific email so it can be signed. But im getting the following error:
"errorCode": "INVALID_REQUEST_PARAMETER",## "message": "The request contained at least one invalid parameter. Query parameter 'from_date' must be set to a valid DateTime, or 'envelope_ids' or 'transaction_ids' must be specified.
I tried the following:
CALL METHOD cl_http_client=>create_by_url
EXPORTING
url = l_url (https://demo.docusign.net/restapi/v2/accounts/XXXXXX')
proxy_host = co_proxy_host
proxy_service = co_proxy_service
IMPORTING
client = lo_http_client
lo_http_client->request->set_method( method = 'POST').
CALL METHOD lo_http_client->request->set_header_field
EXPORTING
name = 'Accept'
value = 'application/json'.
CALL METHOD lo_http_client->request->set_header_field
EXPORTING
name = 'X-DocuSign-Authentication'
value = get_auth_header( ). (json auth header)
CALL METHOD lo_http_client->request->set_cdata
EXPORTING
data = create_body( ).
This is my body:
CONCATENATE
`{`
`"emailSubject": "DocuSign REST API Quickstart Sample",`
`"emailBlurb": "Shows how to create and send an envelope from a document.",`
`"recipients": {`
`"signers": [{`
`"email": "test#email",`
`"name": "test",`
`"recipientId": "1",`
`"routingOrder": "1"`
`}]`
`},`
`"documents": [{`
`"documentId": "1",`
`"name": "test.pdf",`
`"documentBase64":` `"` l_encoded_doc `"`
`}],`
`"status": "sent"`
`}` INTO re_data.
The api request to get the Baseurl is working fine. (I know the error is quite specific what the problem is, but i cant find any sources on the docusign api documentation that one of the mentioned parameters should be added to the request)
Thank you in regards
The error message seems to indicate that you're Posting to an endpoint that requires certain query string parameters -- but you're not specifying them as expected in the query string. I'd suggest you check the DocuSign API documentation for the operation you are using, to determine what query string parameters it requires, and then ensure that you're including those parameters in your request URL.
If you can't figure this out using the documentation, then I'd suggest that you update your post to clarify exactly what URL (endpoint) you are using for the request, including any querystring parameters you're specifying in the URL. You can put fake values for things like Account ID, of course -- we just need to see the endpoint you are calling, and what qs params you're sending.
To create an envelope, use
https://demo.docusign.net/restapi/v2/accounts/XXXXXX/envelopes
instead of
https://demo.docusign.net/restapi/v2/accounts/XXXXXX
Thank you for all the answers, i found the mistake. Creating the request wasn´t the problem. I was using the wrong "sending"-method -_-.
now its working :)
lo_rest_client->post( EXPORTING io_entity = lo_request_entity ).