Docusign live account authentication using REST API not working - php

I am new on Docusign. I have developed a application using REST API on PHP language. In demo account everything is working fine. But in live account does not working. Error is calling webservice and status is 0. I tried many way but can't solve. Please help me. My code for authentication is given below.
$integratorKey = 'xxxxxx';
$email = 'xxxx';
$password = 'xxxx';
// construct the authentication header:
$header = "<DocuSignCredentials><Username>" . $email . "</Username><Password>" . $password . "</Password><IntegratorKey>" . $integratorKey . "</IntegratorKey></DocuSignCredentials>";
$url = "https://www.docusign.net/restapi/v2/login_information";
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array("X-DocuSign-Authentication: $header"));
$json_response = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
//echo $status;
if ( $status != 200 ) {
echo "error calling webservice, status is:" . $status;
exit(-1);
}
$response = json_decode($json_response, true);
$accountId = $response["loginAccounts"][0]["accountId"];
$baseUrl = $response["loginAccounts"][0]["baseUrl"];
curl_close($curl);

Have you completed the DocuSign API Certification process yet? Your integration will not work against a Production DocuSign account until you've completed the API Certification process and DocuSign has approved your Integrator Key for use in the Production environment. (The main purpose of the certification process is for DocuSign to ensure that your integration isn't doing anything that would be harmful to the Production environment, and to ensure that you're able to produce API request/response information from your app, in case you ever need help from DocuSign support in the future -- once you "pass/complete" certification, DocuSign will enable your Integrator Key for use in Production.)
The DocuSign Developer Center (https://www.docusign.com/developer-center) contains information about the API Certification process. In particular, check out the links in "Go Live" section:
The Go Live - Overview page is a good starting point: https://www.docusign.com/developer-center/go-live/overview

Related

Facebook messenger API throws error after deprecation

I'm suddenyly getting errors in my facebook messenger service that sends messages from my website to a facebook chat. The error is
"type":"OAuthException","code":10,"error_subcode":2018278,"fbtrace_id":"AJSz9EQPjUFjShr0QK34yEr"}} {"error":{"message":"(#10) This message is sent outside of allowed window. Learn more about the new policy here:
I have seen this note on the facebook API pages On March 4th, 2020 we introduced Messenger webhook versioning with v6.0 having the first versioned change for the messages field.
Here is my code for sending a message
`
$url = 'https://graph.facebook.com/v2.6/me/messages?access_token=';
/* initialize curl */
$ch = curl_init($url);
/* prepare response */
$jsonData = '{
"recipient":{
"id":"' . $sender . '"
},
"message":{
"text":"' . $message . '"
}
}';
/* curl setting to send a json post data */
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
if (!empty($message)) {
$result = curl_exec($ch); // user will get the message
}`
Can someone explain what FB has changed to make this not work and what the new alternative is or how I can correct my own code.
Thanks
https://developers.facebook.com/docs/messenger-platform/changelog/

Generate Pinterest access token dynamically with PHP API

I developed a Pinterest plugin for WordPress users. Now, I am facing token generation problem with Pinterest API. I have set and configure accordingly to API docs. In Step 1 you get an access code and in Step 2, you need to request for access token with the help of access code. Step 1 going to succeed but in Step 2 throwing error response.
I already asked to Pinterest Support through email but they are saying:
We're a small team right now and we can't offer development support or
consult for the API just yet. For more support around using our API,
we encourage you to use developer resources like Stack Overflow.
The code I did:
I already made an APP and used the give App ID and Secret, and redirect URL also set in APP same below:
$client_id = "&client_id=496200555XXXXXXXX1778834";
$client_secret = "&client_secret=48d62d7c21aa432bb5320c0aeXXXXXXXXXXX75933f6295db1bae61ffa66ca31";
$authorization_url = "https://api.pinterest.com/oauth/?";
$response_type = "response_type=code";
$state = "&state=weblizar_app";
$scope = "&scope=read_public,read_relationships";
$redirect_uri = "&redirect_uri=https://weblizar.com/pinterest-access-token.php";
$access_token_url = "https://api.pinterest.com/v1/oauth/token?";
$grant_type = "grant_type=authorization_code";
// Step 1: get authorization code
$access_code_url = $authorization_url . $response_type . $redirect_uri . $client_id . $scope . $state;
echo "<a href=$access_code_url>Get Authorization Code</a>";
// Step 2: exchange the access token
if(isset($_GET['code'])) {
$authorization_code = $_GET['code'];
$access_code_url = $access_token_url . $grant_type . $client_id . $client_secret ."&code=" .$authorization_code; echo "<br>";
echo "Curl post URL - "; echo "<br>";
$ch = curl_init();
echo $url = $access_code_url;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_HTTPGET, TRUE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$result = trim(curl_exec($ch));
curl_close($ch);
echo "Curl Post Response"; echo "<br>";
echo "<pre>";
print_r($result);
echo "<pre>";
}
Response Returned After Step 2
{
"message": "405: Method Not Allowed",
"type": "http"
}
As everyone knows Pinterest token generation URL no more available for users or closed down.
You can test, the code is live on site: https://weblizar.com/pinterest-access-token.php
Any kind of help really appreciated. Thanks in advance.

Docusign DEMO account authentication using REST API not working

I am new to Docusign. I have a developer account and tryging to use REST API with PHP to establish connection with the API but i have stumble across and error, the Error is calling webservice and status is 0. Below is my code:
$username = "xxxxxx";
$password = "xxxxxx";
$integrator_key = "xxxxxxx";
// construct the authentication header:
$header = "<DocuSignCredentials><Username>" . $email . "</Username><Password>" . $password . "</Password><IntegratorKey>" . $integratorKey . "</IntegratorKey></DocuSignCredentials>";
$url = "https://demo.docusign.net/restapi/v2/login_information";
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array("X-DocuSign-Authentication: $header"));
$json_response = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
//echo $status;
if ( $status != 200 ) {
echo "error calling webservice, status is:" . $status;
exit(-1);
}
$response = json_decode($json_response, true);
$accountId = $response["loginAccounts"][0]["accountId"];
$baseUrl = $response["loginAccounts"][0]["baseUrl"];
curl_close($curl);
This is most likely caused by security software, firewall, or other network interference on your (client) side since your request works just fine when you send through the API Explorer. I recommend tracing your request through your network to see where it is getting held up.

Google Drive OAuth => response=Moved Temporarily

I'm trying to write a small PHP code that should be able to authenticate itself to a Google Account and then upload a file to its Google Drive.
This process should be done in two steps:
send the authentication request and get in exchange the authorization code
POST the authorization code and get in exchange the access token that should be used to send other requests (eq: a file upload) to the Google Drive
Note that by using the Google Client Library everything works smoothly.
What I want to achieve is to NOT use the Google Client Library but instead to use the simple authentication steps described here.
By using these authentication steps mentioned earlier I send a request:
https://accounts.google.com/o/oauth2/auth?scope=email%20profile&redirect_uri=http://example.com&response_type=code&client_id=[my-client-id]
and in exchange the redirected page should contain the "code=xxxx" parameter, like:
http://example.com?code=xxx
where xxx is the authorization code prepended by Google to the redirect_uri mentioned above.
The problem is that the Google returns an error message like Moved Temporarily and also provides a link "The document has moved here.". If I click that link then everything works just fine.
But I don't want the user intervention because this code works at the server level and not at the client level.
How to solve this? Please don't answer with "use the Google Client Library!" because I've already said that by doing so it will work but I don't want the Google Client Library dependency!
My PHP code is:
$CLIENT_ID = '[the client ID from Google Developer Console]';
$CLIENT_SECRET = '[the client secret from Google Developer Console]';
$REDIRECT_URI = 'http' . ($_SERVER['SERVER_PORT'] == 80 ? '' : 's') . '://' . $_SERVER['SERVER_NAME'] . $_SERVER['SCRIPT_NAME'];
$ch = curl_init();
if (isset($_GET['code']))
{
$url = 'https://accounts.google.com/o/oauth2/token';
$post_fields = 'code=' . $_GET['code'] . '&client_id=' . $CLIENT_ID . '&client_secret=' . $CLIENT_SECRET . '&redirect_uri='
. $REDIRECT_URI . '&grant_type=authorization_code';
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER,
array('Host:accounts.google.com', 'Content-Type:application/x-www-form-urlencoded', 'Content-Length:' . strlen($post_fields))
);
}
else
{
$url = sprintf('https://accounts.google.com/o/oauth2/auth?scope=email%%20profile&redirect_uri=%s&response_type=code&client_id=%s',
$REDIRECT_URI, $CLIENT_ID
);
}
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
$result = curl_exec($ch);
$error_no = curl_errno($ch);
curl_close($ch);
echo $result;
?>
The solution for this kind of problem is:
don't call the first request via CURL but by changing the document Location
Also change this block:
...
else
{
$url = sprintf('https://accounts.google.com/o/oauth2/auth?scope=email%%20profile&redirect_uri=%s&response_type=code&client_id=%s',$REDIRECT_URI, $CLIENT_ID);
}
with this one:
...
else
{
$url = sprintf('https://accounts.google.com/o/oauth2/auth?scope=email%%20profile&redirect_uri=%s&response_type=code&client_id=%s',$REDIRECT_URI, $CLIENT_ID);
header('Location:'.$url);
}

