How can I post with curl a sentry event? Which authentication credentials?

Hi there,

I am trying to use the sentry api to send a event to sentry. But I always get the Message “Authentication credentials are not provided”

What key and secret do I have to use? I took this from the project properties DSN page.

Here is a code example from Github that I am using (https://gist.github.com/barroco/1a0009500ebd963b6522):

SENTRY_KEY=
SENTRY_SECRET=
SENTRY_PROJECTID=1
SENTRY_HOST=sentry.example.com

SCRIPT_ARGUMENTS=$@
capture_error()
{

MESSAGE=$1
EVENT_ID=openssl rand -hex 32
EVENT_TIMESTAMP=date +"%Y-%m-%dT%H:%M:%S"
SENTRY_TIMESTAMP=date +%s

curl --data “{
“event_id”: “$EVENT_ID”,
“culprit”: “$0”,
“timestamp”: “$EVENT_TIMESTAMP”,
“message”: “$MESSAGE”,
“tags”: {
“shell”: “$SHELL”,
“server_name”: “hostname”,
“path”: “pwd
},
“exception”: [{
“type”: “ScriptError”,
“value”: “$MESSAGE”,
“module”: “builtins
}],
“extra”: {
“sys.argv”: “$SCRIPT_ARGUMENTS”
}
}” -H “Content-Type: application/json” -H “X-Sentry-Auth: Sentry sentry_version=5, sentry_timestamp=$SENTRY_TIMESTAMP,
sentry_key=$SENTRY_KEY, sentry_client=raven-bash/0.1,
sentry_secret=$SENTRY_SECRET” http://$SENTRY_KEY:$SENTRY_SECRET@$SENTRY_HOST/api/$SENTRY_PROJECTID/store/

}

Hi, this gist contains a lot of useless things and is additionally outdated. This should work:

curl --data '{ ... }' \
  -H 'Content-Type: application/json' \
  -H "X-Sentry-Auth: Sentry sentry_version=7, sentry_key=$SENTRY_KEY, sentry_client=raven-bash/0.1" \
  https://sentry.io/api/$PROJECT_ID/store/

$SENTRY_KEY is the hash in the DSN, $PROJECT_ID is the integer at the end of the DSN.

Also consider https://docs.sentry.io/clientdev/overview/?platform=javascript which contains a lot of useful information should you decide to write your own SDK

4 Likes

Hi, your sample has worked instantly!
Thank you so much for your help!

Hi, just remembered that sentry-cli can also do this: https://blog.sentry.io/2017/11/28/sentry-bash. It offers a nicer interface because you don’t have to write the JSON yourself, at the same time you can’t add some params as far as I know. It should be quite easy to deploy (single binary) but obviously nothing is going to beat a pre-installed curl in that regard.