How to get all chats in website using zendesk chat api - zendesk

There is any way to get all chats from zendesk to website.
I am using zendesk api for get all chats:
curl https://www.zopim.com/api/v2/chats \ -v -u {email_address}:{password}
Here Is my code :
public function getChat_messages(){
$sUrl = "https://www.zopim.com/api/v2/chats";
$authorization = "Authorization: Bearer a362fb582520105c720000631000d6f6f81111f0c95489b9673e722f5c59bf0";
$key= "-v -u email:password";
if (is_resource($rCh = curl_init($sUrl))) {
curl_setopt($rCh, CURLOPT_HTTPHEADER, array('Content-Type: application/json' , 'Authorization: Bearer a362fb582520105c720000631000d6f6f81111f0c95489b9673e722f5c59bf0',
'-v -u email:password',
));
curl_setopt($rCh, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($rCh, CURLOPT_TIMEOUT, 3);
$arrResult = curl_exec($rCh);
$arrResult = explode("\n", $arrResult);
$response = curl_exec($rCh);
$err = curl_error($rCh);
curl_close($rCh);
}
print_r($response);
}
Help will be appreciated..
Thanks.. :)

You did well but there is a little mistake.
$sUrl = "https://www.{your_domain_name}.com/api/v2/chats";
You just copy and paste the line that is why you are getting error.
zopim is not your domain name use your domain name instead of zopim

Related

Etsy oAuth 2.0 flow, Etsy API V3 unable to get Access Token

I was able to get an authorisation code but I have problems with getting Access Token.
While making a Request to get an Access Token, Every time I get Fatal error: Uncaught Exception: HTTP 404 {"error": "Resource not found"}
Here is my request:
$url = "https://api.etsy.com/v3/public/oauth/token?grant_type=authorization_code&client_id={MY_ Etsy_App_ API_ Key }&redirect_uri={MY_REDIRECT_URL}&code=".$code."&code_verifier=".$code_verifier;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$headers = array(
'x-api-key: ={ MY_ Etsy_App_ API_ Key } ',
);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response_body = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if (intval($status) != 200) throw new Exception("HTTP $status\n$response_body");
Where can be a mistake?
You're making a GET request to the token endpoint, but you should be making a POST request and sending the parameters in the request body.
curl_setopt($curl, CURLOPT_POST, true);
$headers = array(
"Content-Type: application/x-www-form-urlencoded",
);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
$data = "grant_type=authorization_code&code=".$code."&redirect_uri="...
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
I think you don't need the x-api-key header when making a call to the token endpoint.

Authy API Webhook - Invalid Signature response

I'm trying to create a Webhook according to the documentation page:
https://www.twilio.com/docs/authy/api/webhooks
My curl call looks like this:
curl -X POST "https://api.authy.com/dashboard/json/application/webhooks" \
-d name="gridzdev_test" \
-d app_api_key="7N0..." \
-d access_key="4za..." \
-d url="https://some-random-string.ngrok.io/api/2fa/webhook" \
-d events="user_added" \
-H "X-Authy-Signature-Nonce: FiNwPdKZci4l3LEn" \
-H "X-Authy-Signature: feYEERfOSoWCB3ml5cnZFWs5xhc1sPeiWguhlJnokKQ="
Unfortunately, the response I receive is not what I expect:
{"message":"Invalid signature.","success":false,"error_code":"60000"}
The PHP code I'm using to generate signature:
public function handle() {
$url = 'https://api.authy.com/dashboard/json/application/webhooks';
$http_method = 'POST';
$params = 'id=53';
$nonce = 'FiNwPdKZci4l3LEn';
$signing_key = 'pr...';
$data = $nonce . '|' . $http_method . '|' . $url . '|' . $params;
$digest = hash_hmac('sha256', $data, $signing_key, true); // TODO tried with binary = false, but no joy
$digest_in_base64 = base64_encode($digest);
$this->info("nonce = $nonce");
$this->info("signature = $digest_in_base64");
}

How do I specify data-binary in Titanium Appcelerator?