Salesforce php REST API with automatic login

I am dragging my hair out over this one right now. I have followed the following example:
http://developer.force.com/cookbook/recipe/interact-with-the-forcecom-rest-api-from-php
but here the user is being sent to the login form and needs to login. Instead I would like to post that data in my code and not have the user login but my app do that automatically.
If anyone could post an example on how to do that with oAuth I would really appreciate it as I am not eager on using that bloated SOAP implementation.
Cheers guys!
It seems after some more tinkering my attempts have been a success::
$loginurl = "https://login.salesforce.com/services/oauth2/token";
$params = "grant_type=password"
. "&client_id=" . CLIENT_ID
. "&client_secret=" . CLIENT_SECRET
. "&username=" . USER_NAME
. "&password=" . PASSWORD;
$curl = curl_init($loginurl);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $params);
$json_response = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ( $status != 200 ) {
die("Error: call to URL failed with status $status, response $json_response, curl_error " . curl_error($curl) . ", curl_errno " . curl_errno($curl));
}
curl_close($curl);
echo $json_response;
Now all that is left to do is store the
access_token & instance_url from that response into a session var
and work away on our objects.
I hope the above helps someone else with similar issues.
Answer for 2018:
https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/intro_understanding_username_password_oauth_flow.htm
Make an POST request with:
grant_type: Must be password for this authentication flow.
client_id: The Consumer Key from the connected app definition.
client_secret: The Consumer Secret from the connected app definition. Required unless the Require Secret for Web Server Flow setting is not enabled in the connected app definition.
username: End-user’s username.
password: End-user’s password.
Example:
grant_type=password&client_id=3MVG9lKcPoNINVBIPJjdw1J9LLM82Hn
FVVX19KY1uA5mu0QqEWhqKpoW3svG3XHrXDiCQjK1mdgAvhCscA9GE&client_secret=
1955279925675241571&username=testuser%40salesforce.com&password=mypassword123456
See above link for more details.

Categories