callrail api secondary request parameters - get

How do I add secondary request parameters using callrail api?
Independently the following two work.
curl -H "Authorization: Token token={faketoken123}" \
-X GET \
"https://api.callrail.com/v2/a/{accountId123}/calls.json?fields=first_time_callers,leads"
gets back the fields I need.
curl -H "Authorization: Token token={faketoken123}" \
-X GET \
"https://api.callrail.com/v2/a/{accountId123}/calls.json?company_id={companyId123}"
gets back specified company.
I need to combine the two. Here is what I've attempted:
curl -H "Authorization: Token token={faketoken123}" \
-X GET \
"https://api.callrail.com/v2/a/{accountId123}/calls.json?company_id={companyId123}&fields=first_time_callers,leads"
I've looked through all their documentation . Without figuring out how to do it. Any help would be greatly appreciated.

This is how you can add secondary request parameters.
var myToken = "4b20c9154e1b21ca5fc30b5c5725729a";
var accountId = "356-678-890";
var companyId = "756789417";
var startDate = "2017-07-03";
var endDate = "2017-08-05";
$.ajax
({
type: "GET",
url: "https://api.callrail.com/v2/a/" + accountId + "/calls.json?fields=tags,lead_status&company_id=" + companyId + "&start_date=" + startDate + "&end_date=" + endDate,
dataType: 'json',
headers: {"Authorization": 'Token token=' + myToken},
success: function (result) {
// your code
},
});

As of 3/31/2017 CallRail API does not currently accept secondary parameters in the HTTP request.
I received an e-mail from their support team telling me they are working on supporting that in the future.

Related

Can someone help me convert this Curl request into node.js?

I'm working with Webhooks and I am trying to run a Curl request from my node.js code. I'm using the npm request package to do this. I'm having trouble finding the proper way to convert the Curl request to code in my application that will send the request.
This is the Curl request:
curl -X POST https://tartan.plaid.com/connect \
-d client_id=test_id \
-d secret=test_secret \
-d username=plaid_test \
-d password=plaid_good \
-d type=wells \
-d options='{
"webhook":"http://requestb.in/",
"login_only":true }'
This works fine when I run it in my terminal so I know the credentials work and it is talking to the server.
Here is my Node.js code:
var request = require('request');
var opt = {
url: 'https://tartan.plaid.com/connect',
data: {
'client_id': 'test_id',
'secret': 'test_secret',
'username': 'plaid_test',
'password': 'plaid_good',
'type': 'wells',
'webhook': 'http://requestb.in/',
'login_only': true
}
};
request(opt, function (error, response, body) {
console.log(body)
});
It should return an item but all I am getting is:
{
"code": 1100,
"message": "client_id missing",
"resolve": "Include your Client ID so we know who you are."
}
All the credentials are from the Plaid website and they work in my terminal just fine so I think it's just the way I am writing my Node.js code that is causing the problem.
If anyone could help my find the right way to write the node code so that it does what the curl request does in the terminal that would be appreciated! Thanks!
You may want to use form: instead of data: in your options. Hopefully that will do the trick.
The default method for request is GET. You want a POST, so you have to set that as a parameter. You also have to send the data as JSON according to the documentation. So I believe this should work:
var opt = {
url: 'https://tartan.plaid.com/connect',
method: "POST",
json: {
'client_id': 'test_id',
'secret': 'test_secret',
'username': 'plaid_test',
'password': 'plaid_good',
'type': 'wells',
'webhook': 'http://requestb.in/',
'login_only': true
}
};
See explainshell: curl -X -d for an explanation of what your curl command actually does.
You send a POST request
You send data using using the content-type application/x-www-form-urlencoded
To replicate that with request you have to configure it accordingly:
var opt = {
url: 'https://tartan.plaid.com/connect',
form: {
// ...
}
};
request.post(opt, function (error, response, body) {
console.log(body)
});
See application/x-www-form-urlencoded for more examples.

Twilio - Need to dynamically set webhook from application after creating a new number

