I am having some issues with uploading attachment into deals in HubSpot.
Here is my code:
$note_details = array(
"engagement" => array(
"active" => true,
"type" => "NOTE",
"timestamp" => 5456563646
),
"associations" => array(
"dealIds" => array( '4875586081' ),
"attachments" => array(
"id" => array ("44830500634")
),
),
"metadata" => array(
"body" => "TESTING-222",
)
);
This code creates an engagement or Notes but the attachment is not there!
and here is the JSON structure that HubSpot uses:
{
"engagement": {
"active": true,
"ownerId": 1,
"type": "NOTE",
"timestamp": 1409172644778
},
"associations": {
"contactIds": [2],
"companyIds": [ ],
"dealIds": [ ],
"ownerIds": [ ],
"ticketIds":[ ]
},
"attachments": [
{
"id": 4241968539
}
],
"metadata": {
"body": "note body"
}
}
Any idea what am I missing?
Related
So I'm trying to sort my search results to show the exact matches before all the partial matches. What I mean by this is if I have the documents with names:
Set 4/102
Set 44/102
Set 94/102
I'm searching on the term 4/102 and it returns all documents. This is fine, however, I want the Set 4/102 to show up first but it seemingly sorts them randomly. Is there a way to use script sorting or something like that to have the exact term match to show up first?
These are my mappings and settings:
$settingsParams = [
'index' => 'products',
'body' => [
'settings' => [
'analysis' => [
'analyzer' => [
'substring_analyzer' => [
'tokenizer' => 'substring_tokenizer',
'filter' => [
'lowercase'
]
],
'fullword_analyzer' => [
'tokenizer' => 'whitespace',
'filter' => [
'lowercase'
]
],
],
'tokenizer' => [
'substring_tokenizer' => [
'type' => 'nGram',
'min_gram' => 3,
'max_gram' => 12,
'token_chars' => [
'letter',
'digit',
'symbol',
'custom'
],
'custom_token_chars' => '/'
]
]
],
'max_ngram_diff' => 20
]
]
];
$mappingParams = [
'index' => 'products',
'body' => [
'_source' => [
'enabled' => true
],
'properties' => [
'name' => [
'type' => 'text',
'fields' => [
'keyword' => [
'type' => 'keyword'
]
],
'analyzer' => 'substring_analyzer',
'search_analyzer' => 'fullword_analyzer'
],
'min_price' => [
'type' => 'double'
],
'saleprice' => [
'type' => 'double'
],
'list_price' => [
'type' => 'double'
],
'root_category_rank' => [
'type' => 'integer'
],
'interest_level' => [
'type' => 'integer'
],
'root_categoryid' => [
'type' => 'integer'
]
]
]
];
Adding a working example
Index Mapping:
{
"settings": {
"analysis": {
"analyzer": {
"substring_analyzer": {
"tokenizer": "substring_tokenizer"
},
"fullword_analyzer": {
"tokenizer": "whitespace"
}
},
"tokenizer": {
"substring_tokenizer": {
"type": "ngram",
"min_gram": 3,
"max_gram": 12,
"token_chars": [
"letter",
"digit",
"custom",
"symbol"
],
"custom_token_chars": "/"
}
}
},
"max_ngram_diff": 50
},
"mappings": {
"properties": {
"name": {
"type": "text",
"analyzer": "substring_analyzer",
"search_analyzer": "fullword_analyzer"
}
}
}
}
Search Query:
{
"query": {
"match": {
"name": "4/102"
}
}
}
Search Result:
The document "name": "4/102" is having a higher score as compared to other documents
"hits": [
{
"_index": "66232066",
"_type": "_doc",
"_id": "1",
"_score": 0.15275992,
"_source": {
"name": "4/102" // note this
}
},
{
"_index": "66232066",
"_type": "_doc",
"_id": "2",
"_score": 0.12562492,
"_source": {
"name": "44/102"
}
},
{
"_index": "66232066",
"_type": "_doc",
"_id": "3",
"_score": 0.12562492,
"_source": {
"name": "94/102"
}
}
]
I am setting up a payment integration with PayPal Checkout Buttons and Paypal Orders API V2. Payments are going throw, but now I want to include items in my Order request, but I getting:
As PayPal docs say I have to pass array (contains the item object) Link to Orders API purchase_unit object Link to Orders API item object. But I'm still getting this error.
This is my request:
public function createOrder($value, $order, $products, $currency = 'EUR')
{
return $this->makeRequest(
'POST',
'/v2/checkout/orders',
[],
[
'intent' => 'CAPTURE',
'payer' => [
'name' => [
'given_name' => $order->billing_firstname,
'surname' => $order->billing_lastname
],
'email_address' => $order->email_address,
'address' => [
'address_line_1' => $order->billing_street_address,
'admin_area_2' => $order->billing_city,
'postal_code' => $order->billing_postcode,
'country_code' => $order->billing_country_code
],
],
'purchase_units' => [
0 => [
'amount' => [
'currency_code' => $currency,
'value' => $value,
],
'description' => 'Order: ' . $order->order_serial_number,
'items' => [
0 => [
'name' => 'Item1',
'unit_amount' => 100,
'quantity' => 1
],
],
],
],
'application_context' => [
'brand_name' => config('app.name'),
'shipping_preference' => 'NO_SHIPPING',
'user_action' => 'PAY_NOW',
'return_url' => route('approval.paypal', $order->id_order),
'cancel_url' => route('payment.cancelled', $order->id_order),
]
],
[],
$isJsonRequest = true
);
}
I'm using: Laravel and Guzzle/HTTP to perform payment requests.
As I say, payments are going throw, but when I try to add Items to Order, I'm getting this error.
You haven't posted the full (rest of the) error response that details the problem, so there may be another issue we can't see, but one thing that's missing is the amount.breakdown.item_total subtotal, which is required when passing an items array with amounts: https://developer.paypal.com/docs/api/orders/v2/#definition-amount_breakdown
A simple example in the API's JSON format, which you can adapt to PHP array syntax:
// based on example array from https://developer.paypal.com/docs/checkout/reference/server-integration/set-up-transaction/
"purchase_units": [{
"amount": {
"value": "17.49",
"currency_code": "USD",
"breakdown": {
"item_total": {
"currency_code": "USD",
"value": "17.49"
},
}
},
"items": [
{
"unit_amount": {
"currency_code": "USD",
"value": "17.49"
},
"quantity": "1",
"name": "item 1",
},
],
}
]
This is how my mapping looks
$arr = [
'index' => 'test1',
'body' => [
'settings' => [
'analysis' => [
'analyzer' => [
'name_analyzer' => [
'type' => 'custom',
'tokenizer' => 'standard',
'filter' => [
'lowercase',
'asciifolding',
'word_delimiter'
]
]
]
]
],
"mappings" => [
"info" => [
"properties" => [
"Name" => [// this field is analyzed
"type" => "string",
"fields" => [
"raw" => [ //subfield of Name is not analyzed so that we can avoid a known issue of space saperated bucket generation
"type" => "string",
"index" => "not_analyzed"
]
]
],
"Address" => [
"type" => "string",
"index" => "analyzed",
"analyzer" => "name_analyzer"
]
]
]
]
]
];
And this is my query
$query['index'] = 'test1';
$query['type'] = 'info';
//without bool & should also it will work
$query['body'] = [
'query'=> [
'bool' => [
'should' => [
'query_string' => [
'fields' => ['Name'],
'query' => 'sa*',
'analyze_wildcard' => 'true'
]
]
]
],
'size'=> '0',
'aggregations' => [
'actor' => [
'terms' => [
'field' => 'Name.raw',
'size' => 10
]
]
]
];
My output is
{
"took": 2,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 3,
"max_score": 0,
"hits": []
},
"aggregations": {
"actor": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "Salma Hayak",
"doc_count": 1
},
{
"key": "Salman Khan",
"doc_count": 1
},
{
"key": "Salman Shaikh",
"doc_count": 1
}
]
}
}
}
What I want is since Salman Khan is the most searched actor as compare to Salma Hayak, having said that when user searched for "sa" they should see salman khan first rather than salma hayak.
Can anyone please help me on this?
How to obtain the following structure after the php json_encode.
It is possible?
{
"data": [
{
"name": "Tiger Nixon",
"position": "System Architect",
"salary": "$320,800"
},
{
"name": "Garrett Winters",
"position": "Accountant",
"salary": "$170,750"
}
]
}
How must look arrays?
Although formally array keys can only be integer you could simple use:
array( 'data' =>
array(
array( 'name' => 'tiger nixon', 'position' => 'system architect', 'salary' => '$320,800' ),
array( 'name' => 'Garrett Winters', 'position' => 'Accountant', 'salary' => '$170,750' )
)
);
I am new to mongoDb and facing issue in using aggregate function. I am trying to get sum of the fields "expectations" and "overall" but it returns 0. I also want to take the total count of the comments which are not empty or null in the same query.
$out = $collection->aggregate
(
array(
array( '$match' => array( 'id' => 6200 )),
array ('$unwind' => '$reviews'),
array( '$group' => array( '_id' => '$id',
'exptotal' => array( '$sum' => array('reviews' => '$expectations') ),
'total' => array( '$sum' => array('reviews' => '$overall' ) ),
'count' => array( '$sum' => 1 )
)
)
)
);
Here is the json
{
"_id": "528c62406a542f7c6a6bf522",
"id": 6200,
"categories": [
{
"id": 6,
"name": "Artificial Intelligence"
},
{
"id": 5,
"name": "Statistics and Data Analysis"
}
],
"courseId": "COURSE_16",
"institute": {
"id": 5693,
"name": "YZ University"
},
"instructors": [
" A Morris"
],
"language": "en",
"reviews": [
{
"username": "kalis",
"expectations": 3,
"content": 2,
"overall": 3,
"comments": "This is really good course for improvement",
"datecreated": "2013-11-02T17:04:11.102Z"
},
{
"username": "julia",
"expectations": 4,
"content": 2,
"overall": 2,
"comments": "This improves my skill a lot",
"datecreated": "2013-11-03T17:04:11.102Z"
},
{
"username": "john",
"expectations": 2,
"content": 4,
"overall": 4,
"comments": "",
"datecreated": "2013-11-04T17:04:11.102Z"
}
],
"shortName": "ml",
"title": "Machine Learning"
}
This looks like it would work:
$out = $collection->aggregate(array(
array('$match' => array( 'id' => 6200 )),
array ('$unwind' => '$reviews'),
array('$unwind' => '$comments'),
array( '$group' => array( '_id' => '$id',
'commTotal' => array('$sum' => array('$cond'=>array(array('$eq'=>array('$comments',null),0,1)))),
'exptotal' => array( '$sum' => '$reviews.expectations'),
'total' => array( '$sum' => '$reviews.overall' ),
'count' => array( '$sum' => 1 )
))
));
The reason is that when you $unwind the data is still in its subdocument field it is just that the subdocument has become an object of a single review.
The documentation is a little misleading on this operator I'll give you that.