Using OAuth Token to Access Salesforce - salesforce

I am working on salesforce client integration. I want to get access token and i am using
URL : https://login.salesforce.com/services/oauth2/token
  Method : Post
  Header : Content-Type: application/x-www-form-urlencoded
 grant_type=password
client_id=XXXXXXXXXX
client_secret=XXXXXXXXXX
username=XXXXXXXXXX
password=XXXXXXXXXX
Above credential working fine with grant_type=authorization_code but while i switched to grant type password then its gives me
"http/1.1 400 bad request"
{"error":"invalid_client_id","error_description":"client identifier invalid"}

That looks right. Try this with curl:
curl https://login.salesforce.com/services/oauth2/token \
-d "grant_type=password" \
-d "client_id=YOUR_CLIENT_ID" \
-d "client_secret=YOUR_CLIENT_SECRET" \
-d "username=YOUR_USERNAME" \
-d "password=YOUR_PASSWORD"

Related

Not able to register the schema for kafka snowflake connector

Distributed Services Got Started Successfully:
[2021-10-17 18:04:29,693] INFO Started o.e.j.s.ServletContextHandler#1422ac7f{/,null,AVAILABLE} (org.eclipse.jetty.server.handler.ContextHandler:916)
[2021-10-17 18:04:29,693] INFO REST resources initialized; server is started and ready to handle requests (org.apache.kafka.connect.runtime.rest.RestServer:319)
[2021-10-17 18:04:29,693] INFO Kafka Connect started (org.apache.kafka.connect.runtime.Connect:57)
But not able to make schema registry:
curl -X PUT -H "Content-Type:application/json" --data '{"name": "file-stream-demo-distributed","config":{"connector.class":"com.snowflake.kafka.connector.SnowflakeSinkConnector","topic":"demo-2-distributed","file":"/home/ramakrishnakonda/kafka_2.13-2.8.0/config/connect-distributed.properties"}}' http://localhost:8083/connectors
{"error_code":405,"message":"HTTP 405 Method Not Allowed"}
Please help
Use POST rather than PUT, as in this example:
$ curl -X POST -H "Content-Type: application/json" --data '{"name": "local-file-sink", "config": {"connector.class":"FileStreamSinkConnector", "tasks.max":"1", "file":"test.sink.txt", "topics":"connect-test" }}' http://localhost:8083/connectors
curl -X POST "http://localhost:8083/connectors" -H "Content- type:application/json" --data
"{
"name":"file-stream-demo-distributed",
"config":{
"connector.class":"com.snowflake.kafka.connector.SnowflakeSinkConnector",
"tasks.max":"1",
"topics":"demo-2-distributed",
"buffer.count.records":"10000",
"buffer.flush.time":"60",
"buffer.size.bytes":"5000000",
"snowflake.url.name":"XXXXXXXX.XXXXXXXXX.snowflakecomputing.com:443",
"snowflake.user.name":"kafka_connector_user_1",
"snowflake.private.key":"XXXXXXXXXXXXXXXXXXX+XXXXXXXXXXXXXXXXXXXXXXXXXXXXX,
"snowflake.database.name":"KAFKA_DB",
"snowflake.schema.name":"KAFKA_SCHEMA",
"key.converter":"org.apache.kafka.connect.storage.StringConverter",
"key.converter.schemas.enable":"true", "value.converter":"com.snowflake.kafka.connector.records.SnowflakeJsonConverter",
"value.converter:schemas.enable":"true",
"value.converter.schema.registry.url":"http://localhost:8081"
}
}"

Bash: works at command line but getting 'curl: (1) Protocol ""https" not supported or disabled in libcurl' when using in a script

Got stuck with the situation that a curl request works fine with the command line but does not work at a script giving weird errors. Here is the part of the script:
#we already got the $token
#vars defining curl parameters
dc="NA EU AU SEA JP"
curl_url='https://example.com/api/config/v1/'
curl_request='alertingProfiles?'
curl_properties='tenant=all&stage=prd&cluster='
curl_auth='"Authorization: Bearer '"$token"'"'
for k in $dc; do
# Download the json for each DC using the curl request
curl_combined=\""$curl_url$curl_request$curl_properties$k"\"; echo "$curl_combined"
curlCMD=( -vv --location --request GET "$curl_combined" -H "$curl_auth" -o \""$k.json"\")
echo "${curlCMD[#]}"
curl "${curlCMD[#]}"
done
When I run this in a script I see the following output:
First, the output from the first echo command
"https://example.com/api/config/v1/alertingProfiles?tenant=all&stage=prd&cluster=NA"
Then, the output from the second echo command which is what curl should take as a parameter, I've skipped the bearer token, but trust me, it is not a problem here.
-vv --location --request GET "https://example.com/api/config/v1/alertingProfiles?tenant=all&stage=prd&cluster=NA" -H "Authorization: Bearer " -o "NA.json"
And I am getting following output
Note: Unnecessary use of -X or --request, GET is already inferred.
* Protocol ""https" not supported or disabled in libcurl
* Closing connection -1
curl: (1) Protocol ""https" not supported or disabled in libcurl
Please note two double quotes in the message above in front of https.
If I simply copy/paste the above second echo output in the command line right after curl and execute, it works as expected and downloads JSON in the file.
If I remove " from curl_combined var, the request is sent without double quotes and now I am getting the message curl: (56) Unexpected EOF from the script.
If I copy/paste the second echo output (without double quotes), supply it to curl, and execute from the command line, I am getting 403 message until I put double or single quotes around the https request.
In short - it seems that double quotes around the https request is necessary but for some reason, curl does not take it.
So what went wrong here? I don't mind even to write the constructed URL in a file and read from it or use herestring if it helps, but want to know what exactly went wrong here.
Thanks.
P.S. Removing --location or --request GET or both does not change the outcome.
The script is using passing the "${curlCMD[#]}" array as parameter to curl. This approach will handle the correct expansion of the url, regardless of any special characters in it. There is no need to wrap the curl_combined with additional quotes using the \" construct.
Suggesting replacing setting curl_combined with:
curl_combined="$curl_url$curl_request$curl_properties$k"
echo "$curl_combined"
This solution works replacing curl request with array to the following
curl -vv \
--location \
--request GET \
"$curl_combined" \
--header "Authorization: Bearer ${token}" \
-o "$k.json"
But it is ugly, let's say politely...

Cannot execute learning task. : Unable to create retraining task - previous training data not present

I am trying to update a classifier. In zip folder, I have more than 10 images. But still, not able to update.
Tried via swagger URl: https://watson-api-explorer.ng.bluemix.net/apis/visual-recognition-v3#!/Custom/updateClassifier
URL: https://gateway.watsonplatform.net/visual-recognition/api/v3/classifiers/sports_cars_1042527461?version=2018-03-19&api_key=xxxxxxxxxxxxxx
CURL: curl -X POST --header 'Content-Type: multipart/form-data' --header 'Accept: application/json' {"type":"formData"} 'https://gateway.watsonplatform.net/visual-recognition/api/v3/classifiers/sports_cars_1042527461?version=2018-03-19&api_key=xxxxx'
RESPONSE: {
"error": {
"code": 400,
"error_id": "input_error",
"description": "Cannot execute learning task. : Unable to create retraining task - previous training data not present."
}
}
Tried it with Node JS code too but got the same error.
Is there anything I missed or tried something wrong?
One thing I noticed is that you have a mix of URL and authentication for older and newer classifiers.
For classifiers created before May 23, you use the URL gateway-a. and &api_key=....
For classifiers created afterward, you use the URL gateway. and IAM authentication (-u "apikey:{apikey}").
so
curl -X POST \
-F "sportscars_positive_examples=#sc.zip" \
-F "negative_examples=#suvs.zip" \
"https://gateway-a.watsonplatform.net/visual-recognition/api/v3/classifiers
/sports_cars_1042527461?version=2018-03-19&api_key=xxxxxxxxxxxxxx"
or
curl -X POST -u "apikey:yyyyyyyyyyyyyyyyyyy" \
-F "sportscars_positive_examples=#sc.zip" \
-F "negative_examples=#suvs.zip" \
"https://gateway.watsonplatform.net/visual-recognition/api/v3/classifiers
/sports_cars_1042527461?version=2018-03-19"
For details, look at the API reference.

IBM dashDb stop_on_error blocker

I am trying to call POST request POST /sql_jobs (dashdbAPI_v2), but I can’t figure out what should be in stop_on_error. It requires string and always ends with error "Parameter stop_on_error is required".
Could you help me solve this issue?
The only valid values for stop_on_error are yes and no. If the value doesn't match one of them, it returns the error message you're seeing.
This is a working sample:
curl \
-X POST "https://host.bluemix.net/dashdb-api/v2/sql_jobs" \
-H "accept: application/json" \
-H "Authorization: Bearer eyJhbGciOiJSUzA ..." \
-H "content-type: application/json" \
-d '{ "commands": "SELECT 1", "limit": 0, "stop_on_error": "yes", "separator": ";" }'

I would like to sent message by add new line in meassage via batch-file (curl)

I create batch file to sent message to line notify.
I want new line in my message. I try to use \n, %0a but it can't use.
curl -X POST -H "Authorization: Bearer mytoken" -F "message=Computer 1 sent message!" https://notify-api.line.me/api/notify
in message=Computer 1 sent message! I want output follow:
Computer 1
sent message!
Try like below, that should work
curl -X "POST" "https://notify-api.line.me/api/notify" \
-H "Authorization: Bearer mytoken" \
-H "Content-Type: multipart/form-data" \
-d $'Computer 1 sent message!
Line1
Line2
Line3'

Resources