I am trying to use the Dropbox API to upload a file. Here is the documentation from Dropbox:
curl -X POST https://content.dropboxapi.com/2/files/upload \
--header "Authorization: Bearer <get access token>" \
--header "Dropbox-API-Arg: {\"path\": \"/Homework/math/Matrices.txt\",\"mode\": \"add\",\"autorename\": true,\"mute\": false}" \
--header "Content-Type: application/octet-stream" \
--data-binary #local_file.txt
I have this in my Appcelerator project:
var xhr = Titanium.Network.createHTTPClient();
xhr.onload = function(e) {
//My function
};
xhr.open('POST','https://content.dropboxapi.com/2/files/upload');
xhr.setRequestHeader('Authorization', 'My Key');
xhr.setRequestHeader('Content-Type', 'application/octet-stream');
xhr.setRequestHeader('Dropbox-API-Arg', '{"path":"/my_path/file.txt","mode":{".tag":"add"}}');
But I can't figure out how to send the data-binary argument. With my current code I can create a file in my Dropbox folder, but is just an empty file.
From http://docs.appcelerator.com/platform/latest/#!/api/Titanium.Network.HTTPClient, it looks like you just pass it into xhr.send(). You can pass a string, an object (which gets form-encoded), or a Titanium.Blob.
(Disclaimer: I've never used Appcelerator, so this is just what I surmise from reading the documentation.)
I figure out a way to do that. In my case I just need to upload a simple data structure, so I am using a JSON object:
var xhr = Titanium.Network.createHTTPClient();
xhr.onload = function(e) {
//My function
};
xhr.open('POST','https://content.dropboxapi.com/2/files/upload');
xhr.setRequestHeader('Authorization', 'My Key');
xhr.setRequestHeader('Content-Type', 'application/octet-stream');
xhr.setRequestHeader('Dropbox-API-Arg', '{"path":"/my_path/file.txt","mode":{".tag":"add"}}');
var my_json = {
"item1" : "content1"
};
xhr.send(JSON.stringify(my_json));
I still can't send a BLOB (like a picture from the phone gallery), but it works if you pass the path of the file:
var my_path = Titanium.Filesystem.getFile(Titanium.Filesystem.tempDirectory,'my_folder');
var newFile = Titanium.Filesystem.getFile(my_path.nativePath,'file.txt');
newFile.createFile();
newFile.write('Content of my text file');
var params = {"data-binary" : newFile};
xhr.send(params);

Can I schedule a Jenkins Build without CRON or REST API?

To schedule a build in Jenkins I need to add a "cron" parameter then all works well. But I have a lot of donkey users and they didn't know how to schedule with cron.
Is there a way to schedule a Jenkins build without the API itself (http://jenkins/job/jobname/build?delay=4000 I don't want this) or cron? Maybe some Jenkins Plugin...
Solved it this way:
<?php
if($_POST) {
$fields = array(
"POST_PARAMETERS" => $_POST['params']
);
$delay = (int) $_POST['delay'];
$username = "my_username";
$password = "my_password";
$token = "MY_JENKINS_TOKEN_NAME";
$job = "JOB_NAME";
$url = "http://jenkins_host/jenkins/job/".$job."/buildWithParameters?token=".$token."&delay=".$delay;
$process = curl_init($url);
curl_setopt($process, CURLOPT_HEADER, 1);
curl_setopt($process, CURLOPT_USERPWD, $username . ":" . $password);
curl_setopt($process, CURLOPT_TIMEOUT, 30);
curl_setopt($process, CURLOPT_POST, 1);
curl_setopt($process, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($process, CURLOPT_POSTFIELDS, http_build_query($fields));
curl_setopt($process, CURLOPT_POST, count($fields));
$return = curl_exec($process);
echo http_build_query($fields);
echo curl_error($process);
curl_close($process);
die;
}
?>
I give the JOB_NAME and the build parameters and it work well. cURL did the trick for me with the authorization token.
Thanks everyone who tried to help.

CURL - no url set

$param = 'get.php';
$url = 'http://mysite.org/'. $param;
$__post = 'option=1&option2=225';
mysite.org/get.php - exists for 100%, when I open them in browser everything works.
$c = curl_init();
curl_setopt($c, CURLOPT_URL, $url);
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
curl_setopt($c, CURLOPT_POST, true);
curl_setopt($c, CURLOPT_POSTFIELDS, $__post);
$result = curl_exec($c);
curl_close($c);
print_r($result); // show 404 o_O
I test it using sniffer and CURL pass URL :
http://mysite.org
not
http://mysite.org/get.php
when I do somethink like that :
curl_setopt($c, CURLOPT_URL,'http://mysite.org/get.php');
everything works fine... so... please help me :D What I do wrong, certainly it is a small error but I don't see where he is :/

Resources