get curl request to eBay Post Order API giving empty string (PHP) - php

GET /post-order/v2/casemanagement/{caseId} call of eBay Post Order API giving an empty string. Can anyone clear out where does my code go wrong? Am I passing the headers correctly? Especially is the syntax of authorization correct?
<?php
error_reporting(E_ALL); // Turn on all errors, warnings and notices for easier debugging
//Seller Authorization Token
$userAuthToken= 'Authorization:TOKEN abc123';
//Endpoint URL to Use
$url = "https://api.ebay.com/post-order/v2/casemanagement/xyz";
//Initializle cURL
$connection = curl_init();
//Set Endpoint URL
curl_setopt($connection,CURLOPT_URL,$url);
//Set HTTP Method
curl_setopt($connection, CURLOPT_HTTPGET, true);
//Create Array of Required Headers
$headers = array();
$headers[] = $userAuthToken;
$headers[] = 'Content-Type:application/json';
$headers[] = 'X-EBAY-C-MARKETPLACE-ID:EBAY-DE';
//var_dump($headers);
//set the headers using the array of headers
curl_setopt($connection,CURLOPT_HTTPHEADER,$headers);
//set it to return the transfer as a string from curl_exec
curl_setopt($connection,CURLOPT_RETURNTRANSFER,1);
//stop CURL from verifying the peer's certificate
curl_setopt($connection, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($connection, CURLOPT_SSL_VERIFYHOST, 0);
//Execute the Request
$response = curl_exec($connection);
//close the connection
curl_close($connection);
var_dump($response);

Try this code it is working fine for me.
<?php
// Your ID and token
$authToken = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
// The data to send to the API
$post_data = json_encode(array("legacyOrderId"=>"110181400870-27973775001"));
$url = 'https://api.sandbox.ebay.com/post-order/v2/cancellation/check_eligibility';
//Setup cURL
$header = array(
'Accept: application/json',
'Authorization: TOKEN '.$authToken,
'Content-Type: application/json',
'X-EBAY-C-MARKETPLACE-ID: EBAY-UK'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
if(curl_errno($ch)){
echo "ERROR:".curl_error($ch);
}
curl_close($ch);
echo json_decode($response,true);
?>
Response:
Array
(
[legacyOrderId] => 110181400870-27973775001
[eligible] => 1
[failureReason] => Array
(
)
[itemEligibilityResult] => Array
(
[0] => Array
(
[itemId] => 110181400870
[transactionId] => 34573775001
[eligible] => 1
[failureReason] => Array
(
)
)
)
[eligibleCancelReason] => Array
(
[0] => OUT_OF_STOCK_OR_CANNOT_FULFILL
[1] => BUYER_CANCEL_OR_ADDRESS_ISSUE
)
)

ADD
curl_setopt($connection, CURLOPT_HEADER, 1);
To return the headers and see what your problem might be.
I also don't know if it matters but my headers array looks like:
$headers = array (
'Authorization: ' . "TOKEN $token",
'Content-Type: ' . 'application/json',
'X-EBAY-C-MARKETPLACE-ID: ' . 'EBAY-US',
'Accept: ' . 'application/json',
);
So you can see there is a space after the colon.

Related

DialmyCall API Curl to PHP

UPDATE*
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $_ENV["https://cf6307f08afef7f0f9f449a55c6fd79b#api.dialmycalls.com/2.0/service/text"]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = array (
'name' => 'Dorothy',
'keyword_id' => '351aa984-9a7b-11e8-a4d5-0cc47ab3cb58',
'messages' => 'test123456',
array ("contacts" => array(
array(
"phone" => "12294622255"
))));
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_POST, 1);
$headers = array();
$headers[] = "Content-Type: application/json";
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close ($ch);
?>
I am still getting
`Error: malformed`
So maybe a little more information about the json construction might help
These are the required fields
name - > name of broadcast
keyword_id - > 351aa984-9a7b-11e8-a4d5-0cc47ab3cb58
messages - > list format but only sending single message "test123456"
contacts - > List format with substring of phone: then number 1234567891
ORIGINAL QUESTION
So i am trying to setup a php page with DialMyCall's API just to sent text with the variables
$numbers (Command Delimited)
$message (message of SMS)
The example that DialMyCode gives is
curl -i -H "Content-Type: application/json" -X POST -d "{\"keyword_id\": \"dfe49537-a0a8-4f4a-98a1-e03df388af11\", \"send_immediately\": true,\"messages\": [\"Testing testing\"], \"contacts\": [{\"phone\":\"1116551235\"},{\"phone\":\"1116551234\"}]}" https://$API_KEY#api.dialmycalls.com/2.0/service/text
I have tried to convert this into php but i cannot get it to work
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $_ENV["https://APIKEY#api.dialmycalls.com/2.0/service/text"]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, array (
'name' => 'Dorothy',
'keyword_id' => '351aa984-9a7b-11e8-a4d5-0cc47ab3cb58',
'message' => 'test123456',
'contacts' => 'phone: 1234567891',
));
curl_setopt($ch, CURLOPT_POST, 1);
$headers = array();
$headers[] = "Content-Type: application/json";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close ($ch);
?>
Error recieved
Error: malformed
What i should get is a success message in JSON and a text message sent.
You need to send your data as a JSON string. When you pass an array to CURLOPT_POSTFIELDS, it formats/passes it like form data. Here, you want to pass a json object as the body, so use something like this below:
$data = array (
'name' => 'Dorothy',
'keyword_id' => '351aa984-9a7b-11e8-a4d5-0cc47ab3cb58',
'messages' => array('test123456'),
'contacts' => array(
array('phone' => '1234567891')
)
);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));

