Skip to content

Latest commit

 

History

History
273 lines (189 loc) · 9.86 KB

README.md

File metadata and controls

273 lines (189 loc) · 9.86 KB

Webhooks

(webhooks())

Overview

Webhooks are a way for Shippo to notify your application when a specific event occurs. For example, when a label is purchased or when a shipment tracking status has changed. You can use webhooks to trigger actions in your application, such as sending an email or updating a database.

Webhook Payload

The payload is the body of the POST request Shippo sends to the URL specified at the time of webhook registration.

Available Operations

createWebhook

Creates a new webhook to send notifications to a URL when a specific event occurs.

Example Usage

package hello.world;

import com.goshippo.shippo_sdk.Shippo;
import com.goshippo.shippo_sdk.models.components.WebhookEventTypeEnum;
import com.goshippo.shippo_sdk.models.components.WebhookUpdateRequest;
import com.goshippo.shippo_sdk.models.operations.CreateWebhookResponse;
import java.lang.Exception;

public class Application {

    public static void main(String[] args) throws Exception {

        Shippo sdk = Shippo.builder()
                .apiKeyHeader("<YOUR_API_KEY_HERE>")
                .shippoApiVersion("2018-02-08")
            .build();

        WebhookUpdateRequest req = WebhookUpdateRequest.builder()
                .event(WebhookEventTypeEnum.BATCH_CREATED)
                .url("https://example.com/shippo-webhook")
                .active(true)
                .isTest(false)
                .build();

        CreateWebhookResponse res = sdk.webhooks().createWebhook()
                .request(req)
                .call();

        if (res.webhook().isPresent()) {
            // handle response
        }
    }
}

Parameters

Parameter Type Required Description
request WebhookUpdateRequest ✔️ The request object to use for the request.

Response

CreateWebhookResponse

Errors

Error Type Status Code Content Type
models/errors/SDKError 4XX, 5XX */*

listWebhooks

Returns a list of all webhooks you have created.

Example Usage

package hello.world;

import com.goshippo.shippo_sdk.Shippo;
import com.goshippo.shippo_sdk.models.operations.ListWebhooksResponse;
import java.lang.Exception;

public class Application {

    public static void main(String[] args) throws Exception {

        Shippo sdk = Shippo.builder()
                .apiKeyHeader("<YOUR_API_KEY_HERE>")
                .shippoApiVersion("2018-02-08")
            .build();

        ListWebhooksResponse res = sdk.webhooks().listWebhooks()
                .call();

        if (res.webhookPaginatedList().isPresent()) {
            // handle response
        }
    }
}

Response

ListWebhooksResponse

Errors

Error Type Status Code Content Type
models/errors/SDKError 4XX, 5XX */*

getWebhook

Returns the details of a specific webhook using the webhook object ID.

Example Usage

package hello.world;

import com.goshippo.shippo_sdk.Shippo;
import com.goshippo.shippo_sdk.models.operations.GetWebhookResponse;
import java.lang.Exception;

public class Application {

    public static void main(String[] args) throws Exception {

        Shippo sdk = Shippo.builder()
                .apiKeyHeader("<YOUR_API_KEY_HERE>")
                .shippoApiVersion("2018-02-08")
            .build();

        GetWebhookResponse res = sdk.webhooks().getWebhook()
                .webhookId("<id>")
                .call();

        if (res.webhook().isPresent()) {
            // handle response
        }
    }
}

Parameters

Parameter Type Required Description
webhookId String ✔️ Object ID of the webhook to retrieve

Response

GetWebhookResponse

Errors

Error Type Status Code Content Type
models/errors/SDKError 4XX, 5XX */*

updateWebhook

Updates an existing webhook using the webhook object ID.

Example Usage

package hello.world;

import com.goshippo.shippo_sdk.Shippo;
import com.goshippo.shippo_sdk.models.components.WebhookEventTypeEnum;
import com.goshippo.shippo_sdk.models.components.WebhookUpdateRequest;
import com.goshippo.shippo_sdk.models.operations.UpdateWebhookResponse;
import java.lang.Exception;

public class Application {

    public static void main(String[] args) throws Exception {

        Shippo sdk = Shippo.builder()
                .apiKeyHeader("<YOUR_API_KEY_HERE>")
                .shippoApiVersion("2018-02-08")
            .build();

        UpdateWebhookResponse res = sdk.webhooks().updateWebhook()
                .webhookId("<id>")
                .webhookUpdateRequest(WebhookUpdateRequest.builder()
                    .event(WebhookEventTypeEnum.BATCH_CREATED)
                    .url("https://example.com/shippo-webhook")
                    .active(true)
                    .isTest(false)
                    .build())
                .call();

        if (res.webhook().isPresent()) {
            // handle response
        }
    }
}

Parameters

Parameter Type Required Description
webhookId String ✔️ Object ID of the webhook to retrieve
webhookUpdateRequest WebhookUpdateRequest ✔️ N/A

Response

UpdateWebhookResponse

Errors

Error Type Status Code Content Type
models/errors/SDKError 4XX, 5XX */*

deleteWebhook

Deletes a specific webhook using the webhook object ID.

Example Usage

package hello.world;

import com.goshippo.shippo_sdk.Shippo;
import com.goshippo.shippo_sdk.models.operations.DeleteWebhookResponse;
import java.lang.Exception;

public class Application {

    public static void main(String[] args) throws Exception {

        Shippo sdk = Shippo.builder()
                .apiKeyHeader("<YOUR_API_KEY_HERE>")
                .shippoApiVersion("2018-02-08")
            .build();

        DeleteWebhookResponse res = sdk.webhooks().deleteWebhook()
                .webhookId("<id>")
                .call();

        // handle response
    }
}

Parameters

Parameter Type Required Description
webhookId String ✔️ Object ID of the webhook to delete

Response

DeleteWebhookResponse

Errors

Error Type Status Code Content Type
models/errors/SDKError 4XX, 5XX */*