Gets JobID issue

My name is Andrey. I’m a senior developer at Simtech Development. I’m developing the Stuart integration with the CS-Cart e-commerce platform for my client.

I have an issue with getting the Job ID value. After creating the job, I’m trying to get the JobID

$job->getId();

but this method contains the null value in the response. Also, I can see the created job in the Sandbox administration panel.

Could you advise what is wrong?

I’m using following code:

// Initializing Client

    $environment = ($this->settings['test_mode']) == 'Y' ? \Stuart\Infrastructure\Environment::SANDBOX : \Stuart\Infrastructure\Environment::PRODUCTION;

    $api_client_id = $this->settings['client_id'];
    $api_client_secret = $this->settings['client_secret'];
    $authenticator = new \Stuart\Infrastructure\Authenticator($environment, $api_client_id, $api_client_secret);

    $httpClient = new \Stuart\Infrastructure\HttpClient($authenticator);

    $client = new \Stuart\Client($httpClient);


    // Creating Job

    $job = new \Stuart\Job();

    $pickup_address = $order_info['product_groups'][$shipping_data['group_key']]['package_info']['origination'];

    $dropoff_address = array(
        'address' => $order_info['s_address'],
        'zipcode' => $order_info['s_zipcode'],
        'city' => $order_info['s_city']
    );

    $job->addPickup($this->prepareAddress($pickup_address))
        ->setContactCompany($pickup_address['name'])
        ->setContactPhone($pickup_address['phone']);

    $job->addDropOff($this->prepareAddress($dropoff_address))
        ->setPackageType(self::SMALL_PACKAGE)
        ->setContactFirstName($order_info['firstname'])
        ->setContactLastName($order_info['lastname'])
        ->setContactPhone($order_info['s_phone'])
        ->setClientReference($order_info['order_id'] . '_' . TIME);
       
    $validate_job = $client->validateJob($job);

    if ($validate_job) {
        $client->createJob($job);
        $job_id = $job->getId();
        print_r($job_id); // see null value!
    }

Hey Andrey,

Which version of the lib are you using?

Furthermore, can you share with us a recent client_reference (at least the order_id part) you have been using to reproduce this issue?

Thanks a lot,
Maximilien

Hi @Maximilien,

Thank you for the quick reply.

  1. I’m using the V2 API version. https://github.com/StuartApp/stuart-client-php
  2. Delivery #109701. API Username: oliver@ukmeds.co.uk

Hey Andrey,

I assume that you are using the last version of the PHP lib, even if it is also supposed to work for each older version of the lib.

Unfortunately, I was not able to reproduce your problem locally using the Sandbox environment, executing the bellow code works for me as it prints the correct value. I am using the version 3.5.0 of the PHP library.

$environment = \Stuart\Infrastructure\Environment::SANDBOX;
$api_client_id = 'key goes here'; 
$api_client_secret = 'secret goes here';
$authenticator = new \Stuart\Infrastructure\Authenticator($environment, $api_client_id, $api_client_secret);
$httpClient = new \Stuart\Infrastructure\HttpClient($authenticator);
$client = new \Stuart\Client($httpClient);

 $job = new \Stuart\Job();
 $job->addPickup('46 Boulevard Barbès, 75018 Paris');
 $job->addDropOff('156 rue de Charonne, 75011 Paris')
        ->setPackageType('small');
 $created_job = $client->createJob($job);

 print_r($created_job->getId());

I also have the confirmation that you job creation request POST /v2/jobs returned you the job id 109701.

The problem actually comes from your implementation: the $client->createJob($job) doesn’t update the job given as a parameter but returns a new instance of the Job class. You should do instead:

if ($validate_job) {
      $created_job = $client->createJob($job);
      $job_id = $created_job->getId();
      print_r($job_id); // see the correct value
}

Regards,
Maximilien