Skip to main content

Hello! I’m using Amplitude HTTP API v2 for a WebGL project, where users are anonymous. The Amplitude documentation clearly states “Don't set the user ID if there isn't one.” So, I did that, but whenever I upload an event without a user ID I get this error:

 

400 Bad Request:

{
    "events_with_missing_fields": {
        "device_id":
            0
        ],
        "user_id":
            0
        ]
    },
    "code": 400,
    "error": "Request missing required field"
}

 

So, then I tried to send an event with the user_id set to an empty string and got a different error (also happens if “null” is sent):

 

400 Bad Request:

{
    "code": 400,
    "events_with_invalid_ids": {
        "user_id": "
            0
        ]
    },
    "error": "Invalid id provided: omit the user_id or device_id field if they are unknown"
}

 

This is quite the conflict. The HTTP API v2 appears to be completely unable to ingest events that don’t contain a user ID. Could someone from the Amplitude team please fix this issue on the back-end?

Hey @REM5 Studios 

For the HTTP API, either a user_id or a device_id is required. So if the user_id is missing and you are correctly sending the device_id with every event, then there shouldn’t be any issue IMO.
If you are sending a device_id and still getting an error, then maybe this is something support can look into.


Hey @Saish Redkar, thanks for your explanation!

 

What do you recommend I use for the device_id? My platform is a Unity WebGL app that can be run on a variety of browsers. Is it ok to generate a random UUID for device_id each time the app is loaded? (Although this would generate a new device each time the app is loaded.)

 

Is there a way to get a unique identifier from the user’s browser (or create and store one) so that the UUID persists even if the webpage is reloaded or the user returns later? If that’s possible (and recommended), I may need some direction on this as I am not a web developer (but willing to put on that hat if necessary). I’m primarily a Unity developer and I am doing the HTTP requests from inside the Unity environment via UnityWebRequest. I do believe there is a way for the Unity app to communicate with javascript, though (although this is new territory for me).


Well, with Unity WebGL I’m able to generate a UUID for user_id and store it in Application.persistentDataPath which uses indexedDB to store the save data in the browser. Then the user ID persists even if the webpage is reloaded or the user returns later (unless, of course, browser data is cleared).

 

So, I think my problem is solved. 🙂 But, if my method could be improved, I’m certainly open to suggestions!

 

Thanks again @Saish Redkar for helping me understand the issue, and apologies for assuming it was a problem with the Amplitude back-end. This has been very helpful for my learning!


Hi @REM5 Studios ,

 

Thanks for writing into Community!

 

@Saish Redkar is spot on! The HTTP API must have a Device ID and/or User ID included in it for it to send correctly. I would recommend a read of this article on how AMplitude tracks users as well as this article on the Taxonomy Data playbook. I would try to not have a new UUID each time but try and associate a fixed Device ID for that user. I wish I could advise on the code side of things but I am not a developer either but perhaps something like this might help?

Glad to see you have your own solution though! Maybe @Saish Redkar will have more to add? :)

 


Thanks for your reply, @Denis Holmes! So, I’m able to generate and store a UUID in the user’s web browser that persists until their browsing data is cleared. If I’m understanding this correctly, I should be using this UUID for device_id, not user_id?


Hi @REM5 Studios ,

 

I would use a UUID for a User ID and this is to keep the users unique. Apologies, I realise now my previous answer is a little misleading. So I would use a UUId for User ID and then try to keep the Device ID consistent per a device. Perhaps you could do some sort of IP Address to Unique Device ID association table. Once the User ID is set , is tied to that profile and that user. Having said that, you can absolutely use a UUID for the Device ID if you wish but the problem is with if two users share the same device. Is that something that would happen often with your application? 


Reply