Zammad API: Create ticket with tag - php

For those who don't want to read the whole question:
I'm looking for the index in the API-Request (Zammad) to set a tag while creating a ticket.
Details:
I'm using PHP to make an API-Request to my server where Zammad is installed. The following shows the data i sent via curl:
json_encode([
"title" => $title,
"group_id" => 2,
"priority_id" => 2,
"category" => 'Some Category',
"state_id" => 1,
"type" => "Some Type",
"customer" => $userID,
"article" => [
"body" => $htmlBody,
"type" => "note",
"content_type" => "text/html",
],
"tag_list" => [ // <-- The question is about this segment
"The tag i want to add",
],
]);
After converting the data to JSON, im sending it via POST to http://<myServerIP>/api/v1/tickets
What I've tried so far:
I tried guessing the index of the tag at which i failed.
The first full example is shown above.
Secondly:
...
"tag_id" => 9, // I've check its the actual ID of the tag i want to add
And Finally:
...
"tag" => "The tag i want to add",
Needless to say that i didn't succeed. Sometimes i get an error id (im assuming its because the index doesn't exist [who would have thought that? :)]), sometimes i get nothing and Zammad just creates the ticket without the tag. What do i mean when i say sometimes? I refer my tries specified above.
What I've also tried:
Searching for some answer on the web. The thing that comes close to what i want is this. But i would rather create the ticket with the tag instead of making another request just to add the tag.

I've looked inside the code, its written in ruby. The index is 'tags' and needs to be sperated by ,.
Basicly:
json_encode([
"title" => $title,
"group_id" => 2,
"priority_id" => 2,
"category" => 'Some Category',
"state_id" => 1,
"type" => "Some Type",
"customer" => $userID,
"article" => [
"body" => $htmlBody,
"type" => "note",
"content_type" => "text/html",
],
"tags" => "tag1,tag2,tag3", // or simply "tags" => "tag1"
]);
It might help someone in the future ...

Related

Fill custom CRM fields in Bitrix via REST API

I have the need to fill custom fields in Bitrix24 CRM via REST API.
When it comes to working on standard fields (like TITLE, TEL, etc) it works, but if I try to valorize a custom field by putting it's property name in the request the endpoint simply ignores it.
Here you have a snippet:
$company = CRest::call(
'crm.company.add',
[
'fields' => [
"TITLE" => "Company 1"
, "COMPANY_TYPE" => "Customer"
, "CURRENCY_ID" => 'EUR'
, "REVENUE" => "123000"
, "ADDRESS" => "st. some address"
, "ADDRESS_CITY" => "some city"
, "ADDRESS_POSTAL_CODE" => "12345"
, "ADDRESS_PROVINCE" => "some province"
, "PHONE" => [
["VALUE" => "1230000000", "VALUE_TYPE" => "WORK"]
,["VALUE" => "1234000000", "VALUE_TYPE" => "FAX"]
]
, "EMAIL" => [ ["VALUE" => "me#company1.com", "VALUE_TYPE" => "WORK"] ]
, "INDUSTRY" => "MANUFACTURING"
, "CUSTOM_FIELD" => "Hey I'm not a standard field and I'm going to be ignored"
]
]
);
Did anyone have the same need? How can I solve it?
I found the solution.
Simply write the Field ID instead of the Field Name. The Field ID looks like "UF_CRM_5AERER454DD4". By putting this as key and the value after " => " the property gets valorized.

updateOrCreate() not updating but adding new

