Comments (3)
Perfect! Thanks, Dan.
One question, though. I ran all three sections of the code
$result = $purplship->trackers->create('ups', $tracking_number);
print_r($result);
$result = $purplship->trackers->retrieves($tracking_number);
print_r($result);
$result = $purplship->trackers->list();
print_r($result);
and they all printed pretty much the same information. Why is that?
It looks like we can get away with just running $purplship->trackers->create
and parsing those results. Or am I missing something?
from karrio-php.
Hi @s22-tech,
Thanks for opening the issue we are about to release richer documentation to cover all supported methods/operations.
I tried tracking myself and discovered that the tracking statuses weren't up to date with the latest purplship server (2021.7). While that error has nothing to do with this issue. I recommend updating your PHP client to the latest patch I just released (2021.7.1
) to avoid having another error.
That said here is how the /v1/trackers
API works with the PHP client:
Create a tracker
When you want to get a package tracking status that will auto-update and get you the latest status in the dashboard, via webhooks or any time to retrieve a tracker, you need to create a tracker at first.
the method is $purplship->trackers->create('CARRIER_NAME', 'TRACKING_NUMBER');
e.g:
require_once(__DIR__ . '/vendor/autoload.php');
// Configure API key authorization: Token
$purplship = new \Purplship\Purplship('YOUR_API_KEY', 'https://cloud.purplship.com');
try {
$result = $purplship->trackers->create('dhl_universal', '1239410034');
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling trackers->create: ', $e->getMessage(), PHP_EOL;
}
Retrieve an existing tracker
Before you can retrieve a tracker, it must have been created within the purplship server before. Only then, you can retrieve the latest tracking status by retrieving the tracker.
The method is $purplship->trackers->create('TRACKING_NUMBER');
or $purplship->trackers->create('TRACKER_ID');
e.g:
try {
$result = $purplship->trackers->retrieves('1239410034');
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling trackers->retrieves: ', $e->getMessage(), PHP_EOL;
}
List all trackers
Now if you are displaying all your trackers somewhere or need to filter through them, you can get the list of trackers.
The method is $purplship->trackers->list();
e.g:
try {
$result = $purplship->trackers->list();
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling trackers->list: ', $e->getMessage(), PHP_EOL;
}
Let me know if you encounter any issues.
from karrio-php.
That's right if all you want is to get the tracking status of a tracking number,
$purplship->trackers->create
is enough because if you are sending it for the first time it will create the tracker, the second time, it will just return what already exists.
$result = $purplship->trackers->list();
is supposed to return a list of trackers though. So if you try another one, you should get more than one.
from karrio-php.
Related Issues (5)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from karrio-php.