How to make an API call
This tutorial page goes over how to make an API call to the WePay API. By now you should already have created an application and have an access token for the user you want to make a call on behalf of. If you do not, you should read the tutorial section on getting authorization. You can also use the access token that was given to you when you created your application. You can see this access token on your application page.
If you want to skip this section, and are using one of the supported languages you can check out our WePay SDKs, which will help you make API calls.
The Access Token
The most important part of any call is the access token. The access token is how WePay knows that you have authorization to make the call. For security reasons, the access token should NEVER be passed as a get or post argument. The access token should be passed in the 'authorization' HTTP request header.
Each access token is associated with the following:
App:
The API application making the call
User:
The user the API call is for
Permissions:
What permissions the API application has for that user
So when you make an API call with an access token, the WePay API will be able to tell what App you are and what user you are making the call for just from the access token. If you want to make a call for user #1 you need to use the access_token you have for user #1, and if you want to make an API call for user #2, you should use the access token you have for user #2.
The authorization header should look like this:
Authorization: Bearer <access-token>
Just make sure to replace <access-token> with your access token.
Constructing the call
There are two endpoints (base urls) that you can make your API calls to. "Stage" if you are testing, and "Production" for when you have finished testing on "Stage" and want your application to go live.
The URLs are:
Stage:
https://stage.wepayapi.com/v2/
Production:
https://wepayapi.com/v2/
To make an API call you should pass the access_token as an HTTP header with the following form:
Authorization: Bearer <access-token>
Call arguments should be passed as JSON in the body of the request with content-type HTTP header set to application/json.
If you are using PHP you can use PHP's libcurl functionality to make calls. As an example, here is a call to /v2/user/ (which does not require any parameters).
<?php
$ch = curl_init('https://stage.wepayapi.com/v2/user'); // the URL of the call
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER,
array('Authorization: Bearer <access-token>'));
// execute the api call
$result = curl_exec($ch);
// echo the json response
echo json_decode($result);
The response for this call should look something like this:
{
"first_name":"Bob",
"last_name": "Smith",
"email":"
[email protected]",
"state":"registered"
}