How add value to custom field in ActiveCampaign? - php

Here is documentation how add custom field to ActiveCampaign https://www.activecampaign.com/api/example.php?call=contact_add
Here is my code in Laravel:
$client = new Client();
$res = $client->request('POST', 'https://domain-example.com/admin/api.php?api_action=contact_add', [
'form_params' => [
'api_key' => 'api_key',
'actid' => 'actid',
'api_action' => 'contact_add',
'api_output' => 'json',
'email' => $_POST['email'],
'field[utm_source, 0]' => $_POST['utm_source'],
'p[123]' => 10,
'field[%REFERRAL_PAGE%, 0]' => $_SERVER['HTTP_REFERER']
]
]);
Result: contact added,but the field utm_source is empty. In Laravel I checked , this property is not empty before send. Other fields are not empty too, the problem is only with custom field utm_source. Any thoughts why it happens?

I think is the next entry in the API what you really should use
field[%utm_source%,0] => $_POST['utm_source']

Related

Prefill PDF form field in Docusign document before sending (transform_pdf_fields == true)

I'm using the Docusign PHP SDK to create an envelope using a PDF with pre-existing form fields.
The fields are correctly being parsed by Docusign and show up on the resulting document.
However, I can't find a way to prefill some of those fields.
// Create document model
$document = new Document([
'document_base64' => $base64_content,
'name' => 'Document',
'file_extensions' => 'pdf',
'document_id' => 1, 'transform_pdf_fields' => true
]);
$signer = new Signer([
'email' => $args['client_email'],
'name' => $args['client_name'],
'recipient_id' => 1,
'routing_order' => 1,
'client_user_id' => $args['client_user_id']
]);
// This is the attempt to prefill the fields
// by using the same label as the PDF form.
// But it does nothing.
$text1 = new Text([
'tab_label' => 'field_one', 'value' => $args['client_coverage'],
]);
$text2 = new Text([
'tab_label' => 'field_two', 'value' => $args['client_term'],
]);
$signer->setTabs(new Tabs(['text_tabs' => [$text1, $text2]]));
$definition = new EnvelopeDefinition([
'email_subject' => "Please sign this document",
'documents' => [$document],
'recipients' => new Recipients(['signers' => [$signer]]),
'status' => 'sent',
]);
A call to the envelope tabs API shows the tabs in question with the exact tab label but the value is blank.
Any suggestions would be very appreciated! Thanks.
P.S. I can, after the envelope creation, get the document tabs, in order to get their IDs, and then make another request to update those.
So this is doable in 3 calls but I have a feeling that it should be possible to do in one - when the envelope is created initially.
#sdragnev, this can work if you use composite templates
$inline_template = new \DocuSign\eSign\Model\InlineTemplate([
'recipients' => new Recipients(['signers' => [$signer]]),
'sequence' => "1"
]);
$inline_templates = [$inline_template];
$composite_template = new \DocuSign\eSign\Model\CompositeTemplate([
'composite_template_id' => "1",
'document' => $document,
'inline_templates' => $inline_templates
]);
$composite_templates = [$composite_template];
$envelope_definition = new \DocuSign\eSign\Model\EnvelopeDefinition([
'composite_templates' => $composite_templates,
'email_subject' => "Agreement",
'status' => "sent"
]);

Laravel Stripe Setup

okay, this is my first time to ask a question here so please give grace if it's not very clear. Anyway, I have this code in Laravel Billing.php.
Is this correct? Whenever a new customer is created, it doesn't have it's user email address but instead this unknown#domain.com was assigned to the user.
This was set by my previous developer. But ever since we hired him for just simple fix, we've had numerous issues with the site.
$stripeCustomer = StripeCustomer::create([
'email' => $currentCustomer->email ? $currentCustomer->email : 'unknown#domain.com',
'description' => $company->name,
'metadata' => [
'company_id' => $company->id,
'card_owner_email' => $currentCustomer->email ? $currentCustomer->email : false,
'company_name' => $company->name,
],
]);
You can remove customer email from the StripeCustomer when creating since stripe API said that email field of customer is optional. Here is the reference link
Here what you should fix:
$customerObject = [
'description' => $company->name,
'metadata' => [
'company_id' => $company->id,
'company_name' => $company->name,
],
];
if ($currentCustomer->email) {
$customerMetadata["metadata"]["card_owner_email"] = $currentCustomer->email;
$customerObject["email"] = $currentCustomer->email;
}
$stripeCustomer = StripeCustomer::create($customerObject);

There is nothing happening when store data for Laravel API

