Category Archives: Uncategorized

ChannelAdvisor REST API – Create a product

This function creates a product in ChannelAdvisor for a SKU that is in our company’s system. We currently actually only send “-” for the title, but you can send other information in the fields array, including brand, manufacturer, etc. You can see more of them in the documentation.

public function createProduct($profileId, $sku, $title, $refreshToken) {
  $token = $this->authorize($refreshToken);
  if(!is_null($token)) {
    $endpoint = $this->url . 'Products?access_token=' . $token->access_token;
    $headers = [
      'Content-Type: application/json',
    ];
    $fields = [
      "ProfileID" => $profileId,
      "Sku" => $sku,
      "Title" => $title,
    ];
    $json = json_encode($fields, 2);
    // Send the information to CA in a post request.
    $product = $this->postRequestWithJson($endpoint, $headers, $json);

    // If we get the product, return the ID
    if ($product !== FALSE) {
      return $product->ID;
    }
    // Otherwise, return null
    return NULL;
  }
  return NULL;
}

We are usually only creating a few products at one go, so this process works for us. ChannelAdvisor recommends importing large numbers of products via file.