I have built an application that assigns a customer a twilio number that they will be able to send text messages to. I am able to create the number dynamically but i now need to set the webhook inside the code for the incoming texts so that twilio knows how to respond. Right now i am only aware of a way to do it through the console which wont work for what i need. Any help would be greatly appreciated. Thanks!
Twilio developer evangelist here.
Thanks to Alex for the answer, that's spot on. I just wanted to add a bit of code as I noticed the question was tagged Node.js.
Here is how to do the API calls with the Node.js helper library.
Update an existing incoming phone number:
var accountSid = 'YOUR_ACCOUNT_NUMBER';
var authToken = 'YOUR_AUTH_TOKEN';
var client = require('twilio')(accountSid, authToken);
client.incomingPhoneNumbers("PHONE_NUMBER_SID").update({
smsUrl: "http://demo.twilio.com/docs/sms.xml"
}, function(err, number) {
if (err) { console.error(err); return }
console.log(number.voiceUrl);
});
When buying the number:
client.incomingPhoneNumbers.create({
friendlyName: "My Company Line",
smsUrl: "http://demo.twilio.com/docs/voice.xml",
phoneNumber: "PHONE_NUMBER_TO_PURCHASE"
}, function(err, number) {
if (err) { console.error(err); return }
console.log(number.sid);
});
It can be done using Optional Parameters
when you update an incoming phone number:
https://www.twilio.com/docs/api/rest/incoming-phone-numbers?code-sample=code-update-an-incomingphonenumber&code-language=curl&code-sdk-version=json
$ curl -XPOST https://api.twilio.com/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/IncomingPhoneNumbers/PN2a0747eba6abf96b7e3c3ff0b4530f6e.json \
-d "VoiceUrl=http://demo.twilio.com/docs/voice.xml" \
-d "SmsUrl=http://demo.twilio.com/docs/sms.xml" \
-u 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token'
or when you create a new incoming phone number:
https://www.twilio.com/docs/api/rest/incoming-phone-numbers?code-sample=code-create-a-new-incomingphonenumber&code-language=curl&code-sdk-version=json
$ curl -XPOST https://api.twilio.com/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/IncomingPhoneNumbers.json \
-d "FriendlyName=My%20Company%20Line" \
-d "SmsUrl=http://demo.twilio.com/docs/sms.xml" \
-d "PhoneNumber=%2B15105647903" \
-d "SmsMethod=GET" \
-u 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token'

Parse + Heroku Query 500 Error

I used Parse's CLI with the new Heroku integration to create the scaffold NodeJS project (parse new).
The example cloud function it gives you is:
// Hello
Parse.Cloud.define('hello', function(request, response) {
response.success('Hello world! ' + (request.params.a + request.params.b));
});
I can hit this route with the following CURL command and everything works fine:
curl -X POST \
-H "X-Parse-Application-Id: b8qPYS4SLSz0WoSWXlWeQosmF2jJPUPydetg3esR" \
-H "X-Parse-REST-API-Key: TOJLbfbNXSQcBdDVnU0MnKVu7SyamQvZmorHL5iD" \
-H "Content-Type: application/json" \
-d '{"a": "Adventurous ", "b": "Parser"}' \
https://api.parse.com/1/functions/hello
But then I added a new Class to my Parse Data, inserted a row, and tried to query & return the results. I keep getting {"code":143,"error":"Invalid webhook response status: 500 Internal Server Error"} as the response.
I'm fairly certain it is not my code that is the problem and am guessing there is some configuration step or something I'm missing.
Here is my modified Parse function:
// Hello
Parse.Cloud.define('hello', function(request, response) {
var query = Parse.Query("Favorites");
query.find({ useMasterKey: true }).then(
function(results) {
response.success('win');
}, function() {
response.error('fail');
});
});
And a picture of my Parse Class with the inserted row:
I have Googled the error and can't find any good answers only poorly worded questions. I'm completely at a loss here. Thanks in advance for your help.
Looks like Parse is wrong initialised on register-webhooks.js post deploy script:
Parse.initialize(process.env.PARSE_APP_ID, "unused", process.env.PARSE_MASTER_KEY);
And without second parameter (JavaScript Key) you can't execute any Parse.Query from cloud functions.
So my solution is:
Add new PARSE_JS_KEY to Heroku Config Variables (value is JavaScript Key from Parse->Settings->Keys)
In server.js file add line:
Parse.initialize(process.env.PARSE_APP_ID, process.env.PARSE_JS_KEY, process.env.PARSE_MASTER_KEY);
before require('./cloud/main.js');
PS: Place process.env.PARSE_JS_KEY directly in register-webhooks.js initializer does not work.

Box api call to fetch the access token is failing in node.js