I making laravel API where i can store a new data where the value in body raw json. but when i try to send request using post, i got nothing but the status is 200 OK. when i chek my mysql there is no data inputed.
So, what should i do?
mysql data
Laravel Controller, and API,
// function in controller
use App\Models\ChartAge;
class ChartController extends Controller
{
public function saveChart(Request $request)
{
$data = $request->validate([
'entity' => 'required|string|max:10',
'code' => 'required|string|max:10',
'year' => 'required|int|max:10',
'under_age_15' => 'required|string|max:50',
'age_15_64' => 'required|string|max:50',
'age_65_over' => 'required|string|max:50',
]);
$values = ChartAge::create($request);
return response()->json(
[
'status' => true,
'message' => "the videos has been favorites",
'data' => $values,
],
201
);
}
}
//in api.php
Route::post("charts", [ChartController::class, 'saveChart']);
and here is when i tried to send request using postman.
because there is no error, i don't know what's wrong??
First double check your ChartAge model, does it have $fillable or not?
and Edit your code:
From
$values = ChartAge::create($request);
To:
$values = ChartAge::create($request->all());
Hope this will be useful.
With validation:
$data = \Validator::make($request->all(),[
'entity' => 'required|string|max:10',
'code' => 'required|string|max:10',
'year' => 'required|int|max:10',
'under_age_15' => 'required|string|max:50',
'age_15_64' => 'required|string|max:50',
'age_65_over' => 'required|string|max:50',
]);
if($data-> fails()){
return back()->withErrors($data)->withInput();
}
$values = ChartAge::create($request->all());
Do you set fillable fields in your 'ChartAge' model?
protected $fillable = ['entity','code','year'...];
Do you try to test code with disabling validation?
Please try to put dd($request) in the first row of the controller code.
Method create expects a plain PHP array, not a Request object.

How to use updateOrCreate proprely

Here is my code :
$user = \App\User::where('id', $uid)->firstOrFail();
$user->token()->updateOrCreate(['user_id' => $uid, 'type' => $type], [
'auth' => $auth_token,
'refresh' => $refresh_token,
'type' => $type
]);
I've got two models User and Token with an 'one to one' relationship.
On the first line, I try to catch a User into the database, then I update my model with the updateOrCreate() method.
However, as you can read it, I must use a selector 'user_id' => $uid before to successfully update my model. I think Eloquent should be able to manage it in a different way without making two requests.
You don't have to use the user_id => $uid on that query. It's injected based on the relationship already. You can rewrite that to:
$token = \App\User::where('id', $uid)->firstOrFail()->token()->updateOrCreate(['type' => $type], [
'auth' => $auth_token,
'refresh' => $refresh_token,
'type' => $type
]);

Laravel 5.1: Guzzle 6 return response is not working

I'm using Gazzle 6 with Laravel 5.1 and I'm having a strange behaviour returning my data from the APIs I'm using. This is my code:
$data = array(
'id' => '112233'
);
$from = \Carbon\Carbon::now()->subDays(1)->format('d/m/Y');
$to = \Carbon\Carbon::now()->subMonths(1)->format('d/m/Y');
$first_report = $this->client->post('https://my.service.com/reporting/execute/', [
'auth' => ['myemail#email.com', 'mypassword'],
'form_params' => ['data' => json_encode($data)]
]);
$second_report = $this->client->get('mysecondservice.com/reports', [
'query' => [
'account_auth_token' => '000011122223333444455556667778889999',
'start_date' => $to,
'end_date' => $from
]
]);
return array(
'first_report' => $first_report,
'second_report' => $second_report
);
If I return the data as an array like the previous one the first_report and second_report are empty. But if I return only for example
return $first_report;
or
return $second_report;
The data is returned correctly for each report but I don't know what is the issue there, because I have tried with: json_encode or even return $response()->json... but still not working.
Do you have any idea about what's going on?
I think you need to run the send() function on the object you have to get the response, then run getBody() on that to get the response object, then run getContents() on that to get the contents of the response as a string. So in total it would look like
$first_report = $this->client->post('https://my.service.com/reporting/execute/', [
'auth' => ['myemail#email.com', 'mypassword'],
'form_params' => ['data' => json_encode($data)]
])->send()->getBody()->getContents();
$second_report = $this->client->get('mysecondservice.com/reports', [
'query' => [
'account_auth_token' => '000011122223333444455556667778889999',
'start_date' => $to,
'end_date' => $from
]
])->send()->getBody()->getContents();
I find the Guzzle documentation does not match up with the actual methods I use to get the results. Not sure if it's out of date or if I'm doing it wrong, but this method works for me.

Categories