Trying to update inserted data. But it's not quite working. If the data in the $variable changed then updateOrCreate method is just creating a new row. But it's supposed to be update the existed column?
$placeItems = [
"website_id" => self::WEBSITE_ID,
"url" => $place,
"place_name" => $title,
"image" => $image,
"description" => "I am changing here",
];
Place::updateOrCreate($placeItems);
I changed the description column. And use updateOrCreate, but it's not update the id of description in. Insert it as new. The way i am using updateOrCreate is wrong?
UPDATED
I tried a way as mentioned in the answer below and test it.
$description = "new data";
$placeItems = [
"website_id" => self::WEBSITE_ID,
"url" => $place,
"place_name" => $title,
"image" => $image,
"description" => "old data",
];
Place::updateOrCreate([
"website_id" => self::WEBSITE_ID,
"url" => $place,
"place_name" => $title,
"image" => $image,
"description" => $description,
], $placeItems);
But it still inserting as new column. not updating the ID of description in.
In your case you should specify parameters for updatedOrCreate.
The first parameter indicates the conditions for a match and second parameter specify which fields to update.
Place::updateOrCreate([ "website_id"=> self::WEBSITE_ID], [
"url" => $place,
"place_name" => $title,
"image" => $image,
"description" => $description]);
Read documentation here

Firebase PHP Data Submission - arrayValue, mapValue

I am trying to push data to a firestore DB using PHP and the Google apis.
Inside the documentation and examples I have seen around the web, I am able to use mapValue and arrayValue when sending data.
The example I am using is as follows:-
[
"orderName" => [
"stringValue" => "Gbeila Aliu Wahab"
],
"orderLocationName" => [
"stringValue" => "Accra Mall Limited"
],
"orderTotalAmount" => [
"doubleValue" => 150.5
],
"orderDescription" => [
"stringValue" => "Lorem Ipsum is simply dummy text of the printing and typesetting industry"
],
"orderLocationGeoPoints" => [
"geoPointValue" => (object) [
"latitude" => 5.5557,
"longitude" => -0.1963
]
],
"orderStatus" => [
"stringValue" => "NotAssigned"
],
]
This works perfectly fine, but when I attempt to send an object or an array I get the following error returned to me:-
"message": "Invalid JSON payload received. Unknown name \"map_value\" at 'document.fields[0].value': Proto field is not repeating, cannot start list.",
when attempting to map the value using the following code:-
"orderName" => [
"mapValue" => ["Gbeila Aliu Wahab", 123]
]
// or
"orderName" => [
"arrayValue" => [
"first" => [
"stringValue" => "test"
],
"second" => [
"stringValue" => "test123"
]
]
]
I have tried many variations to try to get this to work.
How am I supposed to be using the mapValue and arrayValue I can see a lot of mentions regarding the value option but I cannot see any examples on how to use the.
Any help would be greatly appreciated.
Payload to your array or map you're generating is incorrect as per the documentation. You need to wrap your actual data (to store) under values key, your final array should be:
["orderName" => ["arrayValue" => ["values" => [["stringValue" => "test"], ["stringValue" => "test123"]]]]]
Similarly your mapValue should be
["orderName" => ["mapValue" => ["fields" => ["field1" => ["stringValue" => "Gbeila Aliu Wahab"]]]]]
Also, you can play with other data mapper via this package.

DocuSign REST API (PHP) - pre-fill custom tags

I am working on project in which I need to use DocuSign API (PHP). This is my first experience with DocuSign and I successfully made template in DocuSign Console with roleName = signer. There I also made Custom Text Tags: address, city, state and phone and drag them to the desired location in my template. I want there to put my customer (signer) information from project database.
From my project I successfully made connection with DocuSign via PHP API and receive Embedded Singing View URL which opens my template where the user can sign document without problem.
But... all my custom text tags are empty and signer can type into them. I need to pre-fill them with signer personal data which is coming from database. I triple check custom tag label spelling, upper/lower case in my DocuSign Console and in my code as well as roleName->tagLabel relation. My PHP code is below.
Can someone, please, tell me what I am doing wrong?
I lost two days on it.
$data = array(
"accountId" => $accountId,
"emailSubject" => $this->_emailSubject,
"templateId" => $templateId,
"templateRoles" => array(
array(
"email" => $email,
"name" => $recipientName,
"clientUserId" => $clientUserId,
"roleName" => "signer",
"customFields" => array(
"textCustomFields" => array (
array (
"name" => "address",
"value" => "Address from DB",
"show" => "true",
),
array (
"name" => "city",
"value" => "City from DB",
"show" => "true",
),
array (
"name" => "state",
"value" => "State from DB",
"show" => "true",
),
array (
"name" => "phone",
"value" => "Phone from DB",
"show" => "true",
),
),
),
),
),
"status" => "sent"
);
You need to use the textTabs type in your JSON, not customFields which is used for something else. For instance, if you drag a Data Field from the UI onto the document and give it name address, to pre-fill that field you would need to reference it's tabLabel and value fields like this:
"roleName" => "signer",
"tabs" => array(
"textTabs" => array(
array(
"tabLabel"=> "address",
"value" => "123 Main St."
)
)
)

