A '401 Unauthorized' error typically indicates that your application's API requests to Pushwoosh are not being properly authenticated. This can happen for a couple of reasons when using the Pushwoosh Cordova plugin:
- API Token is Missing or Incorrectly Configured: The Pushwoosh API token, required for authorizing API requests, might not be correctly added to your Cordova project's
config.xml
file. - API Token Lacks Permissions: The API token you are using might not have the necessary permissions assigned to it for your specific application in the Pushwoosh control panel.
Here's how to resolve this issue:
Step 1: Add the API Token to config.xml
You need to add a 'device' type API token to your config.xml
file. You can obtain or create this token from your Pushwoosh control panel under your application's 'API Access' section.
Add the following snippets to your config.xml
file, replacing YOUR_IOS_API_TOKEN
and YOUR_ANDROID_API_TOKEN
with your actual 'device' type API token:
For iOS:
<platform name="ios"> <config-file target="*-Info.plist" parent="Pushwoosh_API_TOKEN"> <string>YOUR_IOS_API_TOKEN</string> </config-file> </platform>
For Android:
<platform name="android"> <config-file parent="application" target="AndroidManifest.xml"> <meta-data android:name="com.pushwoosh.apitoken" android:value="YOUR_ANDROID_API_TOKEN" /> </config-file> </platform>
Note: It's recommended to use the config.xml
method. Alternatively, for iOS, you can add the Pushwoosh_API_TOKEN
key and your token string directly to your project's Info.plist
file.
Step 2: Ensure API Token Has Correct Permissions
Even if the token is in your config.xml
, it must have permissions to access your application.
- Go to your Pushwoosh control panel.
- Navigate to the application for which you are configuring pushes.
- Go to the 'API Access' section.
- Find the 'device' type token you are using (or create a new one if needed).
- Ensure that this token has the necessary permissions granted for the application you are working with. If it's a new token, you might need to explicitly assign it access to your app.
After performing these steps, rebuild your Cordova application and test the device registration again. The '401 Unauthorized' error should be resolved.
If the issue persists, ensure you are using the latest Pushwoosh Cordova plugin and that your iOS pods (if applicable) are up to date by running pod install
or pod update
in your project's ios
directory.
Comments
0 comments
Please sign in to leave a comment.