Solved

Call to CreateFullfillment api returns OK but contains only HTML with auth link

Sarah_Fron
Visitor
2 0 1

I want to create a fullfilment in a private shopify app, but instead of the expected json I get a HTML with a oauth login link returned.  (see below)
what do I need to change? 

Other Api's like creating products do work

URL

POST https://{mySlug}.myshopify.com/admin/api/2021-10/orders/{orderid}/fulfillments

I also tried
POST https://{apikey}:{password}@{mySlug}.myshopify.com/admin/api/2021-10/orders/{orderid}/fulfillments

Body

{"fulfillment":{"location_id":{locationid},"notify_customer":false}}

Headers:

X-Shopify-Access-Token - {myAccessToken}

I've seen the following link

https://community.shopify.com/c/shopify-apis-and-sdks/post-returns-200-and-login-page/m-p/877771

Therefore i tried to to post with and without basic auth. Also I set "Cache-Control" to "max-age=0"

but same result.

I tried it with HTTP Client in C# and with postman  directly. both same results. In the C# client I also explicitly disable cookiesC# Code creating the http client

var handler = new HttpClientHandler
{
    UseCookies = false
};
var client = new HttpClient(handler);
client.
DefaultRequestHeaders.Add("X-Shopify-Access-Token",accessToken);
client.DefaultRequestHeaders.Add("Cache-Control", "max-age=0");


Code to post to the api

 

var req = new RequestFulfillment.ShopifyFulFillmentRequest()
{
    Fulfillment = new ()
    {
        LocationId = locationid,
        NotifyCustomer = notifyCustomer
    }
};

using var client = ResolveClient();
string content = JsonSerializer.Serialize(req);

try
{
    var response = await client.PostAsync(url, new StringContent(content, Encoding.UTF8, "application/json"));
    var respcontent = await response.Content.ReadAsStringAsync();
    var responseDto = JsonSerializer.Deserialize<CreateFulfillmentResponse>(respcontent);

 

Response I get

200 OK but his thml

 

Sarah_Fron_1-1635767988430.png

 

 



 

Accepted Solution (1)

awwdam
Shopify Staff
249 42 36

This is an accepted solution.

Hey @Sarah_Fron

I was able to replicate and resolve a similar response by appending the expected .json at the end of the request URL, per the formatting example(s) in our reference docs here.

ex. https://{shop}.myshopify.com/admin/api/{version}/{resource}.json

- Cheers!


awwdam | API Support @ Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

View solution in original post

Replies 2 (2)

awwdam
Shopify Staff
249 42 36

This is an accepted solution.

Hey @Sarah_Fron

I was able to replicate and resolve a similar response by appending the expected .json at the end of the request URL, per the formatting example(s) in our reference docs here.

ex. https://{shop}.myshopify.com/admin/api/{version}/{resource}.json

- Cheers!


awwdam | API Support @ Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

Sarah_Fron
Visitor
2 0 1

Thanks so ,much, that helped 🙂