JIRA REST API POST call via cURL with OAuth access token returns 401

I have went through steps of getting an access token ( i did this though a terminal using java)
When i try to use a GET request in terminal with java like this:
java -jar rest-oauth-client-1.0.one-jar.jar request ACCESS_TOKEN http://locahost:8015/rest/api/2/issue/TP-113
It works and returns an Issue JSON
But when i try to GET or POST an ISSUE using PHP and cURL like this
$FieldSummary = substr($items[0]->summary,strpos($items[0]->summary,'- ')+2);
$FieldDescription = substr($items[0]->description,0);
$FieldStartTime = new DateTime($items[0]->start->dateTime);
$FieldEndTime = new DateTime($items[0]->end->dateTime);
$dateStart = $FieldStartTime->format("Y-m-d\Th:m:s.sOZ");
$dateEnd = $FieldEndTime->format("Y-m-d\Th:m:s.sOZ");
$url = "http://".$config['jiraAdress']."/rest/api/2/issue/".$FieldKey;
$ch = curl_init($url);
$headers = array(
'Authorization: Bearer ACCESS_TOKEN',
'Accept: application/json',
'Content-Type: application/json'
);
$data = json_encode ( array (
'fields' => array (
'summary' => $FieldSummary,
'description' => $FieldDescription,
'customfield_10007' => $dateStart,
'customfield_10008' => $dateEnd
)
), JSON_PRETTY_PRINT );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$result = curl_exec($ch);
It returns error 401 and error JSON:
{
"errorMessages": [
"You do not have the permission to see the specified issue.",
"Login Required"
],
"errors": {
}
}
What am I doing wrong? Remember that this is JIRA REST API.

Sendgrid cURL authentication GET API in php

