Querying a Clarizen Project/Task in PHP - php

I'm currently trying to get a list of all Clarizen active projects so that I can modify some properties of its tasks. I've read the Clarizen API but it doesn't have many informations on PHP queries. What I managed to do so far is to query all the projects and then test their status one by one. In practice this is not a good approach since I have thousands of projects and not all of them are listed at once. Here's the code:
//LOGIN PROCCESS
$soapUrl = 'https://api.clarizen.com/v1.0/Clarizen.svc?WSDL';
$soapApiUrl = 'http://clarizen.com/api';
$soapConfig = array('exceptions' => 1);
$request = array();
$params = array(
'userName' => $username,
'password' => $password
);
$client = new SoapClient($soapUrl, $soapConfig);
$response = $client->Login($params);
$sessionId = $response->LoginResult->SessionId;
$userId = $response->LoginResult->UserId;
//Create a SOAP header containing the session ID for future requests
$header = new SoapHeader($soapApiUrl, 'Session', array("ID"=>$sessionId));
$client->__setSoapHeaders($header);
//Create a Query object
$userQuery = new stdClass();
//Set the name of the entity type you are querying
$userQuery->TypeName = 'Project';
//Select the fields you want retrieved from that entity
$userQuery->Fields = array('Name', 'State');
/* Doesnt work...*/
/*
$userQuery->Where = new stdClass();
$userQuery->Where->LeftExpression = new stdClass();
$userQuery->Where->LeftExpression->FieldName = 'State';
$userQuery->Where->Operator = 'Equal';
$userQuery->Where->RightExpression = new stdClass();
$userQuery->Where->RightExpression->Value = new stdClass();
$userQuery->Where->RightExpression->Value->TypeName = 'State';
$userQuery->Where->RightExpression->Value->Value = 'Active';
*/
$request[] = new SoapVar($userQuery, SOAP_ENC_OBJECT, 'EntityQuery', 'http://clarizen.com/api/queries');
//Execute the request
$result = $client->Execute(array("request"=>$request));
3 questions follow:
What is the right way to query in PHP with the "WHERE" clause
How to fetch the tasks of this project and then, for example create a Stopwatch for it.
How to continue the query until the hasMore flag is 0, or is there a way to fetch the entire thing all at once?
Thanks in advance.

Related

PHP Google Api Client SQL Admin not enable Auth IP

I have this code that updates my Google MySQL instance authorized IPs, connection is ok, the code prints me the current IP's but it cannot add a new IP to the settings I tried many ways but it still do not works it doesn't make any change to the Instance configuration.
$client = new Google_Client();
$client->setAuthConfig('../config/service-account.json');
$client->setApplicationName(env("APP_NAME"));
$projectName = env("GOOGLE_PROJECT_NAME");
$instanceName = env("SQL_INSTANCE_NAME");
$scopes = [
"https://www.googleapis.com/auth/sqlservice.admin",
"https://www.googleapis.com/auth/compute",
];
$client->addScope($scopes);
$sql = new Google_Service_SQLAdmin($client);
$sqlAdmin = new Google_Service_SQLAdmin_Settings($client);
$instanceSettings = $sql->instances->get($projectName, $instanceName)->getSettings();
$authNetworks = $instanceSettings->getIpConfiguration();
$newAuthNetwork = new Google_Service_SQLAdmin_AclEntry($client);
$newAuthNetwork->setName("tmp_ip_connection");
$newAuthNetwork->setKind("sql#aclEntry");
$authNetworks->setAuthorizedNetworks($newAuthNetwork);
$ipv4 = file_get_contents('https://api.ipify.org');
$newAuthNetwork->setValue($ipv4);
$ipConfiguration = new Google_Service_SQLAdmin_IpConfiguration($client);
$ipConfiguration->setIpv4Enabled(true);
$ipConfiguration->setAuthorizedNetworks([$newAuthNetwork]);
$instanceSettings->setIpConfiguration($ipConfiguration);
$sql->instances->get($projectName, $instanceName)->setSettings($instanceSettings);
//TODO why it is not working??
print_r($sql->instances->get($projectName, $instanceName)->getSettings()->getIpConfiguration()->getAuthorizedNetworks());
The main thing missing from yours is you never updated the instance after you made the change.
Working example:
$client = new Google_Client();
$client->setAuthConfig('../config/service-account.json');
$client->setApplicationName(env("APP_NAME"));
$projectName = env("GOOGLE_PROJECT_NAME");
$instanceName = env("SQL_INSTANCE_NAME");
$scopes = [
"https://www.googleapis.com/auth/sqlservice.admin",
"https://www.googleapis.com/auth/compute",
];
$client->addScope($scopes);
$sql = new Google_Service_SQLAdmin($client);
$instances = $sql->instances;
$instance = $instances->get('projectId', 'instanceId');
$networks = $instance->getSettings()->getIpConfiguration()->getAuthorizedNetworks();
$values = [];
foreach ($networks as $network) {
$values[$network->getName()] = $network;
}
$values['1.production'] = array_get($values, '1.production', clone head($values));
$external_ip = #file_get_contents('http://ipecho.net/plain');
$values['1.production']->setValue("$external_ip/32");
$values['1.production']->setName('1.production');
$instance->getSettings()->getIpConfiguration()->setAuthorizedNetworks(array_values($values));
$instances->update('projectId', 'instanceId', $instance);

