I am looping through email bodies that are nothing but JSON output. I am trying to grab a single string emailAddress, but I am unsure of the syntax. I am able to get to the Message portion of the JSON, but anything else I try to access, I end up getting Illegal string offset.
So, if my JSON is:
[Type] => Notification
[MessageId] => gibberishhere
[TopicArn] => arn:aws:somethingsomethingsomething
[Message] => {
"notificationType":"Bounce",
"bounce":{
"feedbackId":"blahblahblahblahblah",
"bounceType":"Permanent",
"bounceSubType":"General",
"bouncedRecipients":[{
"emailAddress":"bounce#simulator.amazonses.com",
"action":"failed",
"status":"5.1.1",
"diagnosticCode":"smtp; 550 5.1.1 user unknown"}],
"timestamp":"2020-11-02T16:37:13.000Z",
"remoteMtaIp":"ip.address.here",
"reportingMTA":"dsn; somethingsomething"},
"mail":{
"timestamp":"2020-11-02T16:37:13.029Z",
"source":"test#emailaddress.com",
"sourceArn":"arn:somethingsomethingdotcom",
"sourceIp":"ip.address.here",
"sendingAccountId":"somethingsomething",
"messageId":"numbersnumbersnumbers1234567890",
"destination":["bounce#simulator.amazonses.com"]
}
}
[Timestamp] => 2020-11-02T16:37:13.677Z
[SignatureVersion] => 1
[Signature] => blahblahblah
[SigningCertURL] => blahblahblah
[UnsubscribeURL] => blahblahblah
And I have this to decode it:
$message = json_decode($message, true);
echo $message['Message'];
I get this output:
{
"notificationType":"Bounce",
"bounce":{
"feedbackId":"blahblahblahblahblah",
"bounceType":"Permanent",
"bounceSubType":"General",
"bouncedRecipients":[{
"emailAddress":"bounce#simulator.amazonses.com", <---- I NEED THIS FIELD
"action":"failed",
"status":"5.1.1",
"diagnosticCode":"smtp; 550 5.1.1 user unknown"}],
"timestamp":"2020-11-02T16:37:13.000Z",
"remoteMtaIp":"ip.address.here",
"reportingMTA":"dsn; e226-55.smtp-out.us-east-2.amazonses.com"},
"mail":{
"timestamp":"2020-11-02T16:37:13.029Z",
"source":"test#emailaddress.com",
"sourceArn":"arn:somethingsomethingdotcom",
"sourceIp":"ip.address.here",
"sendingAccountId":"somethingsomething",
"messageId":"numbersnumbers1234567890",
"destination":["bounce#simulator.amazonses.com"]
}
}
All I need is the emailAddress field. How far in do I need to go to grab it? I've tried
$message['Message']['bounce'], $message['Message']['emailAddress'], and several others, but they all return Illegal string offset.
Working with an associative array is relatively easy, so as suggested in the comment:
$arr = json_decode($message['Message'], true);
Now all you need to do is reference the correct element, follow the path:
echo $arr['bounce']['bouncedRecipients'][0]['emailAddress'];
Which gives:
bounce#simulator.amazonses.com
EDIT: How to reference element emailAddress - explain the [0] index
To get a good view of the array structure of $arr, you can use:
echo '<pre>';
print_r($arr);
echo '</pre>';
Which outputs:
Array
(
[notificationType] => Bounce
[bounce] => Array
(
[feedbackId] => blahblahblahblahblah
[bounceType] => Permanent
[bounceSubType] => General
[bouncedRecipients] => Array
(
[0] => Array
(
[emailAddress] => bounce#simulator.amazonses.com
[action] => failed
[status] => 5.1.1
[diagnosticCode] => smtp; 550 5.1.1 user unknown
)
)
[timestamp] => 2020-11-02T16:37:13.000Z
[remoteMtaIp] => ip.address.here
[reportingMTA] => dsn; e226-55.smtp-out.us-east-2.amazonses.com
)
[mail] => Array
(
[timestamp] => 2020-11-02T16:37:13.029Z
[source] => test#emailaddress.com
[sourceArn] => arn:somethingsomethingdotcom
[sourceIp] => ip.address.here
[sendingAccountId] => somethingsomething
[messageId] => numbersnumbers1234567890
[destination] => Array
(
[0] => bounce#simulator.amazonses.com
)
)
)
Now all you need to do is follow the 'path' to the element you'd like to reference. I.e. for emailAddress let's take the reverse 'route':
emailAddress lives in an array with key [0] (there you have it, key [0])
key [0] lives in an array with key [bouncedRecipients]
key [bouncedRecipients] lives in an array with key [bounce]
key [bounce] lives in the root of array $arr.
So there you have it, the path to your element:
['bounce']['bouncedRecipients'][0]['emailAddress']
I cant create a tag for EbaySDK, so Ebay API may be misleading. The SDK reference is below.
Why do some requests require "input" and where can they be found? The SDK notes don't seem clear on whats required per "call type".
Following the examples from http://devbay.net/sdk/guides/getting-started/basic-usage.html#working-with-responses I'm attempting to get a list of sold items. Since Ebay only keeps 90 days data, I've put no restrictions on my request.
Their example request is:
// Create the API request object.
$request = new Types\FindItemsByKeywordsRequest();
// Assign the keywords.
$request->keywords = 'Harry Potter';
// Output the response from the API.
if ($response->ack !== 'Success') {
foreach ($response->errorMessage->error as $error) {
printf("Error: %s\n", $error->message);
}
} else {
foreach ($response->searchResult->item as $item) {
printf("(%s) %s:%.2f\n", $item->itemId, $item->title, $item->sellingStatus->currentPrice->value);
}
}
mine is a bit more simple (and apparently incomplete)
$request = new Types\GetItemStatusRequestType;
$response = $service->getItemStatus();
if ($response->Ack !== 'Success') {
if (isset($response->Errors)) {
foreach ($response->Errors as $error) {
printf("Error: %s\n", $error->ShortMessage);
}
}
} else {
print_r($response->getItemStatus); //should return all avail values (works with other types of requests)
}
Here is the nasty error
DTS\eBaySDK\Shopping\Types\GetItemStatusResponseType Object
(
[values:DTS\eBaySDK\Types\BaseType:private] => Array
(
[Timestamp] => DateTime Object
(
[date] => 2016-03-23 00:28:28.391000
[timezone_type] => 2
[timezone] => Z
)
[Ack] => Failure
[Errors] => DTS\eBaySDK\Types\UnboundType Object
(
[data:DTS\eBaySDK\Types\UnboundType:private] => Array
(
[0] => DTS\eBaySDK\Shopping\Types\ErrorType Object
(
[values:DTS\eBaySDK\Types\BaseType:private] => Array
(
[ShortMessage] => Missing required input element.
[LongMessage] => Required input element is missing from the request.
[ErrorCode] => 1.19
[SeverityCode] => Error
[ErrorParameters] => DTS\eBaySDK\Types\UnboundType Object
(
[data:DTS\eBaySDK\Types\UnboundType:private] => Array
(
[0] => DTS\eBaySDK\Shopping\Types\ErrorParameterType Object
(
[values:DTS\eBaySDK\Types\BaseType:private] => Array
(
[ParamID] => 0
[Value] => ItemID
)
[attachment:DTS\eBaySDK\Types\BaseType:private] => Array
(
[data] =>
[mimeType] =>
)
)
)
[position:DTS\eBaySDK\Types\UnboundType:private] => 0
[class:DTS\eBaySDK\Types\UnboundType:private] => DTS\eBaySDK\Shopping\Types\ErrorType
[property:DTS\eBaySDK\Types\UnboundType:private] => ErrorParameters
[expectedType:DTS\eBaySDK\Types\UnboundType:private] => DTS\eBaySDK\Shopping\Types\ErrorParameterType
)
[ErrorClassification] => RequestError
)
[attachment:DTS\eBaySDK\Types\BaseType:private] => Array
(
[data] =>
[mimeType] =>
)
)
)
[position:DTS\eBaySDK\Types\UnboundType:private] => 0
[class:DTS\eBaySDK\Types\UnboundType:private] => DTS\eBaySDK\Shopping\Types\GetItemStatusResponseType
[property:DTS\eBaySDK\Types\UnboundType:private] => Errors
[expectedType:DTS\eBaySDK\Types\UnboundType:private] => DTS\eBaySDK\Shopping\Types\ErrorType
)
[Build] => E949_CORE_APILW_17769283_R1
[Version] => 949
)
[attachment:DTS\eBaySDK\Types\BaseType:private] => Array
(
[data] =>
[mimeType] =>
)
)
Error: Missing required input element.
It seems I'm not asking the request for something, but I have no idea.
The GetItemStatus call requires you provide an ItemID. See the following API reference: GetItemStatus
You state you are looking for a sales history. I don't believe this is the call you should be using. This is a function call that appears to be in the shopping API, which is more of a product search tool.
You probably want to be using 'GetOrders' API call if you are looking to get a particular accounts sales history. See the following: GetOrders
I've got a set of arrays of string from imap_fetchstructure. But I can't extract the string out of the set. I need the value of [filePath] so I've silly tried
echo [attachments:protected][filePath];
And it doesn't work at all. I'm so new to this kind of array... This is the sample of an array set.
By the way these lines are getting from this:
$mailStructure = imap_fetchstructure($this->getImapStream(), $mailId, FT_UID);
Which is $this->getImapStream() comes from a class ImapMailbox.php
IncomingMail Object (
[id] => 2687
[date] => 2014-08-07 16:53:11
[subject] => test attc
[fromName] => Hello Kitty
[fromAddress] => hello#kitty.com
[to] => Array (
[sales#hellokitty.com] => sales
)
[toString] => sales
[cc] => Array ( )
[replyTo] => Array (
[hello#kitty.com] => Hello Kitty
)
[textPlain] => testing for attachment
[textHtml] => testing for attachment
[attachments:protected] => Array (
[487540462265330294] => IncomingMailAttachment Object (
[id] => 487540462265330294
[name] => america_support_taks.jpg
[filePath] => /home/hellokitty/domains/hellokitty.com/public_html/email/inc/2687_487540462265330294_america_support_taks.jpg
)
)
)
The answer is easy and the methods can be found in the link you provided.
The attachments are a protected property of the IncomingMail object (see line 558) but a few lines further down there is a public method getAttachments() (line 567). The object IncomingMailAttachment has only 3 properties of which all are marked public (line 589).
$attachments = $mailStructure->getAttachments();
foreach ($attachments as $attachment) {
// Array of IncomingMailAttachment objects
echo $attachment->filePath;
}
How can I obtain the VerificationStatus from this PHP object?
Guzzle\Service\Resource\Model Object
(
[structure:protected] =>
[data:protected] => Array
(
[VerificationAttributes] => Array
(
[user#gmail.com] => Array
(
[VerificationStatus] => Success
)
)
[ResponseMetadata] => Array
(
[RequestId] => csdgdf62-fdsg-dfgdf-23-bf91f933ab69
)
)
)
I discovered the answer in Amazon SES docs:
When the data is accessed with:
$result = $client->getIdentityVerificationAttributes(array(
// Identities is required
'Identities' => array($email)
));
you can access VerificationStatus at:
$result['VerificationAttributes'][$email]['VerificationStatus']
and therefore check it with:
if($result['VerificationAttributes'][$email]['VerificationStatus']=='Success'){
// verification status was successful
}
I've come across a weird scenario I do not know how to code around. I'm creating a JSON API for a wordpress site. I'm using the Connections plugin and trying to pull out the "original" image filename. The output of my sql command is this:
{
["options"]=>
string(396) "a:4:{s:5:"entry";a:1:{s:4:"type";s:12:"organization";}s:5:"group";a:1:{s:6:"family";a:0:{}}s:4:"logo";a:2:{s:6:"linked";b:0;s:7:"display";b:0;}s:5:"image";a:3:{s:6:"linked";b:1;s:7:"display";b:1;s:4:"name";a:4:{s:9:"thumbnail";s:25:"invoicelogo_thumbnail.jpg";s:5:"entry";s:21:"invoicelogo_entry.jpg";s:7:"profile";s:23:"invoicelogo_profile.jpg";s:8:"original";s:24:"invoicelogo_original.jpg";}}}"
}
}
I'm using the following command to acquire that:
querystr = "SELECT options FROM {$wpdb->prefix}connections WHERE id= '{$_GET['companyID']}'";
$options = $wpdb->get_results($querystr);
I'm not sure how to pull out the "original" part of this code though as it's not all that organized. Any help would be appreciated.
What you are seeing is the results of a php serialize call
To get at the original name just do this.
$decodedOptions = unserialize($options);
$original = $decodedOptions["image"]["name"]["original"];
Hope that helps
As a side note the deserialized data looks like
Array
(
[entry] => Array
(
[type] => organization
)
[group] => Array
(
[family] => Array
(
)
)
[logo] => Array
(
[linked] =>
[display] =>
)
[image] => Array
(
[linked] => 1
[display] => 1
[name] => Array
(
[thumbnail] => invoicelogo_thumbnail.jpg
[entry] => invoicelogo_entry.jpg
[profile] => invoicelogo_profile.jpg
[original] => invoicelogo_original.jpg
)
)
)