Create Category using moodle api call from postman error - postman

I am trying to create a category in moodle making api call from postman
API Endpoint: http://localhost/MyMoodle/webservice/rest/server.php
Method: POST
Payload: Selected x-www-form-urlencoded
wstoken:<token>
wsfunction:core_course_create_categories
moodlewsrestfomat:json
categories[0][name]:Custom Cat 1
categories[0][parent]:0
categories[0][idnumber]:1
categories[0][description]:CustomCatdescription
getting below error
<?xml version="1.0" encoding="UTF-8" ?>
<EXCEPTION class="invalid_parameter_exception">
<ERRORCODE>invalidparameter</ERRORCODE>
<MESSAGE>Invalid parameter value detected</MESSAGE>
</EXCEPTION>

Based on the error and the test parameters, I'd guess it's one of these issues:
Postman isn't encoding the spaces, and Moodle doesn't like that. Try replacing the spaces in your category name with %20
The idnumber is not unique. Check that a category with that idnumber doesn't already exist.
Also, I just wanted to note that you can also test the Moodle API directly in your browser. This can be a good way to make sure there's not an issue with any of your credentials or permissions. Just navigate to a url like this:
http://localhost/MyMoodle/webservice/rest/server.php?moodlewsrestformat=json&wstoken=<token>&wsfunction=core_course_create_categories&categories[0][name]=Custom%20Cat%201&categories[0][parent]=0&categories[0][idnumber]=1&categories[0][description]=CustomCatdescription

Related

Amazon sp-api incorrect URL encoding / decoding characters while updating quantity

I have an issue when including the special characters such as "#" in Amazon Listing API. For example, the sku, HP-2DP98AA#ABC-200621 will be updating the quantity at 20. However, Amazon API responses InvalidSignature
I did apply the encoding for the SKU before submitting the request to Amazon, but it is failed all the time. Any idea?
the AWS documents selling-partner-api-docs Rest API about how to patch the items URL is PATCH /listings/2020-09-01/items/{sellerId}/{sku}. This means that sku need to add in URL which contains "#" like this.
/listings/2020-09-01/items/{your sellerId}/HP-2DP98AA#ABC-200621
This request URL would be cause the exception or InvalidSignature from AWS , because "#" in URL need to encode "#" to "%23" such as below:
/listings/2020-09-01/items/{your sellerId}/HP-2DP98AA%23ABC-200621
Also, need to add sellerId, marketplaceIds, and sku parameters as well.
Additionally, AWS4 Canonical Request is like below:
AWS4 Canonical Request: '"PATCH
/listings/2020-09-01/items/{your sellerId}/HP-2DP98AA%2523ABC-200621
marketplaceIds={your marketplaceIds}&sellerId={your sellerId}&sku=HP-2DP98AA%23ABC-200621
content-type:application/json; charset=utf-8
host:sellingpartnerapi-na.amazon.com
x-amz-access-token:Atza|...
x-amz-date:20210831T190152Z
x-amz-security-token:Fwo...
content-type;host;x-amz-access-token;x-amz-date;x-amz-security-token
d1809d68......"

Invoking a BPMN REST Endpoint in WSO2BPS and get payloads in to format xml