PHP web-service multiple data passing?

I am currently trying to receive a result set from Access database using a PHP web-service. The code I current have is a script for functions/web-method:
require_once "lib/nusoap.php";
class food
{
public function getFood()
{
$MyDb = realpath("WEBSERVICES/db/Database.mdb");
$connect = new COM("ADODB.Connection") or die("Cannot start ADO.");
$connStr = "Provider=Microsoft.jet.OLEDB.4.0;Data Source=$MyDb";
$connect->Open($connStr);
$sql = "select all the stuff needed the query works fine";
$result = $connect->Execute($sql);
$resultslist = (
$Routecode = $result->Fields['RouteCode']->Value &
$Route = $result->Fields['Route']->Value &
$StationName = $result->Fields['StationName']->Value &
$Platform = $result->Fields['Platform']->Value &
$ArrivalTime = $result->Fields['ArrivalTime']->Value &
$Departure = $result->Fields['Departure']->Value &
$Status = $result->Fields['Status']->Value
);
return $resultslist;
}
}
$server = new soap_server();
$server->configureWSDL("foodservice", "http://the site");
$server->register("food.getFood",
array("type" => "xsd:string"),
array("return" => "xsd:string"),
"http:// the site /food",
"http://the site /food#getFood",
"rpc",
"encoded",
"Get food by type");
#$server->service($HTTP_RAW_POST_DATA);
and the second script that calls the function:
require_once "lib/nusoap.php";
$client = new nusoap_client("MY.WSDL.FILE", true);
$result = $client->call("food.getFood");
echo $result;
I can get a single piece of data to display but if i try multiple as shown in the $resultlist then it shows a "0" if i rearange the list i sometimes get a single data for one of the items from the lists, strange I know. So my question is, how do I pass all data over, similar to VB.net dataset/datatable etc?

Netsuite PHP API: how to update custom field on item record

I have looked at some answers on here and tried putting them into action in my script; but it's not working, and I'm not sure why.
I am trying to update a custom field on an already-existing inventory item. Here is what I have so far
<?php
require_once '../PHPToolkit/NetSuiteService.php';
$service = new NetSuiteService();
$item = new InventoryItem();
$item->internalId = 72309;
$customFieldList = new CustomFieldList();
$customField = new StringCustomFieldRef();
$customField->value = utf8_encode("12345");
$customField->internalId = 'custitem_testinput';
$customFieldList->customField[] = $customField;
$item->customFieldList = $customFieldList;
$request = new UpdateRequest();
$request->record = $item;
$response = $service->update($request);
?>
I'm trying to pull the item record up by its internalID, and then update just 1 of its many custom fields.
This code doesn't error out, but it doesn't seem to do anything either. Looking at the var_dump of the objects, I can see an item object with just the parameters I've set populated, and everything else null.
What am I doing wrong?
This is a basic example showing how to update custom field in an existing record using PHP toolkit.
<?php
require_once 'PHPToolkit/NetSuiteService.php';
$service = new NetSuiteService();
$ItemId = '72309';
$ItemRecord= new InventoryItem();
//StringCustomFieldRef
$itemField= new StringCustomFieldRef();
$itemField->scriptId = 'custitem_part_lookup';
$itemField->value = 'test';
$customFieldList = new customFieldList();
$customFieldList->customField = array($itemField);
$ItemRecord->internalId = $ItemId ;
$ItemRecord->customFieldList = $customFieldList;
$updateRequest = new UpdateRequest();
$updateRequest->record = $ItemRecord;
$updateResponse = $service->update($updateRequest);
?>
For additional information you can visit Net Suite User Group