I wrote a program in node.js to fetch the access token to call the box apis, unfortunately I am getting an error "invalid_client" which is either "client ID or secret are wrong" as per the documentation. I am pretty sure that both client id and secret are correct since it worked fine for me while doing ajax calls from UI.
Here is the piece of code I am using
{{{
if(queryData && queryData.code) {
var code = queryData.code;
var data = {
"grant_type" : 'authorization_code',
"client_id" : 'alpha-numeric-id',
"client_secret" : 'alpha-numeric-secret',
"code": 'actual-code-given-in-redirect-uri'
};
var options = {
'url': 'https://www.box.com/api/oauth2/token',
'proxy': 'http://corporate-proxy-url:port',
'headers': {
'accept': 'application/json',
'accept-language': 'en'
},
'json': data,
'timeout': 5000
};
request.post( options, function ( err, response, body ) {
if ( err ) {
console.log("====error====");
} else {
console.log("====success=====");
console.log(response.statusCode);
console.log(body);
}
} );
}
}}}
It would be helpful if someone could figure out whats wrong in my code.
Thanks in advance.
Looks like you're hitting the wrong URL: No www.box.com/api for any API calls AFAIK
According to the documentation, it's app.box.com/api/oauth2/authorize? for your first OAuth2 call to do the Authorize and api.box.com/oauth2/token for the Token call, and all subsequent API calls. api.box.com/2.0/
So step 1 : Authorize:
GET https://app.box.com/api/oauth2/authorize?response_type=code&client_id=MY_CLIENT_ID&state=security_token%3DKnhMJatFipTAnM0nHlZA
Step 1.5 user logs onto Box, and you get called back by Box...
Step 2: Get your token
curl https://app.box.com/api/oauth2/token \
-d 'grant_type=authorization_code&code={your_code}&client_id={your_client_id}&client_secret={your_client_secret}' \
-X POST
Step 3: Call APIs:
curl https://api.box.com/2.0/folders/FOLDER_ID/items?limit=2&offset=0 \
-H "Authorization: Bearer ACCESS_TOKEN"

Body format for Stripe POST operations

I'm accessing the stripe API directly with the REST API (not using a library) but, surprisingly, I can't find documentation on the appropriate body format post data.
Does Stripe expect JSON or form-encoded pairs?
You need to post raw data like key-value pair. (No Json)
e.g.
key1=value1&key2=value2
Make sure you include following in header
Content-Type = application/x-www-form-urlencoded
Here is the sample of the curl code to Nodejs
I am working on a similar problem
as you know we can't send JSON for the "post" method
it must be URL encoded
here is the sample provided by stripe
https://stripe.com/docs/api/checkout/sessions/create
curl https://api.stripe.com/v1/checkout/sessions \
> -u stripe_key_here: \
> -d success_url="https://example.com/success" \
> -d cancel_url="https://example.com/cancel" \
> -d "payment_method_types[]=card" \
> -d "line_items[][name]=T-shirt" \
> -d "line_items[][description]=Comfortable cotton t-shirt" \
> -d "line_items[][amount]=1500" \
> -d "line_items[][currency]=usd" \
> -d "line_items[][quantity]=2"
-u means authorization which we provide in the headers
-d means body of the url
sample code in node js
const fetch = require("node-fetch");
const stripeKey = process.env.STRIPE_KEY;
async function getCheckoutID() {
try {
const endpoint = "https://api.stripe.com/v1/checkout/sessions";
const query = objToQuery({
success_url: "https://example.com/success",
cancel_url: "https://example.com/cancel",
"payment_method_types[]": "card",
"line_items[][name]": "T-shirt",
"line_items[][description]": "Comfortable cotton t-shirt",
"line_items[][amount]": 1500,
"line_items[][quantity]": 1,
"line_items[][currency]": "usd"
});
// enpoint => "https://www.domin.com/api"
// query => "?key=value&key1=value1"
const URL = `${endpoint}${query}`;
const fetchOpts = {
method: "post",
headers: {
"Authorization": `Bearer ${stripeKey}`,
"Content-Type": "application/x-www-form-urlencoded"
}
}
const checkout = await getJSON(URL, fetchOpts);
console.log("CHECKOUT OBJECT : " , checkout);
return checkout;
}
catch(e) {
console.error(e);
}
}
// hepler functions
// instead of using fetch
// getJSON will make it readable code
async function getJSON(url, options) {
const http = await fetch(url, options);
if (!http.ok) {
console.log(http);
throw new Error("ERROR STATUS IS NOT OK :");
}
return http.json();
}
// convert JS object to url query
// {key:"value" , key1: "value1"} to "key=value&key1=value1"
function objToQuery(obj) {
const query = Object.keys(obj).map( k => `${k}=${obj[k]}`).join("&");
return query.length > 0 ? `?${query}` : "";
}
Form encoded pairs
The docs for cURL provide good examples. They're just feeding form encoded key/value pairs via the -d switch via cURL on the command line. Just make sure you use your test secret key so you don't screw up any live data. Then you can play around all you want.
The returned data is JSON.
Here is an example cURL charge using a test card:
curl https://api.stripe.com/v1/charges -u your_test_key: -d card[number]=4000056655665556 -d card[exp_month]=11 -d card[exp_year]=2020 -d amount=100 -d currency=eur -d description="Stripe cUrl charge test"
Exchange your_test_key with your stripe test key.
Remember to keep the : after your key to not get asked for a password.

Resources