I am using sendgrid unsub api's for who does not want the campaign e-mails.
But when I send request for unsub the email, the adress goes to global unsub list.
Here is my php code
$parameters = array(
"api_user" => self::EMAIL_USER_NAME,
"api_key" => self::EMAIL_PASSWORD,
"email" => $email,
);
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $parameters);
$json_response = curl_exec($curl);
How to specify an unsub group id for api call?
It looks like you're using the V2 API right now. Unsub groups are only available via the V3 API, using the suppressions endpoint.
In V3, you POST addresses to the resource URL of the unsub group, for example, https://api.sendgrid.com/v3/asm/groups/:group_id/suppressions
Keep in mind that to use V3 you'll need to use the updated authentication schema that uses an Authorization header and a real API key.
Related
I am developing a prestashop sso module using keycloak, to check if a user is already logged in or not with the keycloak interface, I used the keycloak.js script:
const config = { url: urlKeycloak, realm: realm, clientId: clientId, "enable-cors": true, "cors-max-age": 100, "cors-allowed-methods": "POST, PUT, DELETE, GET"};
const keycloak = new Keycloak(config);
keycloak.init({onLoad: 'check-sso', checkLoginIframe: false}).success((authenticated) => {
console.log(authenticated);
}).catch(function(e) {
alert('failed to initialize');
console.log(e);
});
It works perfectly.
Now I want to login to keycloak through the prestashop login form (username and password) (I don't want to redirect to the login page of keycloak), so I used the keycloak REST API to get access_token ..., but my js script does not detect my login on keycloak, a priori It's missing brosser sessions of keycloak. Is there a keycloak REST api which saves sessions through the access_token?
Here is my connection code through the login form
$data['username'] = 'username';
$data['password'] = 'password';
$data['grant_type'] = "password";
$data['client_id'] = 'clientId';
$data['client_secret'] = 'client_secret';
$link = url_keycloak/realms/realm/protocol/openid-connect/token";
$curl = curl_init();
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl, CURLOPT_URL, $url);
$headers = array(
'Content-Type: application/x-www-form-urlencoded',
);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
// EXECUTE:
$result = curl_exec($curl);
curl_close($curl);
I have a Lambda function on AWS for which I have created a trigger with Security. I set the url ($url) to be the API endpoint listed in the "triggers" section of the lambda function, and the x-api-key (instead of my_api_key below) to be the one listed in the trigger "API key".
However, if I try to make a simple call to the lambda function like so:
$url = "https://abcd1234.execute-api.us-east-2.amazonaws.com/default/lambda_function_name";
$header = array(
"Content-Type" => "application/json",
"Accept" => "application/json",
"x-api-key" => "my_api_key",
);
$data = array(
"email_address" => $_POST['email'],
);
$curl = curl_init();
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HTTPHEADER, json_encode($header));
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data));
$result = curl_exec($curl);
curl_close($curl);
I obtain the response "Forbidden".
What is the issue here?
Is there some AWS configuration I need to change?
Or is the syntax or place to add the x-api-key wrong?
Thanks in advance!
Maithreya
I am assuming you are connecting to AWS API Gateway. Your endpoint URL must include the stage and resource, i.e.:
https://abcd1234.execute-api.us-west-2.amazonaws.com/prod/send_email_alert
Calling the API gateway base endpoint URL will result in this error.
I am using PHP to get user information from paypal identity API, but unfortunately i only get user_id in response. I need email and payer_id in response. I have read the documentation , according to that i am supposed to receive multiple parameters in response, but i am receiving only user_id. I have enabled all the scopes in App permissions. here is the documentation getuserinfo.
here is my code to get user info (I am passing $access_token into this function). I am using sandbox credentials.
$api_url = 'https://api.sandbox.paypal.com/v1/oauth2/token/userinfo?schema=openid';//sandbox
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $api_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Bearer '. $access_token, 'Content-Type: application/json'));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
$data = json_decode(curl_exec($ch), true);
//dd($data);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if($http_code == 200)
return $data;
else if($http_code == 404)
return false;
else
return false;
my response :
array:1 [▼ "user_id" => "https://www.paypal.com/webapps/auth/identity/user/HdoaS1nMgR_Ltt5mBTv4mRvC9P1wUrWt2NlOVH2e_3w"]
This is most likely your issue: "The attributes returned depend on the scopes configured for the REST app"
https://developer.paypal.com/docs/integration/paypal-here/sandbox-testing/configuring-accounts/#create-a-rest-application
Log In with PayPal. When you enable Log In with PayPal, click Advanced Options and select Personal Information and Address Information, which are disabled by default.
I am a beginner with building a rest api and authentication.
I've just been reading the following and explains a very simple setup:
laravel 5 rest api basic authentication
At the bottom the article explains not to send usernames and password with headers or in the url.
My question is basicly: can anyone give me an example how to use a cUrl request with the example above?
For example:
$service_url = 'http://example.com/api/conversations';
$curl = curl_init($service_url);
$curl_post_data = array(
'user' => 'user#user.com',
'passw' => '1234'
);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $curl_post_data);
$curl_response = curl_exec($curl);
curl_close($curl);
Laravel is shipped with Guzzle – an advanced HTTP client library. It's probably more reasonable to use that than a low-level cURL.
To do basic auth with Guzzle:
$client = new GuzzleHttp\Client();
$response = $client->post('http://example.com/api/conversations', [
'auth' => [
'user#user.com',
'1234'
]
]);
The response will be in $response->getBody();
If your target endpoint uses SSL – it's not too bad sending the credentials in the headers, but the trendy way is to use temporary tokens (eg. API key or OAuth access token).
In addition to the accepted answer, you can also create a generic function to handle all your curl requests.
You can use the following function to call external webservices and return the data/authentication information.
/*=============================================
* Call External Webservices using CURL
*
* #param $requestURL, $header -> (OPTIONAL)
* #return json
#=============================================*/
public function curlRequest($requestURL, $headers = array())
{
$getData = curl_init($requestURL);
curl_setopt($getData, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($getData, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($getData, CURLOPT_SSL_VERIFYHOST, false);
if (count($headers) != 0) {
curl_setopt($getData, CURLOPT_HTTPHEADER, $headers);
}
$response = curl_exec($getData);
return json_decode($response);
}
Use case specific example to use the above function for authentication:
$requestURL = 'http://www.example.com/api/userLogin';
$userAuthInfo = [
'email'=> 'example#example.com',
'password'=>'123456'
];
$result = $this->curlRequest($requestURL, $userAuthInfo);
dd($result); //Print the Result of the Authentication request
I'm in the final stages of converting our site over to Graph API from the Rest API.
The last piece I'm missing is the old "revokeApplication" call used for when a user chooses to "remove connection" from our site.
Despite my desires to completely remove the Rest API, I thought I might just fire it up for this, but it requires a session key -- something no longer stored in the Graph API.
Anybody have any ideas?
I figured it out. I'll leave it here for those that need to know...
The old rest api (including the revokeApplication api) can still be accessed, now with the new OAuth access_token. Just use this url: https://api.facebook.com/method/METHODNAME
For this particular call, it's a POST:
$ch = curl_init();
curl_setopt($ch, CURLOPT_POSTFIELDS, 'access_token='.$users_access_token);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_URL, 'https://api.facebook.com/method/auth.revokeAuthorization');
$output = curl_exec($ch);
curl_close($ch);
More info here:
http://developers.facebook.com/docs/reference/rest/
You can do it with the new graph API :
$facebook = new Facebook(array(
'appId' => $fbconfig['appid'],
'secret' => $fbconfig['secret'],
'cookie' => true
));
$revoked = $facebook->api("/me/permissions", "DELETE");
$revoked is a boolean.