I want to use BPMN Service Task and invoke a REST API.
I need to receive requests from the service ESB in format XML.
Example of request:
<?xml version="1.0" encoding="utf-8"?>
<reqSendEvent extrSystem="rout" typeEvent="newRout" xmlns="http://magnit.ru/tanderCoreMassageData.xsd">
<originTime>2017.08.25 15:12:00</originTime>
<content>
<rout>
<name>xxxxx</name>
</rout>
</content>
</reqSendEvent>
servicetask:
<serviceTask id="servicetask1" name="Service Task" activiti:class="org.wso2.developerstudio.bpmn.extensions.restTask.RESTTask">
<extensionElements>
<activiti:field name="serviceURL">
<activiti:expression><![CDATA[http://localhost:9773/tanderBPMN/services/servicetask1]]></activiti:expression>
</activiti:field>
<activiti:field name="method">
<activiti:string><![CDATA[POST]]></activiti:string>
</activiti:field>
<activiti:field name="headers">
<activiti:expression><![CDATA[Content-Type:text/xml]]></activiti:expression>
</activiti:field>
<activiti:field name="outputMappings">
<activiti:string><![CDATA[xxxxxx]]></activiti:string>
</activiti:field>
</extensionElements>
</serviceTask>
In all the examples, using JSON payloads. What do i write expression in to the outputMappings to get value from tag *//rout/name?
You should be able to use a simple String to hold the POST payload and map the parameter to the String.
Have you tried this?
Greg

How to get WSDL by request to Siebel Inbound WebService?

Usually Web-services return WSDL by request like this:
http://web_server_host.com/WS_virtual_folder/?wsdl
I've created Siebel Inbound WS.
URL of my WS looks like this:
http://web_server_host/eai_enu/start.swe?SWEExtSource=WebService&SWEExtCmd=Execute&UserName=SADMIN&Password=passwrd
There is a possibility to generate WSDL in the Siebel UI by clicking the button "Generate WSDL".
I tried to make my WS to return WSDL: I added one more parameter &wsdl to URL of my WS.
It doesn't work:
When I request URL by web-browser (only URL is sending, there is no soap-message) - I get error like this:
<SOAP-ENV:Envelope>
<SOAP-ENV:Body>
<SOAP-ENV:Fault>
<faultcode>SOAP-ENV:Client</faultcode>
<faultstring>Supplied input is not well formed or does not contain the expected data.(SBL-EAI-00137)</faultstring>
<detail>
<siebelf:siebdetail>
<siebelf:logfilename>EAIObjMgr_enu_0026_27262989.log</siebelf:logfilename>
<siebelf:errorstack>
<siebelf:error>
<siebelf:errorcode>SBL-EAI-00137</siebelf:errorcode>
<siebelf:errorsymbol>IDS_EAI_WS_BAD_XML_DOCUMENT</siebelf:errorsymbol>
<siebelf:errormsg>Supplied input is not well formed or does not contain the expected data.(SBL-EAI-00137)</siebelf:errormsg>
</siebelf:error>
<siebelf:error>
<siebelf:errorcode>SBL-EAI-00246</siebelf:errorcode>
<siebelf:errorsymbol>IDS_XMLCNV_ERR_EMPTYMSG</siebelf:errorsymbol>
<siebelf:errormsg>XML Hierarchy Converter error - empty input message, expecting an XML document in <Value> of input arguments(SBL-EAI-00246)</siebelf:errormsg>
</siebelf:error>
</siebelf:errorstack>
</siebelf:siebdetail>
</detail>
</SOAP-ENV:Fault>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
This response (error) is the same for both URL (with or without parameter &wsdl)
When I request URL by SoapUI (soap-message is sending) - I get again same response for both URL (with or without parametr &wsdl)
Is there such possibility: to get WSLD from Siebel Inbound WS by requesting URL?
I haven't found any mentions about it in the bookshelf.
Thanks in advance.
Sergey
Siebel WSDLs cannot be generated from URLs like an Axis service. The onlyway is to login to the application and click on the Generate WSDL button in the Webservices screen.

How to enter credentials (Authorize object) in a web service call?

I followed the advice provided here and it worked like a charm. Right now, I'm connecting to the server and calling a method named GetFunctionalityTest. The only input to it is a string, which can be seen in the GetFunctionalityTest.m file. So far so good.
Then I attempted to call the real service named GetSections whose signature according to the file GetSections.m is as follows.
function GetSectionsResult = GetSections(obj,auth)
% GetSections(obj,auth)
% Input: auth = (Authorize)
% Output: GetSectionsResult = (ArrayOfString)
values = { auth, };
names = { 'auth', };
types = { '{WSPro.HostingWebservice}Authorize', };
soapMessage = createSoapMessage( ...
'WSPro.HostingWebservice', ...
'GetSections', values,names,types,'document');
response = callSoapService( obj.endpoint, ...
'WSPro.HostingWebservice/GetSections', soapMessage);
GetSectionsResult = parseSoapResponse(response);
The definition provided by the server is as follows.
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi=...>
<soap:Body>
<GetSections xmlns="WSPro.HostingWebservice">
<auth>
<uid>string</uid>
<pw>string</pw>
</auth>
</GetSections>
</soap:Body>
</soap:Envelope>
My problem is that I can't specify the authorization syntax-wise. As far I understand, it's supposed to consist of two strings somehow but I haven't get it to work. I've tried to compound those as follows.
myAuthorization = ['user', 'pass'];
myAuthorization = {'user', 'pass'};
myAuthorization = ['user' 'pass'];
myAuthorization = {'user' 'pass'};
Nothing helped. I just got a bunch of errors.
Error using callSoapService (line 147)
Unspecified Fault: SOAP Fault: Server was unable to process request.
---> The parameterized query
'(#uid nvarchar(99)) SELECT PassW FROM UserData WHERE UserId = #' expects the parameter '#uid', which was not supplied.
I've browsed all the files automatically created for me and there's no definition of Authorize not ArrayOfString. I'm guessing it's something that the server defines, since I get no hits on those in MatLab documentation.
How can I specify the credentials for authorization?
Where can I look up how MatLab maps Authorization?
As noted above:
The SOAP Authentication happens through SOAP Header and not SOAP Body.This link might give you an idea of how SOAP XML should look in case of authentication :
Web service soap header authentication

Unable to set headers in apex web service callouts in salesforce

I'm currently trying to call Amazon Product Retail Web Service in Salesforce.
As I mentioned in
Getting WSDL parse error while generating Apex code from WSDL in Salesforce
I was initially unable to generate apex stub class, but I followed the method suggested by #Ballinger and created apex class. I wrote an apex class to use that stub and to set request parameters. The class i wrote is as follows
public class AmazonProductStubNew
{
public static void getResults()
{
System.Debug(' getResults start ');
AmazonWS.AWSECommerceServicePortUS stub = new AmazonWS.AWSECommerceServicePortUS();
stub.inputHttpHeaders_x = new Map<String,String>();
stub.inputHttpHeaders_x.put('AWSAccessKeyId','MyAmazonAWSAccessKeyId');
stub.inputHttpHeaders_x.put('Timestamp','2012-11-28T12:11:30Z');
stub.inputHttpHeaders_x.put('Signature','Encrypted Secret Code');
String MarketplaceDomain = '';
String AWSAccessKeyId = 'MyAmazonAWSAccessKeyId';
String AssociateTag = '';
String XMLEscaping = '';
String Validate = '';
AmazonWS.ItemSearchRequest Shared = new AmazonWS.ItemSearchRequest();
Shared.SearchIndex = 'DVD';
AmazonWS.ItemSearchRequest[] Request = new AmazonWS.ItemSearchRequest[1];
Request[0] = new AmazonWS.ItemSearchRequest();
Request[0].Title = 'Inception';
AmazonWS.ItemSearchResponse_element response = stub.ItemSearch(MarketplaceDomain,AWSAccessKeyId,AssociateTag,XMLEscaping,Validate,Shared,Request);
AmazonWS.Items_element[] localItems = response.Items;
System.Debug(localItems[0].TotalResults);
}
}
Even though I've added HTTP headers to stub, I'm not getting it in XML Request message
XML Request is as follows
<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<env:Header />
<env:Body>
<ItemSearch xmlns="http://webservices.amazon.com/AWSECommerceService/2011-08-01">
<MarketplaceDomain>
</MarketplaceDomain>
<AWSAccessKeyId>MyAWSAccessKeyId</AWSAccessKeyId>
<AssociateTag></AssociateTag>
<XMLEscaping></XMLEscaping>
<Validate></Validate>
<Shared><SearchIndex>DVD</SearchIndex></Shared>
<Request><Title>Inception</Title>
</Request></ItemSearch>
</env:Body></env:Envelope>
Since headers are not there in SOAP Request, There is a SOAP fault asking for Signature from Amazon Server.
As you can see, I'm new to Salesforce Apex. I followed the steps in
http://www.salesforce.com/us/developer/docs/apexcode/index_Left.htm#StartTopic=Content/apex_web_services_wsdl2apex.htm#http_header_support
to set the headers.
Any idea on why the header isn't getting added?
P.S I added headers manually and tried in SOAP UI, I'm getting proper response.
Thanks :)
I think you're using wrong functions :) (question is indeed confusing).
SOAP (or generally HTTP) communication consists of sending headers and actual message (payload if you like). Headers are short text thingies, message is often a giant XML.
Your code is setting HTTP headers (which are used in web communication to authenticate, provide info about your browser, preferred languages, set cookies, return status codes like 404 page not found...) Please don't be offended with the "for dummies" but I realize the wikipedia article is a bit too much, this might be simpler: http://net.tutsplus.com/tutorials/other/http-headers-for-dummies/
And what I suspect Amazon's webservice wants is just some fields inside the <env:Header>...</env:Header> tag? Just check the generated apex code for existence of subclass called "Header" (you can also search for the variable names like "Signature". This is going to be a total wild guess but I think you'll have to write something like that:
AmazonWS.AWSECommerceServicePortUS stub = new AmazonWS.AWSECommerceServicePortUS();
AmazonWS.Header h = new AmazonWS.Header();
h.AWSAccessKeyId = 'MyAmazonAWSAccessKeyId';
h.Timestamp = '2012-11-28T12:11:30Z';
h.Signature = 'Encrypted Secret Code';
stub.Header = h; // plug it into the request
// create and plug other required tags
AmazonWS.ItemSearchRequest Shared = new AmazonWS.ItemSearchRequest();
Shared.SearchIndex = 'DVD';
AmazonWS.ItemSearchRequest[] Request = new AmazonWS.ItemSearchRequest[1];
Request[0] = new AmazonWS.ItemSearchRequest();
Request[0].Title = 'Inception';
// ...
Now, to make it more confusing you might still have to use a HTTP header, there's a special one called SOAPAction. But generally speaking I believe you're after placing your data in the XML, not in http headers.
Funny enough, I've downloaded the Java example from http://aws.amazon.com/code/Product-Advertising-API/2478 and if I read it correctly they're passing the signature in the URL (endpoint), not in the XML. Probably because it's a REST GET method (if you can access that API it could save you a lot of hair pulled, SOAP is clunky).