Web Hooks: Making Remote API Calls
Interacting With Remote Services
The After Submit Hook (or the Before Submit Hook), are perfect for creating integrations with 3rd party services. Using the provided HTTP libraries simplifies the process of integrating with a variety of services.
Making Simple HTTP GET and POST Requests
The Needle module is included to simplify making HTTP requests. View the link above for details on how to make GET and POST requests.
Sample GET request:
This sample request returns data from a URL and records it in the field named 'NeedleResponse'.
needle.get('http://www.somedomain.com/returnData.php', function(err, resp) {
try{ log('response from remote GET request returned'); if (!err){ form.setValue([NeedleResponse],resp.body) }else{ form.setValue([NeedleResponse],err) }
}catch(err2){
log('Error parsing response - ' + err2);
} // this line MUST be included in the callback // or no data will ever get returned from the hook logiforms.endRequest() });
Sample POST request
This sample posts form values to a URL and records the value returned in the field named 'NeedleResponse'. The second argument to needle.post, contains the values to POST.
needle.post('http://www.somedomain.com/receiveFormPost.php', { city : [City], company : [Company], id : [RecordID] }, function(err, resp) {
try{ log('response from POST request returned'); if (!err){ form.setValue([NeedleResponse],resp.body) }else{ form.setValue([NeedleResponse],err) }
}catch(err2){
log('Error parsing response - ' + err2);
} // this line MUST be included in the callback // or no data will ever get returned from the hook logiforms.endRequest() }); });
0 Comments