How to send form data to an API - Windev 24 - forms

I'm trying to build a simple application on Windev24 and I can't find the right code to send data with a post method to an API I built with Lumen framework. If I test the API via Postman, everything works fine. Here a screenshot of Postman window:
I tried this code:
//MaReq est un restRequête
LaRéponse est un restRéponse
MaReq.URL="https://mywonderfulapi.ch/record"
//I need to find the way to join parameters here...
MaReq.Méthode=httpPost
LaRéponse=RESTEnvoie(MaReq)
SI ErreurDétectée ALORS
Erreur(HErreurInfo(hErrComplet))
SINON
info(LaRéponse.Contenu)
Info(UTF8VersChaîne(LaRéponse.Contenu))
rep = JSONVersVariant(LaRéponse.Contenu)
info(rep)
FIN
I can correctly connect to the API (I get the error message I created in case falses parameters were added to the request), but as I can't find the right way to join the needed parameters, I'm at a stop.
I tried to read the documentation and I tried to figure it out by myself but I couldn't find the way to do that.
Could anyone here help me, please?
Thank you in advance

It's Pretty simple you have to specifiy the type of content you want to send to the server by using MaReq.ContentType = {YourContentType}, then the content by using MaReq.content = {YourContent}, so your code should look like this :
//MaReq est un restRequête
LaRéponse est un restRéponse
MaReq.URL="https://mywonderfulapi.ch/record"
MaReq.ContentType = //yourContentType
MaReq.Content = // YourContent
MaReq.Méthode=httpPost
LaRéponse=RESTEnvoie(MaReq)
SI ErreurDétectée ALORS
Erreur(HErreurInfo(hErrComplet))
SINON
info(LaRéponse.Contenu)
Info(UTF8VersChaîne(LaRéponse.Contenu))
rep = JSONVersVariant(LaRéponse.Contenu)
info(rep)
FIN

Related

POST request using Power Query

