How to create a fn function via API? - fn

I'd like to create a fn function via API. In the official document,
There are only some endpoint for creating app, routes and call.
any idea?

One of fn contributors answered me:
By creating a route you would create a function with an HTTP webhook to that.

Related

Redirect URL using Firebase Dynamic / Deep Links is losing query parameters

In my Flutter (Android/iOS) app I am using Firebase Dynamic Links for Patreon.com OAuth2 apis.
My dynamic link is https://myappname.page.link/patreon
The deep link is https://myappname.net/patreon
Patreon is using the https://myappname.page.link/patreon as a redirect_url , and is supposed to append some parameters to it, so it looks like
https://myappname.net/patreon?code=xxx
However, all I receive inside my app is the naked url https://myappname.net/patreon
There are no parameters attached to it.
So how can I tell Firebase to preserve the query parameters Patreon is attaching to the redirect_url?
As an alternate question, is there a better way to listen for incoming response inside of a Flutter app, without the use of Dynamic Links?
You loose all parameters by using that.
If you're relying on Patreon to send back that parameter I'd suggest to generate a small proxy where you can redirect your calls to the dynamic link by generating it on the fly.
So:
Patreon shares www.myhost.com/supah-link?p1=aaa&p2=bbb
Your micro-service which runs on www.myhost.com/supah-link receives the call
You generate a dynamic link like the following:
https://example.page.link/?link=https://www.example.com/someresource&apn=com.example.android&amv=3&ibi=com.example.ios&isi=1234567&ius=exampleapp&p1=aaa&p2=bbb
NOTE: Pay attention to the &p1=aaa&p2=bbb parameters added
Return a 302 and redirect to your newly generated link
Based on how you configure it from the console this link can redirect to the store or your app, in your app you can listen for the link as follows:
FirebaseDynamicLinks.instance.onLink(
onSuccess: (dynamicLink) async => handleDeepLink(dynamicLink?.link),
);
In handleDeepLink you can parse your custom query parameters.
NOTE: The URL parameter you pass via the dynamic link HAS TO BE ENCODED! Which means your link will look more like this:
https://example.page.link/?link=https%3A%2F%2Fwww.example.com%2Fsomeresource%26apn%3Dcom.example.android%26amv%3D3%26ibi%3Dcom.example.ios%26isi%3D1234567%26ius%3Dexampleapp%26p1%3Daaa%26p2%3Dbbb

Exposing the Salesforce Data as an Rest API

I am new to Salesforce and I would like to get some expert advice on how I can expose the Sales force data as an Rest API so the external System can consume it. I was think if I can create a Apex Class like
below
#RestResource(urlMapping='/GetAccounts/*')
global with sharing class GetAccounts {
#HttpGet
global static Account doGet() {
RestRequest req = RestContext.request;
RestResponse res = RestContext.response;
String accountId = req.requestURI.substring(req.requestURI.lastIndexOf('/')+1);
Account result = [SELECT Id, Name FROM Account WHERE Id = :accountId];
return result;
}
}
And for the external user to consume the data I thought I can set up up a Connected App and provide them with the Username,password, Consumer Key,Consumer secret and they should be authenticating in to Salesforce to get the URI and session ID. Using the SessionID and URI the should be able to call the API that is exposed above. Is this the right approach, please let me know if I am missing anything here.
Also there is a requirement to use Swagger with the API, is it possible to use the Swagger within the Apex Class. Can you please help how I can leverage Swagger with my API here.
First of all you should try to use Salesforce standard REST API. You can check the full documentation from here.
https://developer.salesforce.com/docs/api-explorer/sobject/Account
You might be asking yourself, well when I should expose an APEX class as a REST API like the code you have provided?
You need to do that when you need custom logic to be performed and combined with the API call.
Exposing Salesforce REST API as OPEN API specification(Swagger) is not yet supported. You can vote for this idea if you need it.
https://success.salesforce.com/ideaView?id=0873A000000cQsxQAE
But the other way is supported. You can import a swagger specification file and invoke it using point and clicks from Salesforce.
Check this blog for more details:
https://andyinthecloud.com/2017/07/23/simplified-api-integrations-with-external-services/

How to write REST Web services in Laravel 5.2?