So I've been trying to figure out how to manage this for a few days but nothing so far...
Here's my problem : I'm trying to retrieve a json object from a SendGrid GET API.
-> https://api.sendgrid.com/v3/suppression/bounces/
Which needs cURL authentication, as the support told me :
curl --request GET \
--url https://api.sendgrid.com/v3/suppression/bounces/
--header 'authorization: Bearer YOUR_API_KEY'
--header 'Content-Type: application/json'
So since I'm pretty new to cURL, I can't manage to retrieve the datas with this :
$ch = curl_init('https://api.sendgrid.com/v3/suppression/bounces/');
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json' , 'authorization: Bearer MY_API_KEY'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
$bounces = json_decode(file_get_contents($response),true);
I get this error :
Warning: file_get_contents({"errors":[{"field":null,"message":"resource not found"}]}): failed to open stream: No such file or directory in ...
Thanks ! :)
Try to use the curl
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.sendgrid.com/v3/suppression/bounces/");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
$headers = array();
$headers[] = "Authorization: Bearer YOUR_API_KEY";
$headers[] = "Content-Type: application/json";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close ($ch);
Edited
based on your JSON response I could try to parse with these
$response = '[{"created":1495048030,"email":"dfezfezfezfezfezfez#exelcia-it.com","reason":"550 5.4.1 [dfezfezfezfezfezfez#exelcia-it.com]: Recipient address rejected: Access denied [DB5EUR01FT015.eop-EUR01.prod.protection.outlook.com] ","status":"5.4.1"},{"created":1494945503,"email":"squestgel#exelcia-it.com","reason":"550 5.4.1 [squestgel#exelcia-it.com]: Recipient address rejected: Access denied [DB5EUR01FT004.eop-EUR01.prod.protection.outlook.com] ","status":"5.4.1"}]';
$json = json_decode($response , true) ;
echo '<pre>'.print_r($json, true).'</pre>';
foreach ($json as $data) {
echo $data['email'].'<br>';
}
And here is the result I got.
Array
(
[0] => Array
(
[created] => 1495048030
[email] => dfezfezfezfezfezfez#exelcia-it.com
[reason] => 550 5.4.1 [dfezfezfezfezfezfez#exelcia-it.com]: Recipient address rejected: Access denied [DB5EUR01FT015.eop-EUR01.prod.protection.outlook.com]
[status] => 5.4.1
)
[1] => Array
(
[created] => 1494945503
[email] => squestgel#exelcia-it.com
[reason] => 550 5.4.1 [squestgel#exelcia-it.com]: Recipient address rejected: Access denied [DB5EUR01FT004.eop-EUR01.prod.protection.outlook.com]
[status] => 5.4.1
)
)
dfezfezfezfezfezfez#exelcia-it.com
squestgel#exelcia-it.com
I managed to do what I wanted to do :
//opening curl sessions
$ch1 = curl_init('https://api.sendgrid.com/v3/suppression/bounces');
$ch2 = curl_init('https://api.sendgrid.com/v3/suppression/invalid_emails');
//setting options to ch1
curl_setopt($ch1, CURLOPT_HTTPHEADER, array('Content-Type: application/json' , 'authorization: Bearer MY_API_KEY'));
curl_setopt($ch1, CURLOPT_RETURNTRANSFER, 1);
//setting options to ch2
curl_setopt($ch2, CURLOPT_HTTPHEADER, array('Content-Type: application/json' , 'authorization: Bearer MY_API_KEY'));
curl_setopt($ch2, CURLOPT_RETURNTRANSFER, 1);
//exec 2 curl sessions
$resp1 = curl_exec($ch1);
$resp2 = curl_exec($ch2);
//Merging 2 curl arrays and converting into json
$array = json_encode(array_merge(json_decode($resp1, true),json_decode($resp2, true)));
//Decoding result
$arr = json_decode($array, true);
foreach ($arr as $data) {
echo $data['email'].'<br>';
}

Walmart Seller API POST not working, Gives 401 unauthorized in PHP only

I am trying to GET Walmart Seller API using CURL PHP to acknowledge.
Can any one suggest which RSA PHP library i need to use ? So that Authentication Signature is verify while making calls to walmart.
Any one experience with this ?
$headers = array(
'WM_SVC.NAME: Walmart Marketplace',
'WM_QOS.CORRELATION_ID: 14730688612',
'WM_SEC.TIMESTAMP:14730688612',
'WM_SEC.AUTH_SIGNATURE: XXXXXXXXXXX'
'WM_CONSUMER.ID: XXXXXXXXXXX',
'Content-Type: application/xml',
'Accept: application/xml',
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_URL,$requestUrl);
curl_setopt($ch, CURLOPT_HEADER, TRUE);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec( $ch );
if(curl_errno($ch)):
echo 'Curl error: '.curl_error($ch);
endif;
I have used reference that found while googling.
- https://github.com/fillup/walmart-auth-signature-php
The hardest part about this is generating the signature and getting that to work properly.
I pulled a lot of these pieces from various spots to give a straight forward example so hopefully it will work.
Let say we want to make a GET call to get all of our feeds statuses.
// Your walmart info from walmart admin
$walmart_consuer_id = XXXXXXXXXXXXX;
$walmart_channel_type = XXXXXXXXXXXX;
$request_type = "GET";
$url = "https://marketplace.walmartapis.com/v2/feeds";
// We need a timestamp to generate the signature and to send as part of the header
$timestamp = round(microtime(true) * 1000);
$signature = getClientSignature($url, $request_type, $timestamp);
$headers = array();
$headers[] = "Accept: application/xml";
$headers[] = "WM_SVC.NAME: Walmart Marketplace";
$headers[] = "WM_CONSUMER.ID: ".$walmart_consuer_id;
$headers[] = "WM_SEC.TIMESTAMP: ".$timestamp;
$headers[] = "WM_SEC.AUTH_SIGNATURE: ".$signature;
$headers[] = "WM_QOS.CORRELATION_ID: ".mt_rand();
$headers[] = "WM_CONSUMER.CHANNEL.TYPE: " .$walmart_channel_type;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $request_type);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
function getClientSignature($url, $request_type, $timestamp) {
// Your walmart info from walmart admin
$walmart_secret = XXXXXXXXXXXXXXXX;
$walmart_consuer_id = XXXXXXXXXXXXX;
// Get an openssl usable private key from the walmart supplied secret
$pem = pkcs8_to_pem(base64_decode($walmart_secret));
$private_key = openssl_pkey_get_private($pem);
// Construct the data we want to sign
$data = $walmart_consuer_id."\n";
$data .= $url."\n";
$data .= $request_type."\n";
$data .= $timestamp."\n";
// Sign the data
$hash = defined("OPENSSL_ALGO_SHA256") ? OPENSSL_ALGO_SHA256 : "sha256";
if (!openssl_sign($data, $signature, $private_key, $hash)) {
// ERROR
return null;
}
return base64_encode($signature);
}
function pkcs8_to_pem($der) {
static $BEGIN_MARKER = "-----BEGIN PRIVATE KEY-----";
static $END_MARKER = "-----END PRIVATE KEY-----";
$value = base64_encode($der);
$pem = $BEGIN_MARKER . "\n";
$pem .= chunk_split($value, 64, "\n");
$pem .= $END_MARKER . "\n";
return $pem;
}
In the new API after August of 2018, you have to generate an access token AND then use a completely separate authentication header to pull anything from their API. It took a couple of hours just to figure this out, so I hope this helps someone in the future.
(This is for the Marketplace API, but should work for any Walmart API)
To generate the access token, you have to pass these headers:
Array(
[0] => Authorization: Basic BASE64_ENCODED_VARIABLE (see below)
[1] => Content-Type: application/x-www-form-urlencoded
[2] => Accept: application/json
[3] => WM_SVC.NAME: Walmart Marketplace
[4] => WM_QOS.CORRELATION_ID: 10_DIGIT_RANDOM_GENERATED_ALPHANUMERIC_ID
[5] => WM_SVC.VERSION: 1.0.0
[6] => WM_CONSUMER.CHANNEL.TYPE: PROVIDED_WHEN_GENERATING_CLIENT_ID_AND_SECRET
)
To generate BASE64_ENCODED_VARIABLE, create a variable using base64_encode as such:
$auth = base64_encode($clientId . ":" . $clientSecret);
...where Client ID and Client Secret are generated from Wal-Mart's Developer Portal API area.
===========================================
After you successfully POST that data to Walmart and receive an Access Token in return, you want to pass the following headers in ANY API CALL you make with Wal-Mart:
Array(
[0] => Authorization: Basic BASE64_ENCODED_VARIABLE (as described above)
[1] => WM_SVC.NAME: Walmart Marketplace
[2] => WM_QOS.CORRELATION_ID: 10_DIGIT_RANDOM_GENERATED_ALPHANUMERIC_ID
[3] => WM_CONSUMER.CHANNEL.TYPE: PROVIDED_WHEN_GENERATING_CLIENT_ID_AND_SECRET
[4] => WM_SEC.ACCESS_TOKEN: GENERATED_FROM_PREVIOUS_STEP (returned as [access_token])
[5] => Content-Type: application/json
[6] => Accept: application/json
)
...then make your calls.
This is what FINALLY worked for me after continuously receiving UNAUTHORIZED.GMP_GATEWAY_API errors across the board.
Passing "Authorization: Bearer TOKENTOKENTOKEN" instead of the way I've listed above WILL NOT WORK as the authentication header. Trust me :-)
<?php
$consumer_id='xxxxxxxxxx';
$private_key='xxxxxxxxxx';
$timestamp='xxxxxxxx';
$correlation_id='xxxxxxxxxxx';
$channel_id='xxxxxxxxxx';
$endPoint = "v3/feeds?feedType=item";
$requestUrl = "https://marketplace.walmartapis.com/$endPoint";
$requestMethod = 'POST';
$signature = new Signature($consumer_id, $private_key, $requestUrl, $requestMethod);
$actual_signature = $signature->getSignature($timestamp);
$file = '..../walmart_product.xml';
$headers = [];
$headers[] = "WM_SVC.NAME: Walmart Marketplace";
$headers[] = "WM_QOS.CORRELATION_ID: ".$correlation_id;
$headers[] = "WM_SEC.TIMESTAMP: ".$timestamp;
$headers[] = "WM_SEC.AUTH_SIGNATURE: ".$actual_signature;
$headers[] = "WM_CONSUMER.ID: " .$consumer_id;
$headers[] = "Content-Type: multipart/form-data";
$headers[] = "Accept: application/xml";
$headers[] = "WM_CONSUMER.CHANNEL.TYPE: ".$channel_id;
$headers[] = "HOST: marketplace.walmartapis.com";
$body ['file'] = new \CurlFile ( $file, 'application/xml' );
$ch = curl_init ();
curl_setopt ( $ch, CURLOPT_URL, $requestUrl );
curl_setopt ( $ch, CURLOPT_HTTPHEADER, $headers );
curl_setopt ( $ch, CURLOPT_HEADER, 1 );
curl_setopt ( $ch, CURLOPT_POST, 1 );
curl_setopt ( $ch, CURLOPT_POSTFIELDS, $body );
curl_setopt ( $ch, CURLOPT_SSL_VERIFYPEER, 0 );
curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, true );
$server_output = curl_exec ( $ch );
?>
$ch = curl_init();
$headers = $actual;
$qos = uniqid();
$url='https://api-gateway.walmart.com/v3/items';
$options =
array (
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 60,
CURLOPT_HEADER => false,
CURLOPT_POST => 1,
CURLOPT_HTTPHEADER => array(
'WM_SVC.NAME: Drop Ship Vendor Services',
'WM_QOS.CORRELATION_ID:'.$qos,
'WM_SEC.TIMESTAMP:1451606400',
'WM_SEC.AUTH_SIGNATURE: '.$headers,
'WM_CONSUMER.ID:'.$WalmartConsumerID
,
'WM_CONSUMER.CHANNEL.TYPE:**********',
'Accept: application/xml'
),
CURLOPT_HTTPGET => true
);
curl_setopt_array($ch, $options);
$response = curl_exec ($ch);
print_r($response);

