I'm trying to use Snowpipe rest api as is pointed in Snowflake site:
https://docs.snowflake.com/en/user-guide/data-load-snowpipe-rest-apis.html#data-file-ingestion
I found a python example in here, my code and steps are pretty much the same:
https://community.snowflake.com/s/article/Connect-to-Snowpipe-Rest-API-by-using-JWT-Token
I checked the token in https://jwt.io/#debugger and is a valid jwt token.
However Snowpipe api responds always with:
{
"code": "390144",
"data": null,
"message": "JWT token is invalid.",
"success": false,
"headers": null
}
Am I missing something?
I created the keys using exactly these steps:
https://docs.snowflake.com/en/user-guide/data-load-snowpipe-rest-gs.html#step-3-configure-security-per-user
Also I tried thise other python code (and other ones), but having the same error:
https://docs.snowflake.com/en/user-guide/data-load-snowpipe-rest-load.html#sample-program-for-the-python-sdk
I ran into this as well and wanted to call the REST API from Go so needed to convert the Python script over. One issue I ran into was that standard Go libraries do not support encrypted PKCS 8 keys, I'd actually recommend starting without the key encrypted to remove an extra obstacle. I understand you went through these steps from the docs, but I'll put them in for a step by step.
Generate Keys (Unencrypted)
Update Snowflake User
Set the public key for the user, only the key itself remove the first and last lines from the
Get the fingerprint stored on the user after updating.
Find the property
RSA_PUBLIC_KEY_FPand copy the value. This will be used in creating the JWT.Creating the Fingerprint
The Python code for creating this fingerprint can be found here. https://github.com/snowflakedb/snowflake-ingest-python/blob/master/snowflake/ingest/utils/tokentools.py#L108
That was a big starting point for me, I wanted to make sure I could create the fingerprint that matched what was in Snowflake. Here is my code and tests in Go.
Unit test - Private key and expected fingerprint from Snowflake have been truncated use your full values. Also using Testify for assertions.
Creating the JWT
The get_token part of the Python Security Manager calls the fingerprint creation and returns the JWT.
And this is my Go code, it is not fancy in that it doesn't check a current token like the Python code. It is creating a new token each time based on your Snowflake account, user, and private key.
For clarity my claims would look like
Make a Request
Making sure to replace the URL with your account and fully qualified pipe. Also replace the header with the your generated JWT.