Jump to content

API get the product ID from GetOrders call


Jogex

Recommended Posts

Hi,

I'm going crazy trying to figure out how to properly get an order from the GetOrders call.
We have a webhook running on accepted orders, and there are some jobs that only runs on a few select products. So we need to stop orders that shouldn't dispatch these jobs.

This is the current logic.

  1. An order is accepted
  2. A webhook runs the API call GetOrders({orderId}) on the order.
  3. We loop through $order->lineitems->lineitem 
  4. Each lineitem contains a relid. Previously we have taken this, and done a DB lookup on tblcustomfieldsvalues and joined the tblproducts table, which would give us a product name and ID.
  5. Then we match the product ID with a list of accepted product IDs.

Currently, I'm stuck at step 4. It's been working well for a while, but after we removed some custom fields on the products (not sure if that's the actual cause) it's started returning an empty queryset. I'm not kidding... The relid does not exist in the tblcustomfieldsvalues table AT ALL.

So I figured using the API would solve my issues since it's obviously somehow getting the product ID and name when browsing the order. From what I gather, the ID in "/clientsservices.php?userid=1&id=99" is the relid right?
 

But from the looks of it, the API result does not contain the product ID. Which I find odd, as the API call for products (GetProducts) accepts a product ID (pid). It's kind of useless right now without that ID.

I'm hoping I'm missing something obvious here. Any help would be greatly appreciated. Also, I hope I posted this in the correct section of the community.

 

With kind regards

 

Link to comment
Share on other sites

The relid in the lineitem should be the service  / domain for that line item and the only time there the relid in the line item will match up to an entry in tblcustomfieldsvalues is when that service has any custom fields saved.  Though you are correct, the getorders doesn't return the product ID but rather the product text (that helps much WHMCS).  As such, you need to go the round about way and get the service either by internal classes (WHMCS/User/Service) or by API (getclientproducts).   Then get the package / product id from that.

Link to comment
Share on other sites

35 minutes ago, steven99 said:

The relid in the lineitem should be the service  / domain for that line item and the only time there the relid in the line item will match up to an entry in tblcustomfieldsvalues is when that service has any custom fields saved.  Though you are correct, the getorders doesn't return the product ID but rather the product text (that helps much WHMCS).  As such, you need to go the round about way and get the service either by internal classes (WHMCS/User/Service) or by API (getclientproducts).   Then get the package / product id from that.

Thanks for the reply 😄 Yeah the API ecosystem has its flaws it seems. I ended up scaping the entire API integration and will rely on basic SQL queries again. I managed to find the proper relation between an invoice and the product

SELECT
tblhosting.id as 'rel_id',
tblhosting.orderid as 'order_oid',
tblproducts.name as 'product_name',
tblproducts.id as 'product_id',
tblhosting.userid as 'user_id'
FROM tblhosting 
INNER JOIN tblproducts on tblhosting.packageid = tblproducts.id 
WHERE tblhosting.id = ?

Who would have thought the PACKAGE id refers to the PRODUCT id? 😂

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated