I'm following the instructions here http://developer.bigcommerce.com/api/webhooks/quickstart to set up webhooks to initiate some third-party order processing. We've been doing this on an hourly batch, real-time webhook triggers will save us a lot of lag time.
I think I've set up the webhook broadcaster, but can't see any evidence that it's being fired- I've created a bunch of new orders and nothing reaches the rails server.
How can I tell if BigCommerce is firing events when / where I expect?
Generated the access token for the given app/user/domain:
curl -XPOST -d '{
"client_id":"[BigCommerceAppClientId]",
"client_secret":"[BigCommerceAppSecret]",
"user":"admin",
"token":"[adminAPIToken]",
"store_domain":"https://[myStore].mybigcommerce.com"
}' https://hooks-beta.bigcommerce.com/token
yields ===>
{
"access_token":"[webHooksAccessToken]",
"producer":"store/[myStoreKey]"
}
Subscribed to webhooks for store/events/listener:
curl -XPOST -d '{
"producer":"store/[myStoreKey]",
"scope":"store/order/created",
"deliverymethod":"HTTP_POST",
"destination":{"url":"http://[myPublicRailsServer]/hooks"}
}' -H 'X-Auth-Client: [BigCommerceAppClientId]' -H 'X-Auth-Token:[X-Auth-Token]' https://hooks-beta.bigcommerce.com
yields ===>
{
"client_id":"[webHooksAccessToken]",
"created_at":"2013-06-27T19:57:38+00:00",
"deliverymethod":"HTTP_POST","destination":{"url":"http://[myPublicRailsServer]/hooks"},
"id":651,
"producer":"store/[myStoreKey]",
"scope":"store/order/created",
"updated_at":"2013-06-27T19:57:38+00:00"
}
I lied. The problem was apparently trying to use https instead of http. Everything works as expected.
Furthermore- BigCommerce provides a hook to check the active clients for a given application:
curl -XGET -H
'X-Auth-Client: [BigCommerceAppClientId]' -H
'X-Auth-Token: [BigCommerceAppSecret]'
https://hooks-beta.bigcommerce.com/producer/store/[myStoreKey]
Related
I have defined a file with name - play.rego
package play
default hello = false
hello {
m := input.message
m == "world"
}
I also have file called -input.json
{ "message": "world"}
I now want to use the policy to evaluate on input data using opa server -
opa run --server
I also then registered the policy using below command -
curl -X PUT http://localhost:8181/v1/policies/play --data-binary #play.rego
and then I run below command for evaluating policy on the query -
curl -X POST http://localhost:8181/v1/policies/v1/data/play --data-binary '{"message": "world"}'
But the server always responds with nothing.
I need help fixing the problem?
The URL of the second request is wrong (should not contain v1/policies), and the v1 API requires you to wrap the input document inside an input attribute. Try:
curl -X POST http://localhost:8181/v1/data/play --data-binary '{"input":{"message": "world"}}'
I am trying to use the Jenkins REST API. In the instructions it says I need to have the API key. I have looked all over the configuration pages to find it. How do I get the API key for Jenkins?
Since Jenkins 2.129 the API token configuration has changed:
You can now have multiple tokens and name them. They can be revoked individually.
Log in to Jenkins.
Click you name (upper-right corner).
Click Configure (left-side menu).
Use "Add new Token" button to generate a new one then name it.
You must copy the token when you generate it as you cannot view the token afterwards.
Revoke old tokens when no longer needed.
Before Jenkins 2.129: Show the API token as follows:
Log in to Jenkins.
Click your name (upper-right corner).
Click Configure (left-side menu).
Click Show API Token.
The API token is revealed.
You can change the token by clicking the Change API Token button.
The non UI way to do this post Jenkins 2.129 is:
curl 'https://<jenkinsURL>/me/descriptorByName/jenkins.security.ApiTokenProperty/generateNewToken' \
--data 'newTokenName=foo' \
--user username:Password
which returns:
{
"status": "ok",
"data": {
"tokenName": "foo",
"tokenUuid": "<uuid>",
"tokenValue": "<redacted>"
}
}
Pre Jenkins 2.129
curl http://<username>:<password>#<jenkins-url>/me/configure
Tested in Jenkins 2.225
After making research for several hours I could find the answer:
The API token is used instead of the CSFR token. However, what happens if you want to make authentication from any other client (Postman, CLI, cURL, etc.)?
First you need to get a CSFR token and save the information in a cookie with --cookie-jar
Request
curl -s --cookie-jar /tmp/cookies -u username:password
http://localhost:8080/crumbIssuer/api/json
Response
{
"_class": "hudson.security.csrf.DefaultCrumbIssuer",
"crumb": "bc92944100d12780cfc251c9255f3f323a475562b4ee0d8b9cc6e4121f50a450",
"crumbRequestField": "Jenkins-Crumb" }
Then we can read the cookie with --cookie and generate the new token:
Request
curl -X POST -H
'Jenkins-Crumb:your_crumb_token_generated_above'
--cookie /tmp/cookies http://localhost:8080/me/descriptorByName/jenkins.security.ApiTokenProperty/generateNewToken?newTokenName=\your_token_name
-u username:password
Response
{
"status": "ok",
"data": {
"tokenName": "my android token",
"tokenUuid": "c510e26c-b2e8-4021-bf79-81d1e4c112af",
"tokenValue": "11a2a0c91913d1391d8e8cb155ca714581"
} }
How to a generate Jenkins API token
The following commands need curl and jq. Execute them in the same session.
# Change the following appropriately
JENKINS_URL="http://localhost:8080"
JENKINS_USER=admin
JENKINS_USER_PASS=admin
Get the Crumb
JENKINS_CRUMB=$(curl -u "$JENKINS_USER:$JENKINS_USER_PASS" -s --cookie-jar /tmp/cookies $JENKINS_URL'/crumbIssuer/api/xml?xpath=concat(//crumbRequestField,":",//crumb)')
Get the access token
ACCESS_TOKEN=$(curl -u "$JENKINS_USER:$JENKINS_USER_PASS" -H $JENKINS_CRUMB -s \
--cookie /tmp/cookies $JENKINS_URL'/me/descriptorByName/jenkins.security.ApiTokenProperty/generateNewToken' \
--data 'newTokenName=GlobalToken' | jq -r '.data.tokenValue')
Consecutive API calls
Instead of the password, you need to use the token with the username along with the crumb that was generated.
curl -u $JENKINS_USER:$ACCESS_TOKEN \
-H $JENKINS_CRUMB \ ..........
I've lost almost two whole days trying to solve PayPal related issues.
I'm trying to execute a payment after user's approval, but I'm getting MALFORMED_REQUEST everytime I send the Curl request.
def execute
# Get the access_token
token = get_paypal_token(false)
payer_id = params[:PayerID]
payment_id = params[:paymentId]
# Creating the data object
stringJson = {:payer_id => "#{payer_id}"}
# You can see that I hard-coded the payer_id to ensure the JSON is correct
curlString = `curl -v -H "Authorization: Bearer #{token}" -H "Content-Type: application/json" -d '{"payer_id" : "QULQSFESGMCX2"}' https://api.sandbox.paypal.com/v1/payments/payment/#{payment_id}/execute/`
end
And the response is:
"{\"name\":\"MALFORMED_REQUEST\",\"message\":\"The request JSON is not well formed.\",\"information_link\":\"https://developer.paypal.com/webapps/developer/docs/api/#MALFORMED_REQUEST\",\"debug_id\":\"6431589715660\"}"
Looks like you are running it from windows. I tried your command from my windows and my test server receiving the json as '{payer_id. It is happening because of your single quote.
I have changed the single quotes into double and it is working fine here with me.
-d "{\"payer_id\" : \"QULQSFESGMCX2\"}"
You can run the curl command from the console and see what happens, after that you can push it inside your ruby script code.
i'm trying to send a parse.com push notification from ruby 1.8.7.
i got a test working with curl. but with ruby's net::http i'm getting Timeout::Error: Resource temporarily unavailable
how can i debug this? i don't know how to see why the parse server is responding differently or otherwise see what's happening. i tried sending the request to my own server and the headers looked ok to me.
i simplified what i'm doing to this:
http = Net::HTTP.new('api.parse.com', 443)
response = http.post("/1/push", "{\"where\":{},\"data\":{\"alert\":\"Elliot net http json test 1\"}}", {"X-Parse-Application-Id"=>"xxxxx", "Content-Type"=>"application/json", "X-Parse-REST-API-Key"=>"xxxxx"})
the json there is hard to read, it's from:
api_req = {:where => {}, :data => {:alert => "Elliot net http json test 1"}}.to_json
puts api_req
# {"where":{},"data":{"alert":"Elliot net http json test 1"}}
i also tried several other ways of sending a request with net::http. same result.
the curl request that worked was:
curl -X POST \
-H "X-Parse-Application-Id: xxxxxx" \
-H "X-Parse-REST-API-Key: xxxxx" \
-H "Content-Type: application/json" \
-d '{
"where": {},
"data": {
"alert": "Elliot curl test #4"
}
}' \
https://api.parse.com/1/push
i'm not using parse-ruby-client because i ran into problems with dependencies assuming a newer version of ruby. all i need to do is send some simple push notifications, and it seems like this should work without too much trouble.
can anyone help me get this working or tell me how to get some useful info about what's happening to debug?
As per the REST API Developers guide,
All API access is over HTTPS, and accessed via the https://api.parse.com domain.
So all you need to do is to add http.use_ssl = true.
This is what I've currently got and it creates a new Confluence page. It doesn't update it. Also it posts it in the root space, TST, but I want it to be in TST/space1/subsection2/updateThisPage.
curl -v -u admin:admin -X POST -H Content-Type: application/json -d "{\"id\":\"123456\",\"type\":\"page\",\"title\":\"new page\",\"space\":{\"key\":\"TST\",\"title\":\"updateThisPage\"},\"body\":{\"storage\":{\"value\":\"<p>This is the updated text for the new page</p>\",\"representation\":\"storage\"}},\"version\":{\"number\":3}}" http://localhost:8090/rest/api/content?spaceKey=TST&title=updateThisPage
This is the error message I get
{"statusCode":400,"message":"A page with this title already exists: A page already exists with the title new page in the space with key TST"}
Would it be a permissions error? I know I do not have access to delete.
Use request /rest/api/content/{id}.
This worked for me.
curl -u admin:admin -X PUT -H "Content-Type: application/json" -d "{\"id\":\"26738701\",\"type\":\"page\",\"title\":\"new page\",\"space\":{\"key\":\"RO\"},\"body\":{\"storage\":{\"value\":\"<p>UPDATE This is a new page</p>\",\"representation\":\"storage\"}},\"version\":{\"number\":2}}" http://localost:10080/rest/api/content/26738701
JSON Payload:
{
"id":"26738701",
"type":"page",
"title":"new page",
"space":{
"key":"RO"
},
"body":{
"storage":{
"value":"<p>UPDATE This is a new page</p>",
"representation":"storage"
}
},
"version":{
"number":2
}
}
Don't forget to use:
content ID in data part
version number in data part
PUT request
content ID in request
Try to use PUT instead of POST.
curl -v -u admin:admin -X PUT -H Content-Type: application/json -d "{\"id\":\"123456\",\"type\":\"page\",\"title\":\"new page\",\"space\":{\"key\":\"TST\",\"title\":\"updateThisPage\"},\"body\":{\"storage\":{\"value\":\"<p>This is the updated text for the new page</p>\",\"representation\":\"storage\"}},\"version\":{\"number\":3}}" http://localhost:8090/rest/api/content?spaceKey=TST&title=updateThisPage
If anyone is looking for javascript solution, here is my answer to another question like that
Unexpected grunt-http error when posting to Atlassian Confluence api
And here you can find working code i've developed on confluence hackathon
https://github.com/devex-web-frontend/dxWebPlugins/blob/master/src/confluence/helpers/buffer.js