Using Your APIs
Nudge allows you to integrate your own APIs with the Nudge SDKs. This means you can call your APIs and display the dynamic data in the interfaces generated by the Nudge SDK directly from the dashboard.
Authentication for Your APIs
If your APIs require authentication, you'll need to pass your authentication key to the Nudge SDK. This allows the SDK to call the registered APIs on your behalf.
How to Pass Your Authentication Key
To authenticate your API calls, you'll need to create a function that returns the appropriate API key when Nudge requests it. This function will be used by Nudge whenever it needs to interact with your API. Once set up, you can register all your APIs requiring authentication in the Nudge dashboard.
1. Define a function that returns your API key for a given API name. Here's an example :
// Define a function that returns your API key for a given API name.
func getAuthKey(key: String) -> String? {
switch(key) {
case "abc":
return "your_api_key_for_abc"; // Return the API key for "abc" API
default:
return nil; // Return nil for unrecognized API names
}
};
2. Register the authentication function with the Nudge SDK. The SDK will call this function to obtain the API key when needed.
nudgeLifecycleManager = NudgeInitialise(
apiKey: "key",
region: .IN,
registerAuth: getAuthKey
)
After this setup, the SDK will be able to use your authentication key to interact with your APIs.