How to update user profile picture in QuickBlox using php api?

How to update user profile picture in Quickblox using php codeigntier ?
Documentation found at
http://quickblox.com/developers/Users
after found rest api i have found the solution for how to upload profile picture to quickblox user.
there are three 3 steps for uploading content as per quickblox rest api
First you generate token from the quickblox and then perform these 3 steps
Create file
https://quickblox.com/developers/Content#Create_a_file
$strFilename = '2.jpeg';
$post_body = http_build_query(array(
'blob[content_type]' => 'image/jpeg',
'blob[name]' =>$strFilename,
));
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, QB_API_ENDPOINT.'blobs.json');
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $post_body);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Accept: application/json',
'Content-Type: application/x-www-form-urlencoded',
'QuickBlox-REST-API-Version: 0.1.0',
'QB-Token: ' . $token
));
$response = curl_exec($curl);
$error = curl_error($curl);
if ($response) {
return $response;
} else {
return false;
}
curl_close($curl);
After this curl call you have got the response and in response got the response like this
[blob] => Array
(
[id] => 7178102
[uid] => f9cc9d7938c4468f8bdccdcb68fb5d8c00
[content_type] => image/jpeg
[name] => 2.jpeg
[size] =>
[created_at] => 2017-02-07T10:35:38Z
[updated_at] => 2017-02-07T10:35:38Z
[ref_count] => 1
[blob_status] =>
[set_completed_at] =>
[public] => 1
[last_read_access_ts] =>
[lifetime] => 8600
[account_id] => 56721
[app_id] =>
[blob_object_access] => Array
(
[id] => 7178102
[blob_id] => 7178102
[expires] => 2017-02-07T11:35:38Z
[object_access_type] => Write
[params] => https://qbprod.s3.amazonaws.com/?Content-Type=image%2Fjpeg&Expires=Tue%2C%2007%20Feb%202017%2011%3A35%3A38%20GMT&acl=public-read&key=f9cc9d7938c4468f8bdccdcb68fb5d8c00&policy=eyJleHBpcmF0aW9uIjoiMjAxNy0wMi0wN1QxMTozNTozOFoiLCJjb25kaXRpb25zIjpbeyJidWNrZXQiOiJxYnByb2QifSx7ImFjbCI6InB1YmxpYy1yZWFkIn0seyJDb250ZW50LVR5cGUiOiJpbWFnZS9qcGVnIn0seyJzdWNjZXNzX2FjdGlvbl9zdGF0dXMiOiIyMDEifSx7IkV4cGlyZXMiOiJUdWUsIDA3IEZlYiAyMDE3IDExOjM1OjM4IEdNVCJ9LHsia2V5IjoiZjljYzlkNzkzOGM0NDY4ZjhiZGNjZGNiNjhmYjVkOGMwMCJ9LHsieC1hbXotY3JlZGVudGlhbCI6IkFLSUFJWTdLRk0yM1hHWEo3UjdBLzIwMTcwMjA3L3VzLWVhc3QtMS9zMy9hd3M0X3JlcXVlc3QifSx7IngtYW16LWFsZ29yaXRobSI6IkFXUzQtSE1BQy1TSEEyNTYifSx7IngtYW16LWRhdGUiOiIyMDE3MDIwN1QxMDM1MzhaIn1dfQ%3D%3D&success_action_status=201&x-amz-algorithm=AWS4-HMAC-SHA256&x-amz-credential=AKIAIY7KFM23XGXJ7R7A%2F20170207%2Fus-east-1%2Fs3%2Faws4_request&x-amz-date=20170207T103538Z&x-amz-signature=5e236c3da60a922951c8ab6281ae82af3a88e37c15d8630ad6ff590610a87fd8
)
)
Upload file
so you have to used the params url parameters and make another call for uploading file
$strFilename = '2.jpeg';
$url = 'https://qbprod.s3.amazonaws.com/';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, array(
'Content-Type' => $arr['Content-Type'],
'Expires'=>$arr['Expires'],
'acl'=>$arr['acl'],
'key'=>$arr['key'],
'policy'=>$arr['policy'],
'success_action_status'=>$arr['success_action_status'],
'x-amz-algorithm'=>$arr['x-amz-algorithm'],
'x-amz-credential'=>$arr['x-amz-credential'],
'x-amz-date'=>$arr['x-amz-date'],
'x-amz-signature'=>$arr['x-amz-signature'],
'file' => new CurlFile('2.jpeg', $arr['Content-Type'], $strFilename)
));
$response = curl_exec($ch);
if (curl_getinfo($ch, CURLINFO_HTTP_CODE) == 204) {
echo 'Success!';
} else {
$error = substr($response, strpos($response, '<Code>') + 6);
echo substr($error, 0, strpos($error, '</Code>'));
}
return $response;
so by using this code your content file will be uploaded and you got the location of the file and used as profile picture or etc .
Declare file
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://api.quickblox.com/blobs/" . $strId . "/complete.xml"); // strId is blod id return by 1 step
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "blob[size]=10000"); //your file size
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
$headers = array();
$headers[] = "Quickblox-Rest-Api-Version: 0.1.0";
$headers[] = "Qb-Token: " . $token;
$headers[] = "Content-Type: application/x-www-form-urlencoded";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
return $result;
Please let me know the any issue regards the same.
Thanks

Categories