ShopifySharp
ShopifySharp copied to clipboard
Create Fulfillment : Object reference not set to an instance of an object.
Hi,
I am attempting to create a fulfillment. I have followed your example code, and tried more complex but always get an error back.
Here is my code:
public class OrderManagement
{
private readonly ShopifySharp.OrderService _orderService;
private readonly ShopifySharp.FulfillmentService _fulfillmentService;
private readonly ShopifySharp.CarrierService _carrierService;
public OrderManagement(string baseUrl, string accessToken)
{
_orderService = new ShopifySharp.OrderService(baseUrl, accessToken);
_fulfillmentService = new ShopifySharp.FulfillmentService(baseUrl, accessToken);
_carrierService = new ShopifySharp.CarrierService(baseUrl, accessToken);
}
public async Task UpdateOrderAsync(long orderId)
{
ShopifySharp.Fulfillment fulfillment = new ShopifySharp.Fulfillment
{
TrackingCompany = "Jack Black's Pack, Stack and Track",
TrackingUrl = "https://example.com/123456789",
TrackingNumber = "123456789"
};
fulfillment = await _fulfillmentService.CreateAsync(orderId, fulfillment);
}
}
The error is: "Object reference not set to an instance of an object." and " at ShopifySharp.ShopifyService.<>c__DisplayClass26_0`1.<<ExecuteRequestAsync>b__0>d.MoveNext()"
When watching Fiddler it appears to start to make a call to the Shopify API
This is what is being sent:
GET https://shop-unimals.myshopify.com/admin/api/2019-10/orders/2500263805033/fulfillments.json HTTP/1.1
Host: shop-unimals.myshopify.com
X-Shopify-Access-Token: shppa_redacted
Accept: application/json
it gets a response back from the API of:
{"fulfillments":[]}
and then throws the error.
Any help would be greatly appreciated!
You must supply a LocationId in your fulfillment.
eg.
var fulfillment = new Fulfillment()
{
OrderId = order.Id,
LocationId = location.Id
};
You can get the LocationId from the LocationService https://github.com/nozzlegear/ShopifySharp#listing-locations