I'm trying to collect data from the major electronic components distributors using their API with Power Query.
I was able to do it easily with ARROW and FARNELL as they use a GET request but now I'm trying to do the same thing with MOUSER but it's a POST request.
Here's the code I've written so far but it's not working :
edit
Can someone please help me and tell me what's wrong ?
The API documentation is here:
https://api.mouser.com/api/docs/ui/index#/SearchApi/SearchApi_SearchByPartNumber
Thanks for your help !
edit
My first attempt was really awful, I've made a few changes but it's still not working:
let
url = "https://api.mouser.com/api/v1.0/search/partnumber?apiKey=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
body = Json.FromValue({[SearchByPartRequest = ""], [mouserPartNumber = "LL4148"], [partSearchOptions = "3"]}),
Source = Json.Document(Web.Contents(url, [Headers=[#"Content-
Type"="application/json"], Content = body]))
in
Source
edit
I get the following error:
error message (from Power Query or the API ?)
The answer you're looking for is in the Web.Contents() function.
You can read more information here, here, and here.

Updating Sharepoint metadata using REST api gives 400 bad request error

I am trying to update a Sharepoint file's metadata using the Indy TidHTTP component in my Delphi program.
Within this program I have successfully managed to do everything else I need to do with the Sharepoint files (create/rename/delete/edit/Checkout etc). But whenever I try to update some metadata property I get a "400 Bad Request" exception.
I know that my RequestDigest string is correct because I am able to upload new contents to the file.
I have seen many similar problems reported and have tried all of the suggestions without success.
(One suggestion was to access the file as a list item rather than using the file url, which I have done in the code below.)
var
str,body,MyUrl: string;
stream: TStringStream;
begin
MyUrl:=MySite+'_api/web/Lists/getByTitle(''CM Library'')/Items(2)';
body:='{"__metadata":{"type":"SP.Data.CM_x0020_LibraryItem"},"Title":"UpdatedTitle"}';
stream := TStringStream.Create(body, TEncoding.UTF8);
try
IdHTTP.Request.Accept:='application/json;odata=verbose';
IdHTTP.Request.ContentType:='application/json';
IdHTTP.Request.ContentLength:=stream.size;
IdHTTP.Request.CustomHeaders.Values['X-RequestDigest']:=RequestDigest;
IdHTTP.Request.CustomHeaders.Values['IF-MATCH']:='*';
IdHTTP.Request.CustomHeaders.Values['X-HTTP-Method']:='MERGE';
try
str := IdHTTP.Post(MyUrl,stream);
except
on E : Exception do
ShowMessage('Exception: '+E.Message);
end;
finally
stream.Free;
end;
// Displays 'Exception: HTTP/1.1 400 Bad Request'
I found it! I needed to add ";odata=verbose" to Request.ContentType (as well as Request.Accept)
Sorry to trouble the community, but I was struggling with this for several days!!

PowerQuery missing supports for windows authentification and REST API POST body

I've discovered the hard way that PowerQuery (Powerbi & excel) Web.Contents function doesn't support a body payload when using Windows authentification.
with similar query
let
body = "{""json"" : ""payload""}",
Data= Web.Contents("http://xxxx/api/Query",[Content=Text.ToBinary(body),Headers=[#"Content-Type"="application/json"]]),
DataRecord = Json.Document(Data)
...
pretty stocked this lonely support and I suspect I'm missing an important aspect. Is there a recommanded way ? My google search were pretty un-successful.
Should I generate some kind of token with a first GET and then make a POST with body + token in anonymous ?
Do you have to use Windows authentication? How about using something like this with Anonymous authentication:
let
AuthKey = "mytoken",
url="http://xxxx/api/Query",
body = "{""json"" : ""payload""}",
Source = Json.Document(Web.Contents(url,[
Headers = [#"Authorization"=AuthKey ,
#"Content-Type"="application/json"],
Content = Text.ToBinary(body)
]
))
in
Source
Will this solve your problem?

Make Hubot run preconfigured commands automatically

I'm using Hubot on flowdock and I'm trying to make Hubot post automatically the respond of a user command.
With the help of https://leanpub.com/automation-and-monitoring-with-hubot/read#leanpub-auto-periodic-task-execution , I've managed to make Hubot talk at a specific time creating a cron.coffee script, so no issues with that.
The thing is that I have another script (trello.coffee) that makes Hubot respond to the command "show cards" and I want the result of this command to be posted in a specific time without the need of me telling Hubot to do this.
How exactly can I do this without the need to write another script (ie. trello.auto.coffee) and the whole robot.emit -> robot.on procedure?
What about using the http listener?
This page has a section for HTTP Listener and has this code example:
module.exports = (robot) ->
robot.router.post '/hubot/chatsecrets/:room', (req, res) ->
room = req.params.room
data = if req.body.payload? then JSON.parse req.body.payload else req.body
secret = data.secret
robot.messageRoom room, "I have a secret: #{secret}"
res.send 'OK'
Would that work?

Get the first product id in a magento system via soap api (2)?

Question: Is there a way (api call) to get the first product id in a magento install via the soap api.
I'm attempting to download all the products from a magento system and insert them into a different database (I do the conversion myself so that's not a bother) What is hard to understand though is how do I get a list of the product id's without getting all of them, if all I know is that the site is up.
Here's the info I have.
soap end point
soap username
soap apikey (aka password)
Here's what I don't know.
the id of any of the products
the date any of the products were created on or last edited.
For my initial load, I have to do a where product id in, because I expect 20 to 40k product lists won't come back in one soap call.
So I call
where id in (1 -> 100) Nope
where id in (101-> 200) Nope..
Now as you can imagine that code smells something fierce. It works, but I have to think there is a better way..
To expand my question: Is there a better way?
I can post the XML that I'm sending if that helps. The language I'm using to create the soap(xml) is vim, so I don't have code I can paste.
Try This
$client = new SoapClient('http://localhost/magento8/index.php/api/soap/?wsdl');
$session = $client->login('soap username', 'soap apikey');
$filters=array('entity_id'=>array(array('lt'=>'1','gt'=>'100')));//get fist 100 result
$result = $client->call($session, 'catalog_product.list',array($filters));
var_dump($result);
for more attributes check this
http://www.magentocommerce.com/wiki/1_-_installation_and_configuration/using_collections_in_magento