How to send push to Huawei device using Huawei Push Kit API?

5.1k views Asked by At

I want to send push from server to Huawei device with Huawei Push Kit integrated. I have deviceToken from device, but when I try so send push message using API I receive error:

80300002: No permission to send message to these tmIDs

1

There are 1 answers

2
mohax On BEST ANSWER

This error can be caused be wrong AppId, used in API url path.

AppId can be found in console so: App Gallery Connect -> My projects -> YOUR_PROJECT -> Project settings. On this screen AppId is Application ID, which can be found above SHA-256 of your signing keys.

enter image description here

So, working request using looks like (for notification push (shown in notification bar)):

curl --location --request POST 'https://push-api.cloud.huawei.com/v1/APP_ID_FROM_CONSOLE/messages:send' \
--header 'Authorization: Bearer ACCESS_TOKEN' \
--header 'Content-Type: application/json' \
--data-raw '{
    "validate_only": false,
    "message": {
        "notification": {
            "title": "Hello!",
            "body": "Hello, shirley!",
            "click_action": {
                "type": 3
            }
        },
        "android": {
            "urgency": "NORMAL",
            "ttl": "10000s",
            "notification": {
                "title": "Hello!",
                "body": "Hello, shirley!",
                "click_action": {
                    "type": 3
                }
            }
        },
        "token": [
            "DEVICE_TOKEN"
        ]
    }
}'

To get ACCESS_TOKEN see this question: How to get access token for Huawei Api for sending push to device?


You can find more information in documentation: https://developer.huawei.com/consumer/en/doc/development/HMSCore-References-V5/https-send-api-0000001050986197-V5#EN-US_TOPIC_0000001070412173__section134322259125