X-Authorization in headers for API interface

I am just getting started on working with an API by a company called SellerVantage. But, I have not done this before and don’t understand the documentation. I have been given a token by the company. The documentation only says this about the token.

You are identified by the authorization token you are given by
SellerVantage. All requests to the Items API must include it in the
headers:

X-Authorization: TOKEN TOKEN
Where TOKEN is the token. The bareword “TOKEN” shown in the previous line must be included.

From a code perpective, I don’t really know what this means. Is this a meta tag? A hidden form field? The API returns all answers in JSON so I think I can use any language to send the requests in. The documentation is only a few paragraphs so I think this should be easy. If you want to see it, it can be found here:

https://app.sellervantage.com/items_api/

Any code examples to explain what I’m missing here would be greatly appreciate. Once I know how the token is supposed to be used I think I’ll be fine.

it’s a HTTP header field. depending on what you use to connect to the API server, you must pass that header in appropriately.

OK, for the sake of ease, let’s say my token is 123 and I want to use the get_items method. The URL for that is:

https://app.sellervantage.com/items_api/get_items/?status=LISTED

So then it seems like the call would be:

https://app.sellervantage.com/items_api/get_items/?status=LISTED?TOKEN=123

But that doesn’t work. Going by the documentation it would be

https://app.sellervantage.com/items_api/get_items/?status=LISTED?X-Authorization: TOKEN 123

But that is all kinds of wrong if for no other reason is has spaces in it.

I feel like I am missing something really basic here and I need someone to explain it to me like I am a child. As in, what would the URL look like that would work (using 123 as the token).

what you’re missing is the basics of the HTTP request/response system: https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol

putting that into the address bar doesn’t have anything to do with HTTP headers.

I highly recommend checking out postman. One very cool feature is post man can generate code in a variety of languages including basic, php curl requests.

https://app.sellervantage.com/items_api/get_items/?status=LISTED

since the token doesn’t go in the URL

The PHP for the token would look like this:

header('X-Authorization: TOKEN 123');

You would need that in the actual web page before outputting any HTML.

OK, thank you all who have responded. I think I’m still a little behind in terms of some assumptions on what I know. Oddz said that the app he recommended could do “basic, php curl requests”. So I went and looked up curl. In reading around, I think curl is what I am looking for. So I ended up with this:

$headers = array();
$headers[] = 'X-Authorization: TOKEN 123';

$curl = curl_init();

curl_setopt($curl, CURLOPT_URL, 'https://app.sellervantage.com/items_api/get_items/?status=LISTED');
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
    
$result = curl_exec($curl);
$result = json_decode($result); 
echo $result;

When I echo out $result I get nothing. I also get nothing if I comment out the line with json_decode. I don’t get an error but I thought I would at least see the JSON response.

Felgall, this looks a little different than what you suggested. So, I removed all the lines that had anything to do with the header (the array and the curl_setopt line), swapped in the line you provided and tried again. That looked like this:

header('X-Authorization: TOKEN 123');

$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'https://app.sellervantage.com/items_api/get_items/?status=LISTED');
    
$result = curl_exec($curl);
$result = json_decode($result);
echo $result;

So far, same result as the top block of code. Any ideas on what I’m missing?

(And you can be sure that I’m not accidentally using 123 as the token…again)

for this scenario header() is wrong, as it sets response headers, not request headers.

1 Like

In case someone stumbles upon this thread looking for the same information I was, this is what eventually worked for me.

<?php 

$headers = array();
$headers[] = "X-Authorization: TOKEN 123";

$curl = curl_init(); 

/* This is another way of doing the same thing as the three lines below. */
/*curl_setopt_array($curl, array(
    CURLOPT_RETURNTRANSFER => 1,
    CURLOPT_URL => 'https://app.sellervantage.com/items_api/get_items/?status=LISTED',
    CURLOPT_HTTPHEADER => $headers
));*/
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); // return the results instead of outputting it
curl_setopt($curl, CURLOPT_URL, 'https://app.sellervantage.com/items_api/get_items/?status=LISTED');
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);   


// Verify SSL
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2);
    
$result = curl_exec($curl);
$result = json_decode($result); 

?>

All of that is just to get the response into the $result variable.

This was my code to output it.

<?php 

$items = $result->items;

foreach($items as $item) {
  
  echo '<h2>title: ' . $item->title . '</h2>';
  echo '<p>';
  echo 'external_id: '     . $item->external_id . '<br />';
  echo 'inventory_id: '     . $item->inventory_id . '<br />';
  echo 'in_store_location: ' . $item->in_store_location . '<br />';  
  echo 'value: '             . $item->value . '<br />';
  echo 'dimensions: '         . $item->dimensions . '<br />';
  echo 'weight: '             . $item->weight . '<br />';
  echo 'serial_number: '     . $item->serial_number . '<br />';
  echo 'status: '             . $item->status . '<br /><br />';
  
  echo '<strong>Characteristics:</strong> ';
  $characteristics  = $item->characteristics;
  echo '<strong>Color:</strong> '             . $characteristics->color . '  ';
  echo '<strong>Model:</strong> '             . $characteristics->model . '  ';
  echo '<strong>Make:</strong> '             . $characteristics->make . '  ';
  echo '<strong>Size:</strong> '             . $characteristics->size . '  ';
  echo '<strong>Brand:</strong> '             . $characteristics->brand . '  ';
  echo '<strong>Manufacturer:</strong> '     . $characteristics->manufacturer . '  ';
  echo '<strong>Width:</strong> '             . $characteristics->width . '  ';
  echo '<strong>Length:</strong> '             . $characteristics->length . '  ';
  echo '<strong>Height:</strong> '             . $characteristics->height . '  ';
  echo '<strong>Condition:</strong> '         . $characteristics->condition . '  ';

  echo '<br />images: <br />';
  $images = $item->photo_urls;
  foreach($images as $image) {
      //echo '<img src="' . $image . '" /><br />';  
      // Images are full size, just output links to them
      echo '<a target="_blank" href="' . str_replace('%2F', '/', $image) . '">Image</a><br />';
  }
  echo '</p>';
}

// I used this to figure out what the data looked like to build the output above.
//print_r ( $items );

// Gotta tidy up 
curl_close($curl);
?>
3 Likes

Thanks for posting the solution after you found it - so many post questions here and never come back to update when they find a solution.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.