Prepopulating Docusign Template Fields

So I'm trying to prepopulate some fields in our DocuSign Templates when submitting them from our custom interface but the request doesn't seem to be able to find them in the templates. We're using REST, cURL and Codeigniter. My data array is as follows:
$data = array("accountId" => $accountId,
"emailSubject" => "Hello World!",
"emailBlurb" => "This comes from PHP",
"templateId" => "********-****-****-****-************",
"templateRoles" => array(
array(
"email" => "****#******.com",
"name" => "**** *****",
"roleName" => "LC3"
),
array(
"email" => $this->input->post("applicant_email"),
"name" => $this->input->post("applicant_name"),
"roleName" => "Applicant",
"tabStatuses" => array(
"textTabs" => array (
array (
"tabLabel" => "lic_num",
"tabValue" => $this->input->post("license_number")
),
array (
"tabLabel" => "ubi_num",
"tabValue" => $this->input->post("ubi_number")
),
array (
"tabLabel" => "tra_nam",
"tabValue" => $this->input->post("trade_name")
)
)
)
)
),
"status" => "sent");
I tried tabs instead of tabStatuses, but that didn't work either and our XML responses have TabStatuses instead of Tabs. Has something changed since the API Walkthroughs were put up?
EDIT: So after much trial and error with Chrome's Postman extension, this is the JSON request that I got to actually not error out:
{
"accountId":"c771ba8c-2947-4bec-acab-15b1b48a11b6",
"emailSubject":"Hello World!",
"emailBlurb":"This comes from PHP",
"templateId":"B96D0480-8792-43E8-AE11-E2AEAC74E601",
"templateRoles":[
{
"email":"mike#cloudpwr.com",
"name":"Mike Longmire",
"roleName":"LC3",
"tabStatuses":[
{
"tabStatus":[
{
"tabLabel":"lic_num",
"tabValue":"1111"
},
{
"tabLabel":"ubi_num",
"tabValue":"2222"
},
{
"tabLabel":"tra_nam",
"tabValue":"Flakey"
}
]
}
],
"email":"duckie715#gmail.com",
"name":"Mike Longmire",
"roleName":"Applicant"
}
],
"status":"sent"
}
I get back my same response:
{
"envelopeId": "0063d398-36b7-4e2f-8515-6ed9ab62aaeb",
"uri": "/envelopes/0063d398-36b7-4e2f-8515-6ed9ab62aaeb",
"statusDateTime": "2013-10-08T18:05:54.9926661Z",
"status": "sent"
}
Any ideas?
This is most likely caused by the values being returned from your function calls inside the JSON not being wrapped by quotation (") marks. To test that theory I would first just hardcode some values wherever you have a function call in your JSON (such as "email" => $this->input->post("applicant_email")) and replace with actual emails, etc and run.
If you still get the 400 error then something else is wrong with your request. If you don't, then you just need to prepend and append quotes around the values that are passed back by those function calls.
For instance, you can assign to variables, such as
$applicantEmail_1 = $this->input->post("applicant_email")
then setup your JSON like:
"templateRoles" => array(
array(
"email" => "****#******.com",
"name" => "**** *****",
"roleName" => "LC3"
),
array(
"email" => "$applicantEmail_1",
"name" => $this->input->post("applicant_name"),
"roleName" => "Applicant",
...
The nice thing about PHP is that even though that variable is in double quotes the value of the variable will still be inserted inside the quotes.

Categories