Simple search for Netsuite Suitetalk API and PHP Toolkit

I'm trying to make a simple search with Netsuite Suitetalk API and the latest PHP Toolkit version.
Here is my code:
$service = new NetSuiteService();
$service->setSearchPreferences(false, 20);
$typeSearchField = new SearchStringField();
$typeSearchField->operator = SearchStringFieldOperator::is;
$typeSearchField->searchValue = "SalesOrder";
$search = new TransactionSearchBasic();
$search->recordType = $typeSearchField;
$request = new SearchRequest();
$request->searchRecord = $search;
$searchResponse = $service->search($request);
However, this request returns all records from Netsuite, not just the SalesOrders. Any idea what I'm doing wrong?
Update:
here is the working version, with the help of eliseobeltran. I had to change also $search->recordType with $search->type
$service = new NetSuiteService();
$service->setSearchPreferences(false, 20);
$SearchEnumMultiSelectField = new SearchEnumMultiSelectField(); //set up multiselect field to which IDs will be put
$SearchEnumMultiSelectField->searchValue = Array('_salesOrder'); //put IDs of transactions to search for as a search value
$SearchEnumMultiSelectField->operator = 'anyOf'; //set operator according to which search will be executed. Values are anyOf/noneOf
$search = new TransactionSearchBasic();
$search->type = $SearchEnumMultiSelectField;
$request = new SearchRequest();
$request->searchRecord = $search;
$searchResponse = $service->search($request);
Use "_salesOrder".
$SearchEnumMultiSelectField = new SearchEnumMultiSelectField(); //set up multiselect field to which IDs will be put
$SearchEnumMultiSelectField->searchValue = Array('_salesOrder'); //put IDs of transactions to search for as a search value
$SearchEnumMultiSelectField->operator = 'anyOf'; //set operator according to which search will be executed. Values are anyOf/noneOf

Netsuite PHP API - Find customer by email

I am trying to search for a customer by email. The Netsuite api documentation does not help much. Appreciate any help i can get. Thank You.
global $myNSclient;
$email = "myemail";
$item = new nsComplexObject('SearchStringField');
$item->setFields(array( 'searchValue' => $email, 'operator' => 'is'));
$search = new nsComplexObject('ContactSearchBasic');
$search->setFields($item);
$myNSclient->setSearchPreferences(false, 10);
$searchResponse = $myNSclient->search($search);
I got quite a few gray hairs trying to figure this out myself.
Below is the code to get a contact (different than a customer in Netsuite, both are native data types though) from their email. It will be very similar for a Customer.
$service = new NetSuiteService();
$service->setSearchPreferences(false, 20);
$recordRef = new RecordRef();
$recordRef->internalId = '-6'; //Internal ID for a customer is -2, contact is -6
$contactSearch = new ContactSearch(); //use CustomerSearch() for a customer
$contactSearchBasic = new ContactSearchBasic();//SearchRecordBasic
$contactSearchBasic->email = new SearchStringField();
$contactSearchBasic->email->searchValue = 'someone#somewhere.com';
$contactSearchBasic->email->operator = SearchStringFieldOperator::is;
$contactSearch->basic = $contactSearchBasic;
$searchRequest = new searchRequest(); //% contains a searchRecord
$searchRequest->searchRecord = $contactSearch;
$searchResponse = $service->search($searchRequest);

Categories