Reputation: 33
I'm new to Snowflake and my objective is to use the SQL API to execute queries.
Using curl I'm able to create an access token and a refresh token. I can then use the access token in the snowsql connection parameter "--token" to start a snowsql session and execute SQL statements. This all works fine.
However, when I try to use curl to POST a request to the /api/statements endpoint (as documented on https://docs.snowflake.com/en/developer-guide/sql-api/guide.html#example-of-a-request) and I use the same access token, then I'm getting an "JWT token is invalid" error. Am I missing something here? Do I need to generate and use a different access token for the SQL API than the one I can use with snowsql? If so, how can I generate such access token?
Any idea or hint is greatly appreciated. Thanks.
Upvotes: 3
Views: 3072
Reputation: 1642
There are 2 mechanisms for authorizing the users for SQL API, one is the External Oauth and the other is key-pair mechanism. From what I presume, it seems that you have used the External OAuth token for Key pair auth for SQL API hence the error is seen. In the SQL API request that is being tested, remove this line:
-H "X-Snowflake-Authorization-Token-Type: KEYPAIR_JWT" \
Now, run the curl command and it should work successfully. When no parameter value for Auth token type is passed, it defaults to external OAuth.
Upvotes: 2