A '401 Unauthorized' error means your app's requests to Pushwoosh are not authenticated. With the Pushwoosh Cordova plugin this normally comes down to one of two things:
-
The Device API token is missing or misconfigured in your Cordova project's
config.xml. - The token has no permission for the project you are registering against.
Step 1: Create a Device API token
In the Pushwoosh Control Panel go to Settings → API Access and create a token of type Device. Tokens are account-level: when you create one you choose which projects it may access (or grant access to all projects). Only grant a token the projects it actually needs. See API Access token.
Step 2: Add the token to config.xml
Replace YOUR_IOS_API_TOKEN / YOUR_ANDROID_API_TOKEN with your Device 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: Pushwoosh_API_TOKEN is the current iOS Info.plist key (the older PW_API_TOKEN is still accepted as a legacy fallback but is overridden by Pushwoosh_API_TOKEN). You can also add the key directly to your project's Info.plist instead of using config.xml, or set it at runtime before registering:
PushNotification.setApiToken('YOUR_DEVICE_API_TOKEN');
Step 3: Verify the token's project permissions
- Open Settings → API Access in the Control Panel.
- Find the Device token you are using (or create a new one).
- Confirm it is granted access to the project whose application code your app registers with. A brand-new token often needs the project assigned explicitly.
Rebuild the Cordova app and retry registration. If the error persists, update to the latest pushwoosh-cordova-plugin and refresh your iOS pods with pod install / pod update in the project's ios directory.
Comments
0 comments
Please sign in to leave a comment.