If you are receiving a 401 Unauthorized error when using Email API endpoints such as /registerEmail, /registerUser, or /setEmailTags, it is typically due to an incorrect API token or authentication format.
To resolve this, ensure you are following these steps:
- Use the Correct Token: For these specific endpoints, you must use your Device API Token, not your Server API Token.
- Use Header Authentication: The token must be passed in the
Authorizationrequest header. - Format the Header Correctly: The value for the header must be the word
Token, followed by a space, and then your Device API Token.
Here is an example of the correct Authorization header format:
Authorization: Token YOUR_DEVICE_API_TOKEN
Example curl Request
Below is a corrected example of a /registerEmail request using the proper authentication method. Note that the auth key is not needed in the request body when using header authentication.
curl -X POST "https://YOUR_APP_CODE.api.pushwoosh.com/json/1.3/registerEmail" \
-H "Content-Type: application/json" \
-H "Authorization: Token YOUR_DEVICE_API_TOKEN" \
-d '{
"request": {
"application": "YOUR_APP_CODE",
"email": "test@example.com",
"userId": "test-user-123"
}
}'
Comments
0 comments
Please sign in to leave a comment.