Was this helpful?

Accessing Profiles

The Alpaca Travel GraphQL API allows developers to access and manipulate user profiles and itineraries on the Alpaca Travel platform. In order to access the API, a valid access token must be included with requests. This access token defines the level of access a user has to a profile, with a secret token providing write access and a public token providing read-only access.

In this reference guide, we will cover the basics of accessing profiles using the Alpaca Travel GraphQL API. We will discuss the use of secret and public tokens, the process of creating and reading profiles and itineraries, and provide code examples for various operations.

Understanding Secret and Public Tokens

Accessing profiles using the Alpaca Travel GraphQL API requires the use of an access token. This access token defines the level of access a user has to a profile, with a secret token providing write access and a public token providing read-only access.

It's very important to keep in mind that the secret key is something that should be hidden from being revealed in your application or website to users (e.g. used in requests from the client). In the case you wish to have javascript call the GraphQL API directly, you should always use the public key.

Based on the version 1 of the Alpaca Travel GraphQL API access token, visually the tokens starting with "sk." are secret keys, and "pk." is a public key.

When creating content, we can associate content to a profile if we have access using the secret token, or with the public token we can create psuedo-anonymous content, which does not have an association to a profile. However, it's important to note that it's not possible to create new profiles with access tokens.

In summary, the secret token provides write access to the profile, allowing you to create and update content associated with the profile. The public token, on the other hand, provides read-only access to the profile, allowing you to view and retrieve information about the profile but not make any changes to it.

Reading Profiles

In order to read a profile using the Alpaca Travel GraphQL API, you may need to locate the authorized profiles that correspond to your access token. The following query can be used to do this:

1query GetAuthorizedProfiles {
2  authorizedProfiles(first: 1) {
3    nodes {
4      id
5      __typename
6      handle
7      name
8    }
9  }
10}

Sandbox: Configure | Try Operation

This query will return a the first authorized profile, including the profile's ID, type, handle, and name.

1{
2  "data": {
3    "authorizedProfiles": {
4      "nodes": [
5        {
6          "id": "profile/ABC123",
7          "__typename": "Profile",
8          "handle": "johndoe",
9          "name": "John Doe"
10        }
11      ]
12    }
13  }
14}

Once you have located the authorized profile, you can use the profile ID to read in a specific profile. The following query can be used to read a profile:

1query GetProfile {
2  profile(id: "profile/ABC123") {
3    id
4    __typename
5    handle
6    name
7    bio
8    websiteUrl
9  }
10}

Sandbox: Configure | Try Operation

This query will return the profile's ID, type, handle, name, bio, and website URL. If the profile ID is invalid or the user does not have access to the profile, the query will return an error.

Expected response from the server:

1{
2  "profile": {
3    "id": "profile/ABC123",
4    "__typename": "Profile",
5    "handle": "johndoe",
6    "name": "John Doe",
7    "bio": "I am a travel enthusiast and love to explore new places.",
8    "websiteUrl": "https://johndoe.com"
9  }
10}

Creating Profile Associated to an Itinerary

Once you have located an authorized profile using the profile ID, you can create an itinerary associated to that profile using the createItinerary mutation. The following example shows how to create an itinerary associated to the profile with ID "profile/ABC123":

1mutation CreateItinerary {
2  createItinerary(
3    profileId: "profile/ABC123"
4    itinerary: {
5      title: "My European Adventure"
6      synopsis: "A curated list of must-see places in Europe"
7    }
8  ) {
9    itinerary {
10      id
11      __typename
12      title
13      synopsis
14    }
15  }
16}

Sandbox: Configure | Try Operation

This mutation creates an itinerary with the title "My European Adventure", the synopsis "A curated list of must-see places in Europe" and associates it to the profile with ID "profile/ABC123". It returns the itinerary's ID, type, title and synopsis.

Expected response from the server:

1{
2  "data": {
3    "createItinerary": {
4      "itinerary": {
5        "id": "itinerary_ABC123",
6        "__typename": "Itinerary",
7        "title": "My European Adventure",
8        "description": "A curated list of must-see places in Europe",
9        "startDate": "2022-07-01"
10      }
11    }
12  }
13}

It is important to note that it is only possible to create itineraries associated to an authorized profile if you are using a secret key. If you are using a public key, you will not be able to create itineraries associated to a profile.

alpaca.tech

Copyright © 2024 - Made with love ❤️ in Australia.