I am creating api for mobile app in laravel 5.2 version but now I am facing one problem. Problem is that in my routes.php I am created routes for my website. Now my question is if I start creating api for mobile for that I have to create new routes for mobile api Or I can use same routes for RESTapi also?
In Laravel 5.2 I have to add any webservices libraries or not? If yes, Please suggest me how to use RESTapi in Laravel 5.2? Please help.
My routes.php
Route::auth();
Route::get('/', 'Auth\AuthController#login');
Route::get('admin/users', 'UserController#getUsers');
Route::get('admin/users/add', 'UserController#addUser');
If your routes an their inside logic returns json response, Its not necessary to create new routes, But if your routes does not returns json response, you must write new routes.
For having better APIs, json-hal, jsend or json-api conventions may help you.
Your api routes can coexist with your regular web routes. It's customary, however, to separate them, typically by a subdomain (https://api.yoursite.com), or at least a path (https://yoursite.com/api/v1).
Also, api version number is often included, as in my last example.
As for a package to develop apis in Laravel, have a look at Dingo. It's very complete, provides its own router, versioning, security, etc.
You have different middleware in laravel. By default you should have "web" middleware activated. It is either directly in your routes.php, in your controler constructor OR in the RouteServiceProvider.php
You wouldn't use web middleware for an api / restful service, therefore you should use another middleware ( e.g. "api" middleware which throttles requests to only allow max. 60 requets per minute etc. )
Typically you group your api requests
Route::group(['prefix' => 'api/v1'], function()
{
...
}
to strictly divide them from your application. You can then also easy change to v2 for example if you plan many releases
Update
if your api logic follows your business logic then you could aswell just watch for ajax calls and return json
public function index(Request $request) {
// do stuff here
if($request->ajax()) {
// return json
}
// return view
}

IFTTT recipe api - is there documentation to create recipe using API call

I have already created triggers and actions for IFTTT channel. Now I want to create a recipe using these triggers and actions, but I want to do it not through Maker, but using an API call. What would be the format of the API call (behind Maker UI) to create a recipe, I am seems to unable to see any documentation or examples?
Click the URL in your maker settings to see IFTTT's description, which reads as follows, and shows your individual API key which must be used in your code:
To trigger an Event Make a POST or GET web request to:
https://maker.ifttt.com/trigger/{event}/with/key/tIpcUAlqRkf8Mls9XepGN
With an optional JSON body of:
{ "value1" : "", "value2" : "", "value3" : "" }
The data is completely optional, and you can also
pass value1, value2, and value3 as query parameters or form variables.
This content will be passed on to the Action in your Recipe. You can
also try it with curl from a command line.
curl -X POST https://maker.ifttt.com/trigger/{event}/with/key/tIpcUAlqRkf8Mls9XepGN
Yes. There is a documentation for create / triggers and actions.
You need to create the API from your server like that:
http://api.test.com:8080/ifttt/v1/triggers/{{triggers}}
More information:
Login: https://developers.ifttt.com/channels/t4/triggers
Click triggers in left menu
Create trigger name
Then as the endpoint you need to give your api url.
There is no public API. With old-type call there is internal API you can see REST calls like create/api/state whilst building a recipe, yet it might be protected from use by third party and I did not check the traffic of new applet maker platform. Note, if you are a partner you can embed your recipes into your apps. Upper tier customers are allowed to request new features (such as API or templates).
I was looking for the same, but after wasting hours, NO LUCK. So, I have decided to create one. This might be too late, but here's one repo of IFTTT boilerplate (https://github.com/Dipen-Dedania/ifttt-boilerplate) using NodeJS and express to create your own recipe (custom triggers and actions)

How to implement restful API with additional noun for entity

I would like to implement the following restful API using sails js:
(https://blog.codecentric.de/en/2012/11/a-restful-learning-curve-nouns-verbs-hateoas-and-roca/)
…/customers/[customer_id]/approval
I will PUT method to send approval information, and GET method to get the approval status.
It is quite easy in Sails js to implement in the following way:
…/customers/approval/[customer_id]
I only need to add a method approval in CustomerController.js. But if I want to implement the first approach (i.e. [customer_id] followed by approval. How can I do that in Sails js?
By the way, which API style is better?
You would need to write your own route
/customers/:customer_id/approval : 'CustomerController.approval'
Then inside your controller/action you would have access to req.param.customer_id
Checkout these links
http://sailsjs.org/documentation/concepts/routes
http://sailsjs.org/documentation/concepts/routes/custom-routes