I m looking to get bitly clicks using it api v4 - php

I am trying to get clicks per link from : https://api-ssl.bitly.com/v4/bitlinks/{bitlink}/clicks/summary i am not getting any result and getting 404 instead of getting clicks back. I am using v4 api of bitly.
I have tried through curl but i m not getting anything.
$url = 'https://api-ssl.bitly.com/v4/bitlinks';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(['long_url' => "https://booktennislessons.com/app/Frontend/registerProgram/165?data="]));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"Authorization: Bearer $code",
"Content-Type: application/json"
]);
$arr_result = json_decode(curl_exec($ch));
echo $arr_result->link;
echo "<pre>";
print_r($arr_result);
this code works fine for getting bitly but not getting the clicks from it. its a post request and i need to send a get request .
i m getting 404 but it should comes up with
{
"units": 0,
"unit_reference": "string",
"unit": "minute",
"link_clicks": [
{}
]
}```

Related

ORO CRM API - No access to this type of entities error

I'm trying to add a user using the POST api/user api request and get the following response (via PHP):
403 - access denied exception - No access to this type of entities
I'm not sure what this means. I'm using the example data set for this with the following php code - just trying to get the basic functionality working:
$ch = curl_init();
$header = array();
$post = array(
'data' => array(
"type"=>"users",
"attributes"=>array(
"username"=>"testuser",
"email"=> "testuser#oroinc.com",
"firstName"=> "Bob",
"lastName"=> "Fedeson",
"password"=> "Password000!"
),
"relationships"=>array(
"owner"=>array(
"data"=>array(
"type"=> "businessunits",
"id"=> "1"
)
)
),
)
);
$header[] = 'Accept: application/vnd.api+json';
$header[] = 'Authorization: WSSE profile="UsernameToken"';
$header[] = $wsseHeader;
curl_setopt($ch, CURLOPT_URL,"https://[full url here]/api/users");
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_HTTPHEADER,$header);
curl_setopt($ch, CURLOPT_POST,true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$rest = curl_exec($ch);
if($rest === false)
{
echo 'Curl error: ' . curl_error($ch);
}else{
$rest = json_decode($rest, true);
echo '<pre>';
var_dump($rest);
echo '</pre>';
}
403 - access denied exception means that your user has not enough access permissions. The server understood the request but is refusing to fulfill it. The authorization will not help and the request SHOULD NOT be repeated.
To grant access to add new entity objects you should set "Create" permission of your entity to the required level (global/.../user) in the "System/User Management/Roles"

Google Mybusiness API getLocatiosn returns empty

I got a verified location in google mybusiness but when i use the API, it returns an empty array [] I am using this endpoint. I am using laravel 6 and curl library for HTTP requests in this project.
'https://mybusiness.googleapis.com/v4/accounts/117177930435384486747/locations'
Here is my whole controller function
public function getLocations(Request $request){
$url = 'https://mybusiness.googleapis.com/v4/accounts/'.$request->account_id.'/locations:batchGet';
$headers = array(
'Content-Type: application/json',
'Authorization: Bearer '.$request->bearer_token
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close ($ch);
return response()->json(json_decode($result,true));
}
What did I miss? I already got the account info by using this endpoint
https://mybusiness.googleapis.com/v4/accounts and it got me a response of
{
"accounts": [
{
"name": "accounts/117177930435384486747",
"accountName": "Michael koh",
"type": "PERSONAL",
"state": {
"status": "UNVERIFIED",
"vettedStatus": "NOT_VETTED"
},
"profilePhotoUrl": "//lh6.googleusercontent.com/-Jv5Xr7SXjuE/AAAAAAAAAAI/AAAAAAAAAAA/QryQ_2-Mjqo/s132-mo/photo.jpg"
}
]
}
In the response, it says not verified. But when i go to google mybusiness UI. I got this when i click manage location. Seems weird because it shows verified.
PS:
I tried getting the location by calling this endpoint GET https://mybusiness.googleapis.com/v4/{parent=accounts/*}/locations but I got an empty array

Razorpay x Api call BAD_REQUEST_ERROR using Laravel

I am trying to integrate razorpay x api for creating contacts and this is the sample api request data from razorpay. reference_id and notes are optional.
curl -u <YOUR_KEY>:<YOUR_SECRET> \
-X POST https://api.razorpay.com/v1/contacts \
-H "Content-Type: application/json" \
-d '{
"name":"Gaurav Kumar",
"email":"gaurav.kumar#example.com",
"contact":"9123456789",
"type":"employee",
"reference_id":"Acme Contact ID 12345",
"notes":{
"notes_key_1":"Tea, Earl Grey, Hot",
"notes_key_2":"Tea, Earl Grey… decaf."
}
}'
and below is my curl function data sent to razorpay.
$user=User::find($request->input('user_id'));
$payload= '{
"name":"'.$user->name.'",
"email":"'.$user->email.'",
"contact":"'.$user->mobile_number.'"
"type":"customer"
}';
$key="test_key";
$secret="secret_key";
$url = 'https://api.razorpay.com/v1/contacts';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type:application/json']);
curl_setopt($ch, CURLOPT_USERPWD, $key . ":" . $secret);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
print_r($result);
curl_close($ch);
I am getting response as name field is required, eve though I have sent all the request fields in the request parameter. Please suggest me if my curl function is correct or not. below is the response from api call
{
"error":
{
"code": "BAD_REQUEST_ERROR",
"description": "The name field is required.",
"metadata": {},
"field": "name"
}
}
Please specify the request method:
curl_setopt($ch, CURLOPT_POST, 1);

How can I create a form, and create a task on a ClickUp task

For few days I am trying to use the ClickUp API. The goal is:
We have a form, and when the form is submitted, it creates a task on a space on ClickUp.
It is a PHP form, and even with the API Doc here, I am not able to understand how it is working.
I found this: https://jsapi.apiary.io/apis/clickup20/reference/0/tasks/create-task.html
But it requires some access token, from the user, but normally, It's not supposed to work like that.
Here the script that I have taken from the doc:
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.clickup.com/api/v2/list/17229593/task");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, "{
\"name\": \"New Task Name\",
\"content\": \"New Task Content\",
\"assignees\": [
183
],
\"tags\": [
\"tag name 1\"
],
\"status\": \"Open\",
\"priority\": 3,
\"due_date\": 1508369194377,
\"due_date_time\": false,
\"time_estimate\": 8640000,
\"start_date\": 1567780450202,
\"start_date_time\": false,
\"notify_all\": true,
\"parent\": null,
\"custom_fields\": [
{
\"id\": \"0a52c486-5f05-403b-b4fd-c512ff05131c\",
\"value\": 23
},
{
\"id\": \"03efda77-c7a0-42d3-8afd-fd546353c2f5\",
\"value\": \"Text field input\"
}
]
}");
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Authorization: "access_token"",
"Content-Type: application/json"
));
$response = curl_exec($ch);
curl_close($ch);
var_dump($response);
When I try that, I get the error 500, and when I go to the API's link, I get an Auth problem.
Is someone know something about this API?

Sending post JSON to an api - no output

I'm working with a new API and I'm trying to understand how to correctly login and send post requests to the api.
Here are some screenshots:
Also , should this authentication be done every time a request is sent or ??(it says something about a token every 8 hours in the notes)
Here is what I did so far but I'm getting no output from that print_r(probably because I haven't authenticated as shown in the notes(Something I don't know how to do correctly):
$data_string = '{
"nameOnCard":"Johnny",
"userDetail": {
"lastName":"Smith",
"firstName":"John",
"middleInitial":"xx",
"dateOfBirth":"1975-02-28",
"addressLine1":"222333 PEACHTREE PLACE",
"city":"Winchester",
"zipCode":"GU14 7JF",
"country":"GB",
"mobileNumber":"2071234567",
"landlineNumber":"57647564234",
"email":"demouser#mailinator.com",
"currencyCode":"EUR",
"externalReferenceId":"WC34930",
"registeredFromIp":"10.10.10.10",
"acceptTermsAndConditions": true,
"acceptEsign" : true
},
"channelType": "1",
"cardProgramId": "0",
"localeTime": "2013-06-04T00:00:00.000+05:00",
"refId": "1",
"dlvAddress": {
"addressLineOne":"222333 DELIVERY PLACE",
"city":"Winchester",
"zipCode":"GU14 7JF",
"country":"GB"
}
}';
$ch = curl_init('https://wcapi.wavecrest.in/apisandbox/cards');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Developerid: xxxxxxxxxx',
'Developerpassword: xxxxxxx',
'X-Method-Override: login',
'Content-Length: ' . strlen($data_string))
);
$result = curl_exec($ch);
print_r($result);
Would appreciate if anyone can help me, thanks!
EDIT: other post got inactive , editing it wouldn